Skip to content

Commit

Permalink
feat(type_de_champ.referentiel_mapping): begin implementation of mapp…
Browse files Browse the repository at this point in the history
…ing on type de champ store_accessor :referentiel_mapping
  • Loading branch information
mfo committed Jan 13, 2025
1 parent ab8558c commit 38c660f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
9 changes: 9 additions & 0 deletions app/controllers/administrateurs/referentiels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ def mapping_type_de_champ
@service.test
end

def update_mapping_type_de_champ
flash = if @type_de_champ.update(type_de_champ_mapping_params)
{ notice: "ok" }
else
{ alert: "ko" }
end
redirect_to mapping_type_de_champ_admin_procedure_referentiel_path(@procedure, @type_de_champ.stable_id, @referentiel), flash:
end

private

def type_de_champ_mapping_params
Expand Down
3 changes: 2 additions & 1 deletion app/models/type_de_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ class TypeDeChamp < ApplicationRecord
:expression_reguliere_error_message,
:collapsible_explanation_enabled,
:collapsible_explanation_text,
:header_section_level
:header_section_level,
:referentiel_mapping

has_many :revision_types_de_champ, -> { revision_ordered }, class_name: 'ProcedureRevisionTypeDeChamp', dependent: :destroy, inverse_of: :type_de_champ

Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@
resources :referentiels, only: [:new, :create, :edit, :update], path: ':stable_id' do
member do
get :mapping_type_de_champ
patch :update_mapping_type_de_champ
end
end

Expand Down
25 changes: 25 additions & 0 deletions spec/controllers/administrateurs/referentiels_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,29 @@
end
end
end

describe '#update_mapping_type_de_champ' do
let(:type_de_champ) { procedure.draft_revision.types_de_champ.first }
let(:referentiel) { create(:api_referentiel, :configured, types_de_champ: [type_de_champ]) }
let(:referentiel_mapping) do
[
{
jsonpath: "jsonpath",
type: "type",
prefill: "prefill",
libelle: "libelle"
}
]
end
it 'update type de champ referentiel_mapping' do
expect do
patch :update_mapping_type_de_champ, params: {
procedure_id: procedure.id,
stable_id: stable_id,
id: referentiel.id,
type_de_champ: { referentiel_mapping: }
}
end.to change { type_de_champ.reload.referentiel_mapping }.from(nil).to(referentiel_mapping)
end
end
end

0 comments on commit 38c660f

Please sign in to comment.