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' ;
32import {
43 MatchersV3 ,
54 MessageConsumerPact ,
65 asynchronousBodyHandler ,
76} from '@pact-foundation/pact' ;
7+ import { z } from 'zod' ;
88
99import {
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+
1623async 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
2029describe ( '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- / ^ ( e m a i l | s m s | l e t t e r | n h s a p p ) $ / ,
38- createdEvent . data . channel ,
39- ) ,
40- channelStatus : MatchersV3 . regex (
41- / ^ ( f a i l e d | c r e a t e d | d e l i v e r e d | s e n d i n g | a s s i g n i n g _ b a t c h | r e t r y | s k i p p e d | s t a l e _ p d s ) $ / ,
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- / ^ h t t p s : \/ \/ n o t i f y \. n h s \. u k \/ c l o u d e v e n t s \/ s c h e m a s \/ m e s s a g i n g \/ c h a n n e l - s t a t u s \. p u b l i s h e d \. \d + \. \d + \. \d + \. s c h e m a \. j s o n $ / ,
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- / ^ c u s t o m e r \/ [ 0 - 9 a - f - ] + \/ m e s s a g e \/ [ ^ / ] + \/ p l a n \/ [ ^ / ] + $ / ,
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- / ^ 0 0 - [ 0 - 9 a - f ] { 32 } - [ 0 - 9 a - f ] { 16 } - 0 [ 0 1 ] $ / ,
78- createdEvent . traceparent ,
79- ) ,
80- type : 'uk.nhs.notify.channel.status.PUBLISHED.v1' ,
8152 } )
8253 . verify ( asynchronousBodyHandler ( handle ) ) ,
8354 ) . resolves . not . toThrow ( ) ;
0 commit comments