Skip to content

Commit 7777220

Browse files
committed
Refactor stubbed request for immunisation api
This is a minor refactoring pulled out to make the changes clearer. Following changes will use this refactor to add the update specs. Jira-Issue: MAV-1012
1 parent 50d3f45 commit 7777220

1 file changed

Lines changed: 21 additions & 31 deletions

File tree

spec/lib/nhs/immunisations_api_spec.rb

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,50 +47,40 @@
4747
created_at: Time.zone.parse("2021-02-07T13:28:17.271+00:00")
4848
)
4949
end
50-
let!(:stubbed_request) do
51-
stub_request(
52-
:post,
53-
"https://sandbox.api.service.nhs.uk/immunisation-fhir-api/FHIR/R4/Immunization"
54-
).to_return(
55-
status: 201,
56-
body: "",
57-
headers: {
58-
location:
59-
"https://sandbox.api.service.nhs.uk/immunisation-fhir-api/Immunization/ffff1111-eeee-2222-dddd-3333eeee4444"
60-
}
61-
)
62-
end
6350

6451
describe "record_immunisation" do
65-
before { Flipper.enable(:immunisations_fhir_api_integration) }
52+
let!(:request_stub) do
53+
stub_request(
54+
:post,
55+
"https://sandbox.api.service.nhs.uk/immunisation-fhir-api/FHIR/R4/Immunization"
56+
).to_return(
57+
status: 201,
58+
body: "",
59+
headers: {
60+
location:
61+
"https://sandbox.api.service.nhs.uk/immunisation-fhir-api/Immunization/ffff1111-eeee-2222-dddd-3333eeee4444"
62+
}
63+
)
64+
end
6665

6766
it "sends the correct JSON payload" do
6867
expected_body =
6968
File.read(Rails.root.join("spec/fixtures/fhir/immunisation.json")).chomp
7069

71-
# stree-ignore
72-
stubbed_request =
73-
stub_request(
74-
:post, "https://sandbox.api.service.nhs.uk/immunisation-fhir-api/FHIR/R4/Immunization"
70+
request_stub.with do |request|
71+
expect(request.headers).to include(
72+
{
73+
"Accept" => "application/fhir+json",
74+
"Content-Type" => "application/fhir+json"
75+
}
7576
)
76-
.with { |request|
77-
expect(request.headers["Accept"]).to eq "application/fhir+json"
78-
expect(
79-
request.headers["Content-Type"]
80-
).to eq "application/fhir+json"
8177
expect(request.body).to eq expected_body
8278
true
83-
}
84-
.to_return(status: 201,
85-
body: "",
86-
headers: {
87-
location:
88-
"https://sandbox.api.service.nhs.uk/immunisation-fhir-api/Immunization/ffff1111-eeee-2222-dddd-3333eeee4444"
89-
})
79+
end
9080

9181
described_class.record_immunisation(vaccination_record)
9282

93-
expect(stubbed_request).to have_been_made
83+
expect(request_stub).to have_been_made
9484
end
9585

9686
it "stores the id from the response" do

0 commit comments

Comments
 (0)