Skip to content

Commit e108ba4

Browse files
authored
Merge branch 'main' into feature/CCM-12845
2 parents 14825dd + cb1488f commit e108ba4

13 files changed

Lines changed: 270 additions & 54 deletions

File tree

.github/actions/acceptance-tests/action.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ runs:
3737
- name: "Repo setup"
3838
uses: ./.github/actions/node-install
3939
with:
40-
node-version: ${{ steps.nodejs_version.outputs.nodejs_version }}
4140
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
4241

4342
- name: "Set PR NUMBER"

.github/actions/node-install/action.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ name: 'npm install and setup'
22
description: 'Setup node, authenticate github package repository and perform clean npm install'
33

44
inputs:
5-
node-version:
6-
description: 'Node.js version'
7-
required: true
85
GITHUB_TOKEN:
96
description: "Token for access to github package registry"
107
required: true
@@ -15,7 +12,7 @@ runs:
1512
- name: 'Use Node.js'
1613
uses: actions/setup-node@v6
1714
with:
18-
node-version: '${{ inputs.node-version }}'
15+
node-version-file: '.tool-versions'
1916
registry-url: 'https://npm.pkg.github.com'
2017
scope: '@nhsdigital'
2118

.github/workflows/pr_closed.yaml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080
- name: Setup NodeJS
8181
uses: actions/setup-node@v4
8282
with:
83-
node-version: ${{ inputs.nodejs_version }}
83+
node-version-file: '.tool-versions'
8484
registry-url: 'https://npm.pkg.github.com'
8585

8686
- name: check if local version differs from latest published version
@@ -113,19 +113,14 @@ jobs:
113113
steps:
114114
- name: "Checkout code"
115115
uses: actions/checkout@v5.0.0
116-
- name: Setup NodeJS
117-
uses: actions/setup-node@v4
116+
- name: "Repo setup"
117+
uses: ./.github/actions/node-install
118118
with:
119-
node-version: ${{ inputs.nodejs_version }}
120-
registry-url: 'https://npm.pkg.github.com'
121-
- name: "Install dependencies"
122-
env:
123-
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
124-
run: npm ci
119+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
125120
- name: "Run provider contract tests"
126121
run: make test-contract
127122
env:
128-
GITHUB_PACKAGES_TOKEN: ${{ secrets.GITHUB_TOKEN }}
123+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
129124

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

151146
- name: Install dependencies

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ test-component:
106106
test-performance:
107107
(cd tests && npm install && npm run test:performance)
108108

109+
test-contract: # Run provider contract tests @Testing
110+
npm run test:contracts --workspace tests/contracts/provider
111+
109112
version:
110113
rm -f .version
111114
make version-create-effective-file dir=.

package-lock.json

Lines changed: 100 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
},
5252
"name": "nhs-notify-supplier-api",
5353
"overrides": {
54+
"fast-xml-parser": "^5.3.4",
5455
"pretty-format": {
5556
"react-is": "19.0.0"
5657
},
@@ -89,6 +90,7 @@
8990
"lambdas/*",
9091
"pact-contracts",
9192
"scripts/utilities/*",
92-
"tests"
93+
"tests",
94+
"tests/contracts/*"
9395
]
9496
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { MessageProviderPact } from "@pact-foundation/pact";
2+
import {
3+
LETTER_STATUSES,
4+
getMessageProviderForStatus,
5+
getPactUrlForStatus,
6+
} from "./utils/utils";
7+
8+
const CONSUMER_PACKAGE = "@nhsdigital/notify-core-consumer-contracts";
9+
10+
describe("Supplier API letter status provider tests", () => {
11+
describe.each(LETTER_STATUSES)("letter.%s event", (status) => {
12+
test(`verifies letter-${status.toLowerCase()} pact`, async () => {
13+
const p = new MessageProviderPact({
14+
provider: `letter-${status.toLowerCase()}`,
15+
messageProviders: getMessageProviderForStatus(status),
16+
pactUrls: [getPactUrlForStatus(CONSUMER_PACKAGE, status)],
17+
logLevel: "error",
18+
});
19+
20+
await expect(p.verify()).resolves.not.toThrow();
21+
}, 60_000);
22+
});
23+
});
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import path from "node:path";
2+
import fs from "node:fs";
3+
4+
export const LETTER_STATUSES = [
5+
"ACCEPTED",
6+
"CANCELLED",
7+
"DELIVERED",
8+
"DISPATCHED",
9+
"ENCLOSED",
10+
"FAILED",
11+
"FORWARDED",
12+
"PENDING",
13+
"PRINTED",
14+
"REJECTED",
15+
"RETURNED",
16+
] as const;
17+
18+
type LetterStatus = (typeof LETTER_STATUSES)[number];
19+
20+
export function getExampleEvent(status: LetterStatus): unknown {
21+
const examplePath = path.join(
22+
__dirname,
23+
"../../../../../internal/events/schemas/examples",
24+
`letter.${status}.json`,
25+
);
26+
27+
const content = fs.readFileSync(examplePath, "utf8");
28+
return JSON.parse(content);
29+
}
30+
31+
export function getMessageProviderForStatus(
32+
status: LetterStatus,
33+
): Record<string, () => Promise<unknown>> {
34+
return {
35+
[`letter-${status.toLowerCase()}`]: async () => getExampleEvent(status),
36+
};
37+
}
38+
39+
export function getPactUrlForStatus(
40+
consumerPackage: string,
41+
status: LetterStatus,
42+
): string {
43+
return path.join(
44+
__dirname,
45+
"../../",
46+
".contracts",
47+
consumerPackage,
48+
"pacts",
49+
"supplier-api",
50+
`core-letter-${status.toLowerCase()}.json`,
51+
);
52+
}
53+
54+
export function getAllLetterStatuses(): readonly LetterStatus[] {
55+
return LETTER_STATUSES;
56+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { Config } from "jest";
2+
3+
const config: Config = {
4+
testEnvironment: "node",
5+
transform: {
6+
"^.+\\.tsx?$": "ts-jest",
7+
},
8+
testMatch: ["**/*.test.ts"],
9+
moduleNameMapper: {
10+
"@nhsdigital/nhs-notify-event-schemas-supplier-api$":
11+
"<rootDir>/../../../internal/events/src",
12+
},
13+
};
14+
15+
export default config;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "@sap/contracts-provider",
3+
"version": "1.0.0",
4+
"private": true,
5+
"scripts": {
6+
"lint": "eslint .",
7+
"lint:fix": "eslint . --fix",
8+
"test:contracts": "./scripts/test.sh",
9+
"test:unit": "echo Unit tests not required",
10+
"typecheck": "tsc --noEmit"
11+
},
12+
"dependencies": {
13+
"@nhsdigital/nhs-notify-event-schemas-supplier-api": "*",
14+
"@pact-foundation/pact": "^16.0.4"
15+
},
16+
"devDependencies": {
17+
"@tsconfig/node22": "^22.0.2",
18+
"@types/jest": "^30.0.0",
19+
"@types/node": "^22.0.0",
20+
"eslint": "^9.27.0",
21+
"glob": "^11.0.0",
22+
"jest": "^30.0.0",
23+
"ts-jest": "^29.4.0",
24+
"typescript": "^5.9.3"
25+
}
26+
}

0 commit comments

Comments
 (0)