feat(demarche): describe dossier prefilling with POST (#8298)
* feat(demarche): describe dossier prefilling with POST * show response example
This commit is contained in:
parent
4389c689f2
commit
456be420fa
10 changed files with 86 additions and 1 deletions
|
@ -30,6 +30,15 @@ class PrefillDescription < SimpleDelegator
|
|||
@prefill_link ||= commencer_url({ path: path }.merge(prefilled_champs_for_link))
|
||||
end
|
||||
|
||||
def prefill_query
|
||||
@prefill_query ||=
|
||||
<<~TEXT
|
||||
curl --request POST '#{api_public_v1_dossiers_url(self)}' \\
|
||||
--header 'Content-Type: application/json' \\
|
||||
--data '{#{prefilled_champs_for_query}}'
|
||||
TEXT
|
||||
end
|
||||
|
||||
def prefilled_champs
|
||||
@prefilled_champs ||= active_fillable_public_types_de_champ.where(id: selected_type_de_champ_ids)
|
||||
end
|
||||
|
|
14
app/views/prefill_descriptions/_prefill_query.html.haml
Normal file
14
app/views/prefill_descriptions/_prefill_query.html.haml
Normal file
|
@ -0,0 +1,14 @@
|
|||
= turbo_frame_tag "#{dom_id(prefill_description)}_query" do
|
||||
|
||||
- if prefill_description.prefilled_champs.any?
|
||||
|
||||
= render Dsfr::CalloutComponent.new(title: t("views.prefill_descriptions.edit.prefill_query_title"), theme: :success, icon: "fr-icon-code-box-fill") do |c|
|
||||
- c.with_body do
|
||||
= t("views.prefill_descriptions.edit.prefill_query_info")
|
||||
%pre
|
||||
%code.code-block
|
||||
= prefill_description.prefill_query
|
||||
%br
|
||||
= t("views.prefill_descriptions.edit.prefill_query_response_html", url: commencer_url(prefill_description.path, prefill_token: "faketoken"))
|
||||
- c.with_bottom do
|
||||
= render Dsfr::CopyButtonComponent.new(title: t("views.prefill_descriptions.edit.prefill_query_copy"), text: prefill_description.prefill_query)
|
|
@ -17,3 +17,5 @@
|
|||
= render "types_de_champs", prefill_description: @prefill_description
|
||||
|
||||
= render "prefill_link", prefill_description: @prefill_description
|
||||
|
||||
= render "prefill_query", prefill_description: @prefill_description
|
||||
|
|
|
@ -3,3 +3,6 @@
|
|||
|
||||
= turbo_stream.replace "#{dom_id(@prefill_description)}_url" do
|
||||
= render "prefill_link", prefill_description: @prefill_description
|
||||
|
||||
= turbo_stream.replace "#{dom_id(@prefill_description)}_query" do
|
||||
= render "prefill_query", prefill_description: @prefill_description
|
||||
|
|
|
@ -137,6 +137,10 @@ en:
|
|||
prefill_link_info: Use the button to copy the link, then remplace the values with your data.
|
||||
prefill_link_too_long: Warning, the prefill link is too long and may not work on all browsers.
|
||||
prefill_link_copy: Copy prefill link
|
||||
prefill_query_title: Prefill query (POST)
|
||||
prefill_query_info: Use the button to copy the query, then remplace the values with your data.
|
||||
prefill_query_response_html: '# Response:<br># {"dossier_url":"%{url}"}'
|
||||
prefill_query_copy: Copy prefill query
|
||||
registrations:
|
||||
new:
|
||||
title: "Create an account %{name}"
|
||||
|
|
|
@ -130,6 +130,10 @@ fr:
|
|||
prefill_link_info: Copiez le lien grâce au bouton ci-dessous et remplacez les valeurs par les données dont vous disposez.
|
||||
prefill_link_too_long: Attention, ce lien de préremplissage est trop long et risque de ne pas fonctionner sur certains navigateurs.
|
||||
prefill_link_copy: Copier le lien de préremplissage
|
||||
prefill_query_title: Requête de préremplissage (POST)
|
||||
prefill_query_info: Copiez la requête grâce au bouton ci-dessous et remplacez les valeurs par les données dont vous disposez.
|
||||
prefill_query_response_html: '# Response:<br># {"dossier_url":"%{url}"}'
|
||||
prefill_query_copy: Copier la requête de préremplissage
|
||||
registrations:
|
||||
new:
|
||||
title: "Creation de compte sur %{name}"
|
||||
|
|
|
@ -322,6 +322,8 @@ Rails.application.routes.draw do
|
|||
end
|
||||
end
|
||||
|
||||
resources :prefills, only: :show
|
||||
|
||||
resource :feedback, only: [:create]
|
||||
get 'demarches' => 'demarches#index'
|
||||
|
||||
|
|
|
@ -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}""
|
||||
)
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue