Skip to content

Commit

Permalink
Passage d’un meeting_point_id vide à l’appel API ANTS status (#4940)
Browse files Browse the repository at this point in the history
* generisation des specs pour utiliser query: hash_including(appointment_ids:)

* Passage d’un meeting_point_id vide à l’appel API ANTS status
  • Loading branch information
adipasquale authored Jan 7, 2025
1 parent c7b7357 commit 1564935
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 31 deletions.
7 changes: 5 additions & 2 deletions app/lib/ants_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions app/validators/ants_pre_demande_number_validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions spec/features/users/online_booking/on_rdv_mairie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: {
Expand Down
18 changes: 10 additions & 8 deletions spec/services/ants_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions spec/support/ants_stubs.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 1564935

Please sign in to comment.