CCM-15633: Add Pact tests for channel status published event#289
CCM-15633: Add Pact tests for channel status published event#289gareth-allan wants to merge 19 commits intomainfrom
Conversation
5cae08f to
eae77f1
Compare
eae77f1 to
393d599
Compare
040a8fb to
a4f5437
Compare
There was a problem hiding this comment.
Pull request overview
Adds Pact-based consumer/provider verification for the Channel Status Published event, and aligns Digital Letters CloudEvents to a new plane/dataschemaversion-driven convention (removing /data-plane/ from source), with CI automation to run and publish generated pact contracts.
Changes:
- Introduce a new
tests/pact-testsworkspace with consumer + provider verification, plus CI job + scripts to generate and publish pact contract artifacts. - Update CloudEvents schemas, generators, lambdas, and test fixtures to include
plane: "data"/dataschemaversion: "1.0.0"and adjustsourcepatterns accordingly. - Update several workspaces’
axiosdependency version specifier.
Reviewed changes
Copilot reviewed 113 out of 116 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| utils/utils/src/tests/event-publisher/event-publisher.test.ts | Updates test CloudEvent source strings to match new source convention. |
| utils/utils/package.json | Updates axios version specifier. |
| utils/py-utils/dl_utils/tests/test_event_publisher.py | Updates expected CloudEvent envelope fields (plane, dataschemaversion, source). |
| utils/comms-utils/package.json | Adds a local stub package to satisfy an upstream dependency. |
| utils/comms-utils/index.js | Exports empty module for stub package. |
| utils/comms-utils/index.d.ts | Provides empty type surface for stub package. |
| utils/comms-utils/README.md | Documents the stub package workaround. |
| tests/playwright/helpers/report-helpers.ts | Updates reporting event fixtures (plane, dataschemaversion, source). |
| tests/playwright/helpers/event-builders.ts | Updates shared builder to add plane/dataschemaversion and new source format. |
| tests/playwright/digital-letters-component-tests/ttl-handle.component.spec.ts | Updates test events to include plane/dataschemaversion and new source. |
| tests/playwright/digital-letters-component-tests/ttl-create.component.spec.ts | Updates test events to include plane/dataschemaversion and new source. |
| tests/playwright/digital-letters-component-tests/send-reports-trust.component.spec.ts | Updates test events to include plane/dataschemaversion and new source. |
| tests/playwright/digital-letters-component-tests/print-sender.component.spec.ts | Updates test events to include plane/dataschemaversion and new source. |
| tests/playwright/digital-letters-component-tests/print-analyser.component.spec.ts | Updates test events to include plane/dataschemaversion and new source. |
| tests/playwright/digital-letters-component-tests/pdm-uploader.component.spec.ts | Updates test events to include plane/dataschemaversion and new source. |
| tests/playwright/digital-letters-component-tests/pdm-poll.component.spec.ts | Updates test events to include plane/dataschemaversion and new source. |
| tests/playwright/digital-letters-component-tests/mesh-poll-download.component.spec.ts | Updates test events (plane, dataschemaversion, datacontenttype, source). |
| tests/playwright/digital-letters-component-tests/mesh-acknowledge.component.spec.ts | Updates test events to include plane/dataschemaversion and new source. |
| tests/playwright/digital-letters-component-tests/file-scanner.component.spec.ts | Updates queue event fixtures to include plane/dataschemaversion and new source. |
| tests/playwright/digital-letters-component-tests/core-notify.component.spec.ts | Updates PDM event fixtures to include plane/dataschemaversion and new source. |
| tests/pact-tests/utils/pact-config.ts | Adds shared Pact config constants and pact file location. |
| tests/pact-tests/tsconfig.json | Adds tsconfig for the pact-tests workspace. |
| tests/pact-tests/pact-verification/channel-status-published.provider.pact.test.ts | Adds local provider verification against generated pact(s). |
| tests/pact-tests/package.json | Adds pact-tests workspace package + scripts. |
| tests/pact-tests/jest.config.ts | Adds jest config for pact-tests (based on repo base config). |
| tests/pact-tests/consumer/channel-status-published.consumer.pact.test.ts | Adds consumer pact test validating schema parsing of the message. |
| tests/pact-tests/README.md | Documents pact-tests scope and command. |
| src/typescript-schema-generator/PLAN.md | Updates example source strings to the new format. |
| src/eventcatalog/package.json | Updates axios version specifier used in overrides. |
| src/digital-letters-events/README.md | Updates documentation examples for plane/dataschemaversion and new source format. |
| src/cloudevents/tools/generator/example-generator/example-generator.ts | Ensures generated examples include plane + dataschemaversion. |
| src/cloudevents/domains/digital-letters/2025-10-draft/supplierapi-profile.schema.yaml | Removes temporary Supplier API profile schema file. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.reporting.report.sent.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.reporting.report.generated.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.reporting.generate.report.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.queue.item.enqueued.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.queue.item.dequeued.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.queue.digital.letter.read.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.print.pdf.analysed.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.print.letter.transitioned.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.print.invalid.attachment.received.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.print.file.safe.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.print.file.quarantined.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.pdm.resource.unavailable.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.pdm.resource.submitted.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.pdm.resource.submission.rejected.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.pdm.resource.retries.exceeded.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.pdm.resource.available.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.messages.request.submitted.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.messages.request.skipped.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.messages.request.rejected.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.mesh.inbox.message.received.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.mesh.inbox.message.invalid.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.mesh.inbox.message.downloaded.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.mesh.inbox.message.acknowledged.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/events/uk.nhs.notify.digital.letters.letter.available.v1.schema.yaml | Updates source pattern to remove /data-plane/. |
| src/cloudevents/domains/digital-letters/2025-10-draft/digital-letters-viewer-profile.schema.yaml | Updates profile source pattern and minLength. |
| src/cloudevents/domains/digital-letters/2025-10-draft/digital-letters-reporting-profile.schema.yaml | Updates profile source pattern and minLength. |
| src/cloudevents/domains/digital-letters/2025-10-draft/digital-letters-queue-profile.schema.yaml | Updates profile source pattern and minLength. |
| src/cloudevents/domains/digital-letters/2025-10-draft/digital-letters-profile.schema.yaml | Updates base profile ref and adds plane/dataschemaversion/datacontenttype. |
| src/cloudevents/domains/digital-letters/2025-10-draft/digital-letters-print-profile.schema.yaml | Updates profile source pattern and minLength. |
| src/cloudevents/domains/digital-letters/2025-10-draft/digital-letters-pdm-profile.schema.yaml | Updates profile source pattern and minLength. |
| src/cloudevents/domains/digital-letters/2025-10-draft/digital-letters-messages-profile.schema.yaml | Updates profile source pattern and minLength. |
| src/cloudevents/domains/digital-letters/2025-10-draft/digital-letters-mesh-profile.schema.yaml | Updates profile source pattern and minLength. |
| src/cloudevents/domains/digital-letters/2025-10-draft/digital-letters-letter-profile.schema.yaml | Updates profile source pattern and minLength. |
| src/cloudevents/domains/digital-letters/2025-10-draft/digital-letters-fhir-profile.schema.yaml | Updates profile source pattern and minLength. |
| src/cloudevents/domains/digital-letters/2025-10-draft/digital-letters-event-bus-profile.schema.yaml | Updates profile source pattern and minLength. |
| scripts/tests/contract.sh | Adds contract test runner script for make test-contract. |
| scripts/publish-pact-contracts.sh | Adds script to publish pact contracts package to GitHub Packages. |
| scripts/config/sonar-scanner.properties | Excludes utils/comms-utils from coverage scanning. |
| project.code-workspace | Adds pact-tests workspace folder to VS Code workspace file. |
| pact-contracts/package.json | Adds a publishable package for generated pact JSON artifacts. |
| package.json | Adds test:contract script and includes tests/pact-tests workspace. |
| lambdas/ttl-handle-expiry-lambda/src/tests/apis/dynamodb-stream-handler.test.ts | Updates DynamoDB stream test fixture to match new CloudEvent envelope fields. |
| lambdas/ttl-create-lambda/src/tests/data.ts | Updates test fixture to include plane/dataschemaversion and new source. |
| lambdas/ttl-create-lambda/src/tests/apis/sqs-trigger-lambda.test.ts | Updates SQS-trigger TTL create test fixture source. |
| lambdas/report-sender/report_sender/report_sender_processor.py | Updates reporting event source and adds new envelope fields. |
| lambdas/report-sender/report_sender/tests/test_report_sender_processor.py | Updates expected event envelope fields (plane, dataschemaversion, source). |
| lambdas/report-scheduler/src/apis/scheduled-event-handler.ts | Adds envelope fields and updates source/dataschema for generate-report events. |
| lambdas/report-scheduler/src/tests/apis/scheduled-event-handler.test.ts | Updates assertions for new event envelope fields. |
| lambdas/report-generator/src/tests/app/report-generator.test.ts | Updates test event fixture to include envelope fields. |
| lambdas/report-generator/src/tests/apis/sqs-trigger-lambda.test.ts | Updates SQS record fixture to include envelope fields and new source. |
| lambdas/report-event-transformer/src/tests/test-data.ts | Updates fixture source string. |
| lambdas/refresh-apim-access-token/package.json | Updates axios version specifier. |
| lambdas/print-status-handler/src/apis/sqs-handler.ts | Updates output event source and sets plane/dataschemaversion. |
| lambdas/print-status-handler/src/tests/apis/sqs-handler.test.ts | Updates expected source and includes plane/dataschemaversion in fixtures. |
| lambdas/print-sender-lambda/src/tests/app/print-sender.test.ts | Updates PDFAnalysed fixture and validates plane. |
| lambdas/print-sender-lambda/src/tests/apis/sqs-trigger-lambda.test.ts | Updates PDFAnalysed fixture to include envelope fields and new source. |
| lambdas/print-analyser/src/apis/sqs-handler.ts | Updates generated event source string. |
| lambdas/print-analyser/src/tests/test-data.ts | Updates fixture to include plane/dataschemaversion and new source. |
| lambdas/print-analyser/src/tests/apis/sqs-handler.test.ts | Updates expected source string. |
| lambdas/pdm-uploader-lambda/src/tests/data.ts | Updates fixture to include plane/dataschemaversion and new source. |
| lambdas/pdm-uploader-lambda/package.json | Updates axios version specifier. |
| lambdas/pdm-poll-lambda/src/tests/test-data.ts | Updates fixture to include plane/dataschemaversion and new source. |
| lambdas/move-scanned-files-lambda/src/domain/mapper.ts | Adds envelope fields (plane, dataschema, dataschemaversion, datacontenttype) and updates source. |
| lambdas/move-scanned-files-lambda/src/tests/domain/mapper.test.ts | Updates expected events with new envelope fields and updated source. |
| lambdas/move-scanned-files-lambda/src/tests/apis/sqs-handler.test.ts | Updates SQS handler fixtures to include new envelope fields. |
| lambdas/move-scanned-files-lambda/package.json | Updates axios version specifier. |
| lambdas/mesh-poll/mesh_poll/processor.py | Updates source and adds envelope fields to published MESH events. |
| lambdas/mesh-download/mesh_download/processor.py | Adds envelope fields to published downloaded event. |
| lambdas/mesh-download/mesh_download/tests/test_processor.py | Updates fixtures and assertions for new envelope fields and source. |
| lambdas/mesh-acknowledge/mesh_acknowledge/events.py | Adds envelope fields to acknowledged event. |
| lambdas/mesh-acknowledge/mesh_acknowledge/tests/test_events.py | Updates fixtures/expected outputs for new envelope fields and source. |
| lambdas/mesh-acknowledge/mesh_acknowledge/tests/fixtures.py | Updates downloaded event fixture source and adds envelope fields. |
| lambdas/file-scanner-lambda/src/tests/apis/sqs-handler.test.ts | Updates fixtures to include plane/dataschemaversion and new source. |
| lambdas/core-notifier-lambda/src/tests/domain/mapper.test.ts | Updates fixture to include plane/dataschemaversion. |
| lambdas/core-notifier-lambda/src/tests/constants.ts | Updates PDM fixture to include envelope fields and dataschema. |
| lambdas/core-notifier-lambda/package.json | Updates axios version specifier. |
| infrastructure/terraform/components/dl/modules_eventpub.tf | Updates SNS publish policy condition to allow new EventBridge rule. |
| infrastructure/terraform/components/dl/cloudwatch_event_rule_data_plane.tf | Adds EventBridge rule/target routing “data plane” events to SNS topic. |
| eslint.config.mjs | Adds eslint override for tests/pact-tests relative import rule. |
| .gitignore | Ignores generated pact outputs and published pact package artifacts. |
| .github/workflows/stage-5-publish.yaml | Downloads pact contracts artifact and publishes pact-contracts package. |
| .github/workflows/stage-2-test.yaml | Adds a dedicated “Contract tests” job and uploads generated pact artifacts. |
| .github/workflows/cicd-1-pull-request.yaml | Changes workflow-level GitHub token permissions. |
a4f5437 to
d529b58
Compare
| if [[ $outdated_status -eq 1 ]]; then | ||
| echo "The provider schema package ($schema_package) is outdated." | ||
| echo "Please run npm update $schema_package to update to the latest version and re-run." | ||
| echo |
There was a problem hiding this comment.
The guidance message suggests running npm update @nhsdigital/nhs-notify-event-schemas-status-published, but this dependency is declared in the tests/pact-tests workspace (not the repo root). To avoid confusion and ensure the right lockfile entry is updated, consider pointing users at a workspace-scoped install/update command (and remind to commit package-lock.json).
| exit 0 | ||
| fi | ||
|
|
||
| if ! ls pact-contracts/pacts/**/*.json >/dev/null 2>&1; then |
There was a problem hiding this comment.
ls pact-contracts/pacts/**/*.json relies on Bash globstar to expand **, but globstar is disabled by default. This will often make the check fail even when pact JSON files exist, preventing publishing. Use find pact-contracts/pacts -type f -name '*.json' (or enable shopt -s globstar nullglob) to reliably detect pact files.
| if ! ls pact-contracts/pacts/**/*.json >/dev/null 2>&1; then | |
| if ! find pact-contracts/pacts -type f -name '*.json' -print -quit | grep -q .; then |
Description
This PR adds Pact tests for the
uk.nhs.notify.channel.status.PUBLISHED.v1event that will be consumed by digital letters to identify when a user has opted out of receiving the paper copy of their digital letter.Changes:
tests/pact-testschannel-status-published.consumer.pact.test.ts) that declares what Digital Letters expects in a uk.nhs.notify.channel.status.PUBLISHED.v1 event and makes sure the handler code we've implemented can properly handle an event matching our contract. Note: As we have not yet completed CCM-15676 there is no actual handler code to test, so a dummy function is used for the time-beingchannel-status-published.provider.pact.test.ts). This is a provider test in Pact terminology and is implemented here to allow us to verify the Pacts produced by the consumer test against the example events provided by the@nhsdigital/nhs-notify-event-schemas-status-published` that core publishesscripts/tests/contract.shscript so that themake test-contractMake target now runs the contract testspact-contractspackage (for pacts to be copied into by the CI workflow) and ascripts/publish-pact-contracts.shscript that will publish thepact-contractspackage as an NPM package called@nhsdigital/notify-digital-letters-consumer-contractsto our Github package repo, so it can be consumed by coresrc/cloudevents/domains/common.mkso that it works on both Mac and the Github runners (thanks @Ian-Hodges!)Context
As the
uk.nhs.notify.channel.status.PUBLISHED.v1event is published by core, we want to ensure there are tests in place that will identify is changes are made to core that would be incompatible with Digital Letters. Contract tests allow us to do this by ensuring that core is validating the events it produces against the requirements Digital Letters has declared (in the consumer test added as part of this PR).Validation
Publishing of the Contracts Package
Downloaded the latest pact contracts artifact from the CI workflow and extracted it to

pact-contracts/pacts:Updated

scripts/publish-pact-contracts.shto pass the--dry-runargument tonpm publish, then ran it:Using the Contracts Package
Downloaded the latest pact contracts artifact from the CI workflow and extracted it to

pact-contracts/pacts:Ran

npm pack ./pact-contracts:Copied the
nhsdigital-notify-digital-letters-consumer-contracts-1.0.0.tgzfile into my comms-mgr repository.Installed the package from file:

With the changes from this PR, ran the comms-mgr component tests:

Checking that Contract Tests Fail if the Schema Package is Outdated
I installed an outdated version of the @nhsdigital/nhs-notify-event-schemas-status-published package, tried to run the contract tests, then installed the latest version of the package and ran the contract tests again:

Type of changes
Checklist
Sensitive Information Declaration
To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.