Skip to content

Add contract tests for SDS FHIR API stub#147

Merged
Vox-Ben merged 7 commits intofeature/GPCAPIM-350_sds_stub_contract_testsfrom
copilot/add-contract-tests-for-sds-stub
Apr 2, 2026
Merged

Add contract tests for SDS FHIR API stub#147
Vox-Ben merged 7 commits intofeature/GPCAPIM-350_sds_stub_contract_testsfrom
copilot/add-contract-tests-for-sds-stub

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 30, 2026

The SdsFhirApiStub had no contract tests to verify it faithfully emulates the SDS OpenAPI spec. This adds a contract test suite.

New files

  • tests/contract/stub/test_sds_stub_contract.py — 78 contract tests across 7 classes, calling stub methods directly and asserting on the returned requests.Response objects:
Class Scope
TestGetDeviceBundleSuccess GET /Device 200: Bundle shape, entry fields, X-Correlation-Id echo, empty result for unknown org
TestGetDeviceResourceStructure Device resource fields: id, identifier list (ASID + party key), owner with ODS system
TestGetDeviceBundleValidationErrors 400s for missing apikey, organization, identifier, missing interaction ID; OperationOutcome shape
TestGetEndpointBundleSuccess GET /Endpoint 200: same Bundle checks, optional organization, empty result for unknown party key
TestGetEndpointResourceStructure Endpoint resource fields: status=active, connectionType, payloadType, address, managingOrganization, identifiers
TestGetEndpointBundleValidationErrors 400s for missing apikey / identifier; OperationOutcome shape
TestGetConvenienceMethod get() URL routing (Device vs Endpoint), last-call metadata recording, error propagation
TestUpsertOperations upsert_device / clear_devices / upsert_endpoint / clear_endpoints round-trips

Key contract assertions

# FHIR-style parameter encoding verified throughout
_INTERACTION_ID_PARAM = (
    f"{FHIRSystem.NHS_SERVICE_INTERACTION_ID}|{ACCESS_RECORD_STRUCTURED_INTERACTION_ID}"
)

# GET /Device requires apikey + organization + identifier(with interaction ID)
# GET /Endpoint requires apikey + identifier only (organization is optional)
# Both return Bundle{type: "searchset"} with total == len(entry)
# X-Correlation-Id echoed on success AND error responses
# Missing/invalid inputs → 400 OperationOutcome{issue[].severity, .code, .diagnostics}
Original prompt

The file gateway-api/stubs/stubs/sds/stub.py contains a stub implementation for an external service called SDS that is used for testing. The file is a test harness and as such does not need unit tests, but we do want contract tests to verify that the stub interface matches that of the service it is meant to emulate.

The repository for the SDS service can be found on Github at https://github.com/NHSDigital/spine-directory-service-api. The OpenAPI specifications for the SDS service are available in this repository in the specification directory.

Can you please:

  • Create a test_pds_stub_contract.py file in the tests/contract/stub directory to hold the new contract tests.
  • Write contract tests for the SDS stub to ensure that the stub matches the OpenAPI contract.
  • When you have finished and the tests are working, create a markdown document that describes in detail what each part of the code does. The document should be detailed enough to understand the exact algorithm used in each code block solely by reading the document, without reference to the code itself.

Do not change stub.py, this file is correct.

Created from VS Code via the GitHub Pull Request extension.

Copilot AI changed the title [WIP] Add contract tests for SDS stub implementation Add contract tests for SDS FHIR API stub Mar 30, 2026
Copilot AI requested a review from Vox-Ben March 30, 2026 22:05
@Vox-Ben
Copy link
Copy Markdown
Contributor

Vox-Ben commented Apr 1, 2026

@copilot tests/contract/stub/sds_stub_contract_tests.md has lots of trailing whitespace, please remove this.

Copy link
Copy Markdown
Author

Copilot AI commented Apr 1, 2026

@copilot tests/contract/stub/sds_stub_contract_tests.md has lots of trailing whitespace, please remove this.

Fixed in a0a1fdc — removed trailing whitespace from all 78 affected lines.

@Vox-Ben
Copy link
Copy Markdown
Contributor

Vox-Ben commented Apr 1, 2026

@copilot Please remove tests/contract/stub/sds_stub_contract_tests.md

Copy link
Copy Markdown
Author

Copilot AI commented Apr 1, 2026

@copilot Please remove tests/contract/stub/sds_stub_contract_tests.md

Done — file removed in 231758f.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 1, 2026

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

Deployment Complete

@Vox-Ben Vox-Ben marked this pull request as ready for review April 2, 2026 14:56
@Vox-Ben Vox-Ben requested a review from a team as a code owner April 2, 2026 14:56
@Vox-Ben Vox-Ben merged commit fa59278 into feature/GPCAPIM-350_sds_stub_contract_tests Apr 2, 2026
53 checks passed
@Vox-Ben Vox-Ben deleted the copilot/add-contract-tests-for-sds-stub branch April 2, 2026 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants