|
301 | 301 | include_examples "an imms_api_integration feature flag check"
|
302 | 302 | end
|
303 | 303 |
|
| 304 | + describe "read immunisation" do |
| 305 | + subject(:perform_request) do |
| 306 | + described_class.read_immunisation(vaccination_record) |
| 307 | + end |
| 308 | + |
| 309 | + let(:status) { 200 } |
| 310 | + let(:body) { file_fixture("fhir/fhir_record_full.json").read } |
| 311 | + let(:headers) { { "content-type" => "application/fhir+json" } } |
| 312 | + |
| 313 | + let!(:request_stub) do |
| 314 | + stub_request( |
| 315 | + :get, |
| 316 | + "https://sandbox.api.service.nhs.uk/immunisation-fhir-api/FHIR/R4/Immunization/ffff1111-eeee-2222-dddd-3333eeee4444" |
| 317 | + ).to_return(status:, body:, headers:) |
| 318 | + end |
| 319 | + |
| 320 | + before do |
| 321 | + vaccination_record.update( |
| 322 | + nhs_immunisations_api_id: "ffff1111-eeee-2222-dddd-3333eeee4444" |
| 323 | + ) |
| 324 | + end |
| 325 | + |
| 326 | + include_examples "an imms_api_integration feature flag check" |
| 327 | + |
| 328 | + it "sends the correct request" do |
| 329 | + request_stub.with do |request| |
| 330 | + expect(request.headers).to include( |
| 331 | + { "Accept" => "application/fhir+json" } |
| 332 | + ) |
| 333 | + end |
| 334 | + |
| 335 | + perform_request |
| 336 | + |
| 337 | + expect(request_stub).to have_been_made |
| 338 | + end |
| 339 | + |
| 340 | + it "returns the FHIR record" do |
| 341 | + expect(perform_request).to be_a FHIR::Immunization |
| 342 | + end |
| 343 | + |
| 344 | + context "an error is returned by the api" do |
| 345 | + let(:code) { nil } |
| 346 | + let(:diagnostics) { nil } |
| 347 | + |
| 348 | + let(:body) do |
| 349 | + { |
| 350 | + resourceType: "OperationOutcome", |
| 351 | + id: "bc2c3c82-4392-4314-9d6b-a7345f82d923", |
| 352 | + meta: { |
| 353 | + profile: [ |
| 354 | + "https://simplifier.net/guide/UKCoreDevelopment2/ProfileUKCore-OperationOutcome" |
| 355 | + ] |
| 356 | + }, |
| 357 | + issue: [ |
| 358 | + { |
| 359 | + severity: "error", |
| 360 | + code: "invalid", |
| 361 | + details: { |
| 362 | + coding: [ |
| 363 | + { |
| 364 | + system: "https://fhir.nhs.uk/Codesystem/http-error-codes", |
| 365 | + code: |
| 366 | + } |
| 367 | + ] |
| 368 | + }, |
| 369 | + diagnostics: |
| 370 | + } |
| 371 | + ] |
| 372 | + }.to_json |
| 373 | + end |
| 374 | + |
| 375 | + include_examples "unexpected response status", 201, "reading" |
| 376 | + include_examples "client error (4XX) handling", "reading" |
| 377 | + include_examples "generic error handling" |
| 378 | + end |
| 379 | + end |
| 380 | + |
304 | 381 | describe "update immunisations" do
|
305 | 382 | subject(:perform_request) do
|
306 | 383 | described_class.update_immunisation(vaccination_record)
|
|
0 commit comments