From 1564935fa4b90ddd672588adba20b95cbbf04510 Mon Sep 17 00:00:00 2001 From: Adrien Di Pasquale Date: Tue, 7 Jan 2025 13:49:39 +0100 Subject: [PATCH] =?UTF-8?q?Passage=20d=E2=80=99un=20meeting=5Fpoint=5Fid?= =?UTF-8?q?=20vide=20=C3=A0=C2=A0l=E2=80=99appel=20API=20ANTS=20status=20(?= =?UTF-8?q?#4940)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * generisation des specs pour utiliser query: hash_including(appointment_ids:) * Passage d’un meeting_point_id vide à l’appel API ANTS status --- app/lib/ants_api.rb | 7 +++++-- .../ants_pre_demande_number_validation.rb | 1 + ...create_rdv_for_a_user_in_rdv_mairie_spec.rb | 7 +++---- .../users/online_booking/on_rdv_mairie_spec.rb | 7 +++---- ...appointment_serializer_and_listener_spec.rb | 18 +++++++++--------- spec/services/ants_api_spec.rb | 18 ++++++++++-------- spec/support/ants_stubs.rb | 10 ++++++---- 7 files changed, 37 insertions(+), 31 deletions(-) diff --git a/app/lib/ants_api.rb b/app/lib/ants_api.rb index 43ebaaf156..328bbbf7c5 100644 --- a/app/lib/ants_api.rb +++ b/app/lib/ants_api.rb @@ -21,8 +21,11 @@ class ApiRequestError < StandardError; end class << self def status(ants_pre_demande_number:, timeout: nil) - response_body = request(:get, "status", params: { application_ids: ants_pre_demande_number }, timeout: timeout) - + params = { + application_ids: ants_pre_demande_number, + meeting_point_id: nil, # required but unused cf https://github.com/betagouv/rdv-service-public/pull/4940 + } + response_body = request(:get, "status", params:, timeout:) response_body.fetch(ants_pre_demande_number) end diff --git a/app/validators/ants_pre_demande_number_validation.rb b/app/validators/ants_pre_demande_number_validation.rb index a28542879e..e1506ee27d 100644 --- a/app/validators/ants_pre_demande_number_validation.rb +++ b/app/validators/ants_pre_demande_number_validation.rb @@ -30,6 +30,7 @@ def validate(record) # Si l'API de l'ANTS est fiable, donc si elle renvoie une erreur ou un timeout, # on préfère bloquer la réservation et logguer l'erreur. record.errors.add(:ants_pre_demande_number, "n'a pas pu être validé à cause d'une erreur inattendue. Merci de réessayer dans 30 secondes.") + Rails.logger.error e Sentry.capture_exception(e) end diff --git a/spec/features/prescripteurs/can_create_rdv_for_a_user_in_rdv_mairie_spec.rb b/spec/features/prescripteurs/can_create_rdv_for_a_user_in_rdv_mairie_spec.rb index 3da298eaf9..0821849be8 100644 --- a/spec/features/prescripteurs/can_create_rdv_for_a_user_in_rdv_mairie_spec.rb +++ b/spec/features/prescripteurs/can_create_rdv_for_a_user_in_rdv_mairie_spec.rb @@ -124,10 +124,9 @@ def fill_up_prescripteur_and_user context "ANTS responds with an unexpected error" do before do - stub_request(:get, "https://int.api-coordination.rendezvouspasseport.ants.gouv.fr/api/status?application_ids=1122334455").to_return( - status: 500, - body: "Internal Server Error" - ) + stub_request(:get, "https://int.api-coordination.rendezvouspasseport.ants.gouv.fr/api/status") + .with(query: hash_including(application_ids: "1122334455")) + .to_return(status: 500, body: "Internal Server Error") end it "prevents from creating the user / RDV" do diff --git a/spec/features/users/online_booking/on_rdv_mairie_spec.rb b/spec/features/users/online_booking/on_rdv_mairie_spec.rb index 34fc51b863..740cc87dae 100644 --- a/spec/features/users/online_booking/on_rdv_mairie_spec.rb +++ b/spec/features/users/online_booking/on_rdv_mairie_spec.rb @@ -224,10 +224,9 @@ def json_response context "ANTS responds with an unexpected error" do before do - stub_request(:get, "https://int.api-coordination.rendezvouspasseport.ants.gouv.fr/api/status?application_ids=5544332211").to_return( - status: 500, - body: "Internal Server Error" - ) + stub_request(:get, "https://int.api-coordination.rendezvouspasseport.ants.gouv.fr/api/status") + .with(query: hash_including(application_ids: "5544332211")) + .to_return(status: 500, body: "Internal Server Error") end it "detects wrong format without calling ANTS API an warns user" do diff --git a/spec/models/concerns/ants/appointment_serializer_and_listener_spec.rb b/spec/models/concerns/ants/appointment_serializer_and_listener_spec.rb index 50ee1ecf82..a210ed55ea 100644 --- a/spec/models/concerns/ants/appointment_serializer_and_listener_spec.rb +++ b/spec/models/concerns/ants/appointment_serializer_and_listener_spec.rb @@ -36,7 +36,7 @@ let!(:status_stub) do stub_request(:get, "#{api_url}/status") - .with(query: { application_ids: "A123456789" }, headers:) + .with(query: hash_including(application_ids: "A123456789"), headers:) .to_return(status: 200, body: { "A123456789" => { status: "validated", appointments: [] } }.to_json) end let!(:create_stub) do @@ -103,7 +103,7 @@ let!(:status_stub) do stub_request(:get, "#{api_url}/status") - .with(query: { application_ids: "A123456789" }, headers:) + .with(query: hash_including(application_ids: "A123456789"), headers:) .to_return( status: 200, body: { @@ -155,7 +155,7 @@ let!(:status_stub) do stub_request(:get, "#{api_url}/status") - .with(query: { application_ids: "A123456789" }, headers:) + .with(query: hash_including(application_ids: "A123456789"), headers:) .to_return( status: 200, body: { @@ -208,7 +208,7 @@ let!(:status_stub) do stub_request(:get, "#{api_url}/status") - .with(query: { application_ids: "A123456789" }, headers:) + .with(query: hash_including(application_ids: "A123456789"), headers:) .to_return( status: 200, body: { "A123456789" => { status: "consumed", appointments: [] } }.to_json @@ -236,7 +236,7 @@ let!(:status_stub) do stub_request(:get, "#{api_url}/status") - .with(query: { application_ids: "A123456789" }, headers:) + .with(query: hash_including(application_ids: "A123456789"), headers:) .to_return( status: 200, body: { @@ -305,7 +305,7 @@ let!(:status_stub) do stub_request(:get, "#{api_url}/status") - .with(query: { application_ids: "AABBCCDDEE" }, headers:) + .with(query: hash_including(application_ids: "AABBCCDDEE"), headers:) .to_return(status: 200, body: { "AABBCCDDEE" => { status: "validated", appointments: [] } }.to_json) end let!(:create_stub) do @@ -345,7 +345,7 @@ let!(:status_stub) do stub_request(:get, "#{api_url}/status") - .with(query: { application_ids: "A123456789" }, headers:) + .with(query: hash_including(application_ids: "A123456789"), headers:) .to_return(status: 200, body: { "A123456789" => { status: "validated", appointments: [] } }.to_json) end let!(:create_stub) do @@ -385,7 +385,7 @@ let!(:status_stub) do stub_request(:get, "#{api_url}/status") - .with(query: { application_ids: "A123456789" }, headers:) + .with(query: hash_including(application_ids: "A123456789"), headers:) .to_return(status: 200, body: { "A123456789" => { status: "validated", appointments: [] } }.to_json) end let!(:create_stub) do @@ -425,7 +425,7 @@ let!(:status_stub) do stub_request(:get, "#{api_url}/status") - .with(query: { application_ids: "A123456789" }, headers:) + .with(query: hash_including(application_ids: "A123456789"), headers:) .to_return( status: 200, body: { diff --git a/spec/services/ants_api_spec.rb b/spec/services/ants_api_spec.rb index 42171fa347..83caae84c6 100644 --- a/spec/services/ants_api_spec.rb +++ b/spec/services/ants_api_spec.rb @@ -4,14 +4,16 @@ describe ".status" do context "when credentials are incorrect" do before do - stub_request(:get, "https://int.api-coordination.rendezvouspasseport.ants.gouv.fr/api/status?application_ids=1122334455").to_return( - status: 401, - body: <<~JSON - { - "detail": "X-RDV-OPT-AUTH-TOKEN header invalid" - } - JSON - ) + stub_request(:get, "https://int.api-coordination.rendezvouspasseport.ants.gouv.fr/api/status") + .with(query: hash_including(application_ids: "1122334455")) + .to_return( + status: 401, + body: <<~JSON + { + "detail": "X-RDV-OPT-AUTH-TOKEN header invalid" + } + JSON + ) end it "raises an error" do diff --git a/spec/support/ants_stubs.rb b/spec/support/ants_stubs.rb index 85e9fe431e..0c748e3722 100644 --- a/spec/support/ants_stubs.rb +++ b/spec/support/ants_stubs.rb @@ -1,8 +1,10 @@ def stub_ants_status(application_id, status: "validated", appointments: []) - stub_request(:get, "https://int.api-coordination.rendezvouspasseport.ants.gouv.fr/api/status?application_ids=#{application_id}").to_return( - status: 200, - body: { application_id => { status: status, appointments: appointments } }.to_json - ) + stub_request(:get, "https://int.api-coordination.rendezvouspasseport.ants.gouv.fr/api/status") + .with(query: hash_including(application_ids: application_id)) + .to_return( + status: 200, + body: { application_id => { status: status, appointments: appointments } }.to_json + ) end def stub_ants_create(application_id)