feat(demarche): describe dossier prefilling with POST (#8298)

* feat(demarche): describe dossier prefilling with POST

* show response example
This commit is contained in:
Sébastien Carceles 2023-01-04 08:31:31 +01:00 committed by GitHub
parent 4389c689f2
commit 456be420fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 86 additions and 1 deletions

View file

@ -77,6 +77,16 @@ describe PrefillDescriptionsController, type: :controller do
"champ_#{type_de_champ_to_add.to_typed_id}" => I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ_to_add.type_champ}")
}.to_query)
end
it "includes the prefill query" do
type_de_champ_value = I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ.type_champ}")
type_de_champ_to_add_value = I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ_to_add.type_champ}")
expect(response.body).to include(api_public_v1_dossiers_path(procedure))
expect(response.body).to include(
""champ_#{type_de_champ.to_typed_id}": "#{type_de_champ_value}", "champ_#{type_de_champ_to_add.to_typed_id}": "#{type_de_champ_to_add_value}&quot"
)
end
end
context 'when removing a type_de_champ_id' do
@ -94,6 +104,19 @@ describe PrefillDescriptionsController, type: :controller do
"champ_#{type_de_champ_to_remove.to_typed_id}" => I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ_to_remove.type_champ}")
}.to_query)
end
it "includes the prefill query" do
type_de_champ_value = I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ.type_champ}")
type_de_champ_to_remove_value = I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ_to_remove.type_champ}")
expect(response.body).to include(api_public_v1_dossiers_path(procedure))
expect(response.body).to include(
""champ_#{type_de_champ.to_typed_id}": "#{type_de_champ_value}""
)
expect(response.body).not_to include(
""champ_#{type_de_champ_to_remove.to_typed_id}": "#{type_de_champ_to_remove_value}""
)
end
end
context 'when removing the last type de champ' do
@ -105,6 +128,10 @@ describe PrefillDescriptionsController, type: :controller do
it "does not include the prefill URL" do
expect(response.body).not_to include(commencer_path(path: procedure.path))
end
it "does not include the prefill query" do
expect(response.body).not_to include(api_public_v1_dossiers_path(procedure))
end
end
end
end

View file

@ -100,4 +100,23 @@ RSpec.describe PrefillDescription, type: :model do
)
end
end
describe '#prefill_query' do
let(:procedure) { create(:procedure) }
let(:type_de_champ) { create(:type_de_champ_text, procedure: procedure) }
let(:prefill_description) { described_class.new(procedure) }
let(:expected_query) do
<<~TEXT
curl --request POST '#{api_public_v1_dossiers_url(procedure)}' \\
--header 'Content-Type: application/json' \\
--data '{"champ_#{type_de_champ.to_typed_id}": "#{I18n.t("views.prefill_descriptions.edit.examples.#{type_de_champ.type_champ}")}"}'
TEXT
end
before { prefill_description.update(selected_type_de_champ_ids: [type_de_champ.id]) }
it "builds the query to create a new prefilled dossier" do
expect(prefill_description.prefill_query).to eq(expected_query)
end
end
end

View file

@ -11,11 +11,12 @@ describe 'As an integrator:', js: true do
expect(page).to have_content(type_de_champ.description)
end
scenario 'I can select champs to prefill' do
scenario 'I can select champs to prefill and get prefill link and prefill query' do
click_on 'Ajouter'
prefill_description = PrefillDescription.new(procedure)
prefill_description.update(selected_type_de_champ_ids: [type_de_champ.id.to_s])
expect(page).to have_content(prefill_description.prefill_link)
expect(page).to have_content(prefill_description.prefill_query.gsub("\n ", "").delete("\n"))
end
end