Skip to content

Commit 167aea9

Browse files
committed
CCM-15633: Relax pact test contract
1 parent 724d6fd commit 167aea9

3 files changed

Lines changed: 26 additions & 54 deletions

File tree

package-lock.json

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

tests/pact-tests/consumer/channel-status-published.consumer.pact.test.ts

Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { $ChannelStatusPublishedEventV1 } from '@nhsdigital/nhs-notify-event-schemas-status-published';
2-
import createdEvent from '@nhsdigital/nhs-notify-event-schemas-status-published/examples/ChannelStatusPublishedEvent/v1/created.json';
1+
import ChannelStatusPublishedEventPaperLetterOptedOut from '@nhsdigital/nhs-notify-event-schemas-status-published/examples/ChannelStatusPublishedEvent/v1/paper_letter_opted_out.json';
32
import {
43
MatchersV3,
54
MessageConsumerPact,
65
asynchronousBodyHandler,
76
} from '@pact-foundation/pact';
7+
import { z } from 'zod';
88

99
import {
1010
PACT_CONSUMER,
@@ -13,8 +13,17 @@ import {
1313
PACT_PROVIDER,
1414
} from '../utils/pact-config';
1515

16+
const ChannelStatusPublishedEventSchema = z.object({
17+
data: z.object({
18+
messageReference: z.string(),
19+
supplierStatus: z.literal('paper_letter_opted_out'),
20+
}),
21+
});
22+
1623
async function handle(event: unknown) {
17-
$ChannelStatusPublishedEventV1.parse(event);
24+
// This should ultimately reference the actual event validation code
25+
// being implemented in CCM-15676
26+
ChannelStatusPublishedEventSchema.parse(event);
1827
}
1928

2029
describe('Pact message consumer - ChannelStatusPublished event', () => {
@@ -31,53 +40,15 @@ describe('Pact message consumer - ChannelStatusPublished event', () => {
3140
messagePact
3241
.expectsToReceive(PACT_MESSAGE_DESCRIPTION)
3342
.withContent({
34-
datacontenttype: 'application/json',
3543
data: {
36-
channel: MatchersV3.regex(
37-
/^(email|sms|letter|nhsapp)$/,
38-
createdEvent.data.channel,
39-
),
40-
channelStatus: MatchersV3.regex(
41-
/^(failed|created|delivered|sending|assigning_batch|retry|skipped|stale_pds)$/,
42-
createdEvent.data.channelStatus,
43-
),
44-
clientId: MatchersV3.uuid(createdEvent.data.clientId),
45-
messageId: MatchersV3.string(createdEvent.data.messageId),
4644
messageReference: MatchersV3.string(
47-
createdEvent.data.messageReference,
48-
),
49-
timestamp: MatchersV3.regex(
50-
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/,
51-
createdEvent.data.timestamp,
45+
ChannelStatusPublishedEventPaperLetterOptedOut.data
46+
.messageReference,
5247
),
53-
supplierStatus: 'paper_letter_opted_out',
48+
supplierStatus:
49+
ChannelStatusPublishedEventPaperLetterOptedOut.data
50+
.supplierStatus,
5451
},
55-
dataschema: MatchersV3.regex(
56-
/^https:\/\/notify\.nhs\.uk\/cloudevents\/schemas\/messaging\/channel-status\.published\.\d+\.\d+\.\d+\.schema\.json$/,
57-
createdEvent.dataschema,
58-
),
59-
dataschemaversion: MatchersV3.regex(
60-
/^\d+\.\d+\.\d+$/,
61-
createdEvent.dataschemaversion,
62-
),
63-
id: MatchersV3.uuid(createdEvent.id),
64-
plane: 'data',
65-
sequence: MatchersV3.string(createdEvent.sequence),
66-
source: MatchersV3.string(createdEvent.source),
67-
specversion: MatchersV3.regex(/^1\.0$/, createdEvent.specversion),
68-
subject: MatchersV3.regex(
69-
/^customer\/[0-9a-f-]+\/message\/[^/]+\/plan\/[^/]+$/,
70-
createdEvent.subject,
71-
),
72-
time: MatchersV3.datetime(
73-
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
74-
createdEvent.time,
75-
),
76-
traceparent: MatchersV3.regex(
77-
/^00-[0-9a-f]{32}-[0-9a-f]{16}-0[01]$/,
78-
createdEvent.traceparent,
79-
),
80-
type: 'uk.nhs.notify.channel.status.PUBLISHED.v1',
8152
})
8253
.verify(asynchronousBodyHandler(handle)),
8354
).resolves.not.toThrow();

tests/pact-tests/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
{
2-
"dependencies": {
3-
"@nhsdigital/nhs-notify-event-schemas-status-published": "^1.0.1"
4-
},
52
"devDependencies": {
3+
"@nhsdigital/nhs-notify-event-schemas-status-published": "^1.0.1",
64
"@pact-foundation/pact": "^16.3.0",
75
"@types/jest": "^29.5.14",
86
"jest": "^29.7.0",
9-
"rimraf": "^6.0.1"
7+
"rimraf": "^6.0.1",
8+
"zod": "^4.3.6"
109
},
1110
"name": "nhs-notify-digital-letters-pact-tests",
1211
"private": true,

0 commit comments

Comments
 (0)