Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/actions/acceptance-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ runs:
- name: "Repo setup"
uses: ./.github/actions/node-install
with:
node-version: ${{ steps.nodejs_version.outputs.nodejs_version }}
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}

- name: "Set PR NUMBER"
Expand Down
5 changes: 1 addition & 4 deletions .github/actions/node-install/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: 'npm install and setup'
description: 'Setup node, authenticate github package repository and perform clean npm install'

inputs:
node-version:
description: 'Node.js version'
required: true
GITHUB_TOKEN:
description: "Token for access to github package registry"
required: true
Expand All @@ -15,7 +12,7 @@ runs:
- name: 'Use Node.js'
uses: actions/setup-node@v6
with:
node-version: '${{ inputs.node-version }}'
node-version-file: '.tool-versions'
registry-url: 'https://npm.pkg.github.com'
scope: '@nhsdigital'

Expand Down
17 changes: 6 additions & 11 deletions .github/workflows/pr_closed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.nodejs_version }}
node-version-file: '.tool-versions'
registry-url: 'https://npm.pkg.github.com'

- name: check if local version differs from latest published version
Expand Down Expand Up @@ -113,19 +113,14 @@ jobs:
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
- name: Setup NodeJS
uses: actions/setup-node@v4
- name: "Repo setup"
uses: ./.github/actions/node-install
with:
node-version: ${{ inputs.nodejs_version }}
registry-url: 'https://npm.pkg.github.com'
- name: "Install dependencies"
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm ci
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: "Run provider contract tests"
run: make test-contract
env:
GITHUB_PACKAGES_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish-event-schemas:
name: Publish event schemas package to GitHub package registry
Expand All @@ -145,7 +140,7 @@ jobs:
- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.nodejs_version }}
node-version-file: '.tool-versions'
registry-url: 'https://npm.pkg.github.com'

- name: Install dependencies
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ test-component:
test-performance:
(cd tests && npm install && npm run test:performance)

test-contract: # Run provider contract tests @Testing
npm run test:contracts --workspace tests/contracts/provider

version:
rm -f .version
make version-create-effective-file dir=.
Expand Down
107 changes: 98 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"lambdas/*",
"pact-contracts",
"scripts/utilities/*",
"tests"
"tests",
"tests/contracts/*"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { MessageProviderPact } from "@pact-foundation/pact";
import {
LETTER_STATUSES,
getMessageProviderForStatus,
getPactUrlForStatus,
} from "./utils/utils";

const CONSUMER_PACKAGE = "@nhsdigital/notify-core-consumer-contracts";

describe("Supplier API letter status provider tests", () => {
describe.each(LETTER_STATUSES)("letter.%s event", (status) => {
test(`verifies letter-${status.toLowerCase()} pact`, async () => {
const p = new MessageProviderPact({
provider: `letter-${status.toLowerCase()}`,
messageProviders: getMessageProviderForStatus(status),
pactUrls: [getPactUrlForStatus(CONSUMER_PACKAGE, status)],
logLevel: "error",
});

await expect(p.verify()).resolves.not.toThrow();
}, 60_000);
});
});
56 changes: 56 additions & 0 deletions tests/contracts/provider/__tests__/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import path from "node:path";
import fs from "node:fs";

export const LETTER_STATUSES = [
"ACCEPTED",
"CANCELLED",
"DELIVERED",
"DISPATCHED",
"ENCLOSED",
"FAILED",
"FORWARDED",
"PENDING",
"PRINTED",
"REJECTED",
"RETURNED",
] as const;

type LetterStatus = (typeof LETTER_STATUSES)[number];

export function getExampleEvent(status: LetterStatus): unknown {
const examplePath = path.join(
__dirname,
"../../../../../internal/events/schemas/examples",
`letter.${status}.json`,
);

const content = fs.readFileSync(examplePath, "utf8");
return JSON.parse(content);
}

export function getMessageProviderForStatus(
status: LetterStatus,
): Record<string, () => Promise<unknown>> {
return {
[`letter-${status.toLowerCase()}`]: async () => getExampleEvent(status),
};
}

export function getPactUrlForStatus(
consumerPackage: string,
status: LetterStatus,
): string {
return path.join(
__dirname,
"../../",
".contracts",
consumerPackage,
"pacts",
"supplier-api",
`core-letter-${status.toLowerCase()}.json`,
);
}

export function getAllLetterStatuses(): readonly LetterStatus[] {
return LETTER_STATUSES;
}
15 changes: 15 additions & 0 deletions tests/contracts/provider/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Config } from "jest";

const config: Config = {
testEnvironment: "node",
transform: {
"^.+\\.tsx?$": "ts-jest",
},
testMatch: ["**/*.test.ts"],
moduleNameMapper: {
"@nhsdigital/nhs-notify-event-schemas-supplier-api$":
"<rootDir>/../../../internal/events/src",
},
};

export default config;
26 changes: 26 additions & 0 deletions tests/contracts/provider/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@sap/contracts-provider",
"version": "1.0.0",
"private": true,
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"test:contracts": "./scripts/test.sh",
"test:unit": "echo Unit tests not required",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@nhsdigital/nhs-notify-event-schemas-supplier-api": "*",
"@pact-foundation/pact": "^16.0.4"
},
"devDependencies": {
"@tsconfig/node22": "^22.0.2",
"@types/jest": "^30.0.0",
"@types/node": "^22.0.0",
"eslint": "^9.27.0",
"glob": "^11.0.0",
"jest": "^30.0.0",
"ts-jest": "^29.4.0",
"typescript": "^5.9.3"
}
}
24 changes: 24 additions & 0 deletions tests/contracts/provider/scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

set -euo pipefail

ROOT_DIR="$(git rev-parse --show-toplevel)"
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
TESTS_ROOT="$(dirname "$SCRIPT_DIR")"

cd "$TESTS_ROOT"

rm -rf .packages .contracts
mkdir -p .packages

CONSUMER_PACKAGES=(
"@nhsdigital/notify-core-consumer-contracts"
)

for PKG in "${CONSUMER_PACKAGES[@]}"; do
mkdir -p ".contracts/$PKG"
TGZ_NAME=$(npm pack "$PKG" --pack-destination .packages)
tar -xvzf ".packages/$TGZ_NAME" -C ".contracts/$PKG" --strip-components=1
done

npx jest --runInBand
12 changes: 12 additions & 0 deletions tests/contracts/provider/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "@tsconfig/node22/tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./",
"resolveJsonModule": true,
"esModuleInterop": true,
"isolatedModules": true
},
"include": ["**/*.ts"],
"exclude": ["node_modules", "dist"]
}
Loading
Loading