From 177dec2bdb0b6d04bddf97d0586dab04b1738e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Carceles?= Date: Fri, 6 Jan 2023 14:46:27 +0100 Subject: [PATCH] feat(dossier): add dossier id to prefill response (#8382) --- app/controllers/api/public/v1/dossiers_controller.rb | 6 +++++- config/locales/en.yml | 2 +- config/locales/fr.yml | 2 +- .../api/public/v1/dossiers_controller_spec.rb | 11 +++++++---- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/public/v1/dossiers_controller.rb b/app/controllers/api/public/v1/dossiers_controller.rb index cffe7aa66..2e770d6ce 100644 --- a/app/controllers/api/public/v1/dossiers_controller.rb +++ b/app/controllers/api/public/v1/dossiers_controller.rb @@ -11,7 +11,11 @@ class API::Public::V1::DossiersController < API::Public::V1::BaseController dossier.build_default_individual if dossier.save dossier.prefill!(PrefillParams.new(dossier, params.to_unsafe_h).to_a) - render json: { dossier_url: commencer_url(@procedure.path, prefill_token: dossier.prefill_token) }, status: :created + render json: { + dossier_url: commencer_url(@procedure.path, prefill_token: dossier.prefill_token), + dossier_id: dossier.to_typed_id, + dossier_number: dossier.id + }, status: :created else render_bad_request(dossier.errors.full_messages.to_sentence) end diff --git a/config/locales/en.yml b/config/locales/en.yml index b74f9861e..14b092094 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -139,7 +139,7 @@ en: 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:
# {"dossier_url":"%{url}"}' + prefill_query_response_html: '# Response:
# {
# "dossier_url": "%{url}",
# "dossier_id": "aBase64Id==",
# "dossier_number": 42
# }' prefill_query_copy: Copy prefill query registrations: new: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 45860fd36..043849734 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -132,7 +132,7 @@ fr: 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:
# {"dossier_url":"%{url}"}' + prefill_query_response_html: '# Response:
# {
# "dossier_url": "%{url}",
# "dossier_id": "aBase64Id==",
# "dossier_number": 42
# }' prefill_query_copy: Copier la requête de préremplissage registrations: new: diff --git a/spec/controllers/api/public/v1/dossiers_controller_spec.rb b/spec/controllers/api/public/v1/dossiers_controller_spec.rb index e4cc80de9..ac434fe44 100644 --- a/spec/controllers/api/public/v1/dossiers_controller_spec.rb +++ b/spec/controllers/api/public/v1/dossiers_controller_spec.rb @@ -30,11 +30,14 @@ RSpec.describe API::Public::V1::DossiersController, type: :controller do expect(Dossier.last.user).to eq(nil) end - it "responds with the brouillon dossier path" do + it "responds with the brouillon dossier url and id" do create_request - expect(JSON.parse(response.body)["dossier_url"]).to eq( - "http://test.host#{commencer_path(procedure.path, prefill_token: Dossier.last.prefill_token)}" - ) + + dossier = Dossier.last + dossier_url = "http://test.host#{commencer_path(procedure.path, prefill_token: dossier.prefill_token)}" + expect(JSON.parse(response.body)["dossier_url"]).to eq(dossier_url) + expect(JSON.parse(response.body)["dossier_id"]).to eq(dossier.to_typed_id) + expect(JSON.parse(response.body)["dossier_number"]).to eq(dossier.id) end context 'when prefill values are given' do