fix(prefill.repetitions): with more than one row, should be able to prefill champs repetition rows

This commit is contained in:
mfo 2024-12-06 17:32:35 +01:00
parent 4e7693db89
commit ad832b9401
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
2 changed files with 7 additions and 3 deletions

View file

@ -9,6 +9,7 @@ module DossierPrefillableConcern
attributes = { prefilled: true }
attributes[:champs_attributes] = champs_attributes.map { |h| h.merge(prefilled: true) }
attributes[:individual_attributes] = identity_attributes if identity_attributes.present?
reload
assign_attributes(attributes)
save(validate: false)

View file

@ -85,12 +85,15 @@ RSpec.describe API::Public::V1::DossiersController, type: :controller do
end
let(:prefilled_champs) { TypesDeChamp::PrefillTypeDeChamp.wrap(procedure.published_revision.types_de_champ, procedure.active_revision) }
let(:prefilled_champs_as_params) { prefilled_champs.map { |type_de_champ| ["champ_#{type_de_champ.to_typed_id_for_query}", type_de_champ.example_value] }.to_h }
let(:params) do
prefilled_champs_as_params.merge(id: procedure.id)
end
let(:params) { prefilled_champs_as_params.merge(id: procedure.id) }
it "updates the champs with the new values and mark them as prefilled" do
expect { create_request }.not_to raise_error(ActiveRecord::RecordNotFound)
dossier = Dossier.last
first_row = dossier.project_champs_public.first.rows.first
second_row = dossier.project_champs_public.first.rows.last
expect(dossier.project_champs_public.first.rows.flatten.map(&:value)).to match_array(['Texte court', 'Texte court'])
end
end
end