@@ -20,138 +20,183 @@ const baseEvent = {
2020 '/nhs/england/notify/production/primary/data-plane/digitalletters/pdm' ,
2121 subject :
2222 'customer/920fca11-596a-4eca-9c47-99f624614658/recipient/769acdd4-6a47-496f-999f-76a6fd2c3959' ,
23- type : 'uk.nhs.notify.digital.letters.pdm.resource.submitted.v1' ,
2423 time : '2023-06-20T12:00:00Z' ,
2524 recordedtime : '2023-06-20T12:00:00.250Z' ,
2625 severitynumber : 2 ,
2726 traceparent : '00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01' ,
2827 datacontenttype : 'application/json' ,
29- dataschema :
30- 'https://notify.nhs.uk/cloudevents/schemas/digital-letters/2025-10-draft/data/digital-letters-pdm-resource-submitted-data.schema.json' ,
3128 dataschemaversion : '1.0' ,
3229 severitytext : 'INFO' ,
3330} ;
3431
32+ const submittedEvent = {
33+ ...baseEvent ,
34+ type : 'uk.nhs.notify.digital.letters.pdm.resource.submitted.v1' ,
35+ dataschema :
36+ 'https://notify.nhs.uk/cloudevents/schemas/digital-letters/2025-10-draft/data/digital-letters-pdm-resource-submitted-data.schema.json' ,
37+ } ;
38+
39+ const unavailableEvent = {
40+ ...baseEvent ,
41+ type : 'uk.nhs.notify.digital.letters.pdm.resource.unavailable.v1' ,
42+ dataschema :
43+ 'https://notify.nhs.uk/cloudevents/schemas/digital-letters/2025-10-draft/data/digital-letters-pdm-resource-unavailable-data.schema.json' ,
44+ } ;
45+
3546test . describe ( 'PDM Poll' , ( ) => {
3647 test . beforeAll ( async ( ) => {
3748 test . setTimeout ( 250_000 ) ;
3849 } ) ;
3950
40- test ( 'should send a pdm.resource.available event when available in PDM' , async ( ) => {
41- const eventId = uuidv4 ( ) ;
42- const documentResourceId = '9ae75410-c067-35ae-9410-153fa849a4dd' ;
43- const messageReference = uuidv4 ( ) ;
44- const senderId = uuidv4 ( ) ;
45-
46- await eventPublisher . sendEvents (
47- [
48- {
49- ...baseEvent ,
50- id : eventId ,
51- data : {
52- resourceId : documentResourceId ,
53- messageReference,
54- senderId,
55- } ,
56- } ,
57- ] ,
58- pdmResourceSubmittedValidator ,
59- ) ;
51+ test . describe ( 'pdm.resource.submitted' , ( ) => {
52+ test ( 'should send a pdm.resource.available event when available in PDM' , async ( ) => {
53+ const eventId = uuidv4 ( ) ;
54+ const documentResourceId = '9ae75410-c067-35ae-9410-153fa849a4dd' ;
55+ const messageReference = uuidv4 ( ) ;
56+ const senderId = uuidv4 ( ) ;
6057
61- await expectToPassEventually ( async ( ) => {
62- const eventLogEntry = await getLogsFromCloudwatch (
63- EVENT_BUS_LOG_GROUP_NAME ,
58+ await eventPublisher . sendEvents (
6459 [
65- '$.message_type = "EVENT_RECEIPT"' ,
66- '$.details.detail_type = "uk.nhs.notify.digital.letters.pdm.resource.available.v1"' ,
67- `$.details.event_detail = "*\\"messageReference\\":\\"${ messageReference } \\"*"` ,
68- `$.details.event_detail = "*\\"odsCode\\":\\"Y05868\\"*"` ,
69- `$.details.event_detail = "*\\"nhsNumber\\":\\"9912003071\\"*"` ,
60+ {
61+ ...submittedEvent ,
62+ id : eventId ,
63+ data : {
64+ resourceId : documentResourceId ,
65+ messageReference,
66+ senderId,
67+ } ,
68+ } ,
7069 ] ,
70+ pdmResourceSubmittedValidator ,
7171 ) ;
7272
73- expect ( eventLogEntry . length ) . toEqual ( 1 ) ;
74- } , 120 ) ;
75- } ) ;
76-
77- test ( 'should send a pdm.resource.unavailable event when not available in PDM' , async ( ) => {
78- const eventId = uuidv4 ( ) ;
79- const documentResourceId = 'unavailable-response' ;
80- const messageReference = uuidv4 ( ) ;
81- const senderId = uuidv4 ( ) ;
82-
83- await eventPublisher . sendEvents (
84- [
85- {
86- ...baseEvent ,
87- id : eventId ,
88- dataschema :
89- 'https://notify.nhs.uk/cloudevents/schemas/digital-letters/2025-10-draft/data/digital-letters-pdm-resource-unavailable-data.schema.json' ,
90- type : 'uk.nhs.notify.digital.letters.pdm.resource.unavailable.v1' ,
91- data : {
92- resourceId : documentResourceId ,
93- messageReference,
94- senderId,
95- retryCount : 0 ,
96- } ,
97- } ,
98- ] ,
99- pdmResourceUnavailableValidator ,
100- ) ;
101-
102- await expectToPassEventually ( async ( ) => {
103- const eventLogEntry = await getLogsFromCloudwatch (
104- EVENT_BUS_LOG_GROUP_NAME ,
73+ await expectToPassEventually ( async ( ) => {
74+ const eventLogEntry = await getLogsFromCloudwatch (
75+ EVENT_BUS_LOG_GROUP_NAME ,
76+ [
77+ '$.message_type = "EVENT_RECEIPT"' ,
78+ '$.details.detail_type = "uk.nhs.notify.digital.letters.pdm.resource.available.v1"' ,
79+ `$.details.event_detail = "*\\"messageReference\\":\\"${ messageReference } \\"*"` ,
80+ `$.details.event_detail = "*\\"odsCode\\":\\"Y05868\\"*"` ,
81+ `$.details.event_detail = "*\\"nhsNumber\\":\\"9912003071\\"*"` ,
82+ ] ,
83+ ) ;
84+
85+ expect ( eventLogEntry . length ) . toEqual ( 1 ) ;
86+ } , 120 ) ;
87+ } ) ;
88+
89+ test ( 'should send a pdm.resource.unavailable event when unavailable in PDM' , async ( ) => {
90+ const eventId = uuidv4 ( ) ;
91+ const documentResourceId = 'unavailable-response' ;
92+ const messageReference = uuidv4 ( ) ;
93+ const senderId = uuidv4 ( ) ;
94+
95+ await eventPublisher . sendEvents (
10596 [
106- '$.message_type = "EVENT_RECEIPT"' ,
107- '$.details.detail_type = "uk.nhs.notify.digital.letters.pdm.resource.unavailable.v1"' ,
108- `$.details.event_detail = "*\\"messageReference\\":\\"${ messageReference } \\"*"` ,
109- `$.details.event_detail = "*\\"retryCount\\":1*"` ,
97+ {
98+ ...submittedEvent ,
99+ id : eventId ,
100+ data : {
101+ resourceId : documentResourceId ,
102+ messageReference,
103+ senderId,
104+ } ,
105+ } ,
110106 ] ,
107+ pdmResourceSubmittedValidator ,
111108 ) ;
112109
113- expect ( eventLogEntry . length ) . toEqual ( 1 ) ;
114- } , 120 ) ;
110+ await expectToPassEventually ( async ( ) => {
111+ const eventLogEntry = await getLogsFromCloudwatch (
112+ EVENT_BUS_LOG_GROUP_NAME ,
113+ [
114+ '$.message_type = "EVENT_RECEIPT"' ,
115+ '$.details.detail_type = "uk.nhs.notify.digital.letters.pdm.resource.unavailable.v1"' ,
116+ `$.details.event_detail = "*\\"messageReference\\":\\"${ messageReference } \\"*"` ,
117+ `$.details.event_detail = "*\\"retryCount\\":0*"` ,
118+ ] ,
119+ ) ;
120+
121+ expect ( eventLogEntry . length ) . toEqual ( 1 ) ;
122+ } , 120 ) ;
123+ } ) ;
115124 } ) ;
116125
117- test ( 'should send a pdm.resource.retries.exceeded event when not available in PDM after 10 retries' , async ( ) => {
118- const eventId = uuidv4 ( ) ;
119- const documentResourceId = 'unavailable-response' ;
120- const messageReference = uuidv4 ( ) ;
121- const senderId = uuidv4 ( ) ;
126+ test . describe ( 'pdm.resource.unavailable' , ( ) => {
127+ test ( 'should send a pdm.resource.unavailable event when still unavailable in PDM' , async ( ) => {
128+ const eventId = uuidv4 ( ) ;
129+ const documentResourceId = 'unavailable-response' ;
130+ const messageReference = uuidv4 ( ) ;
131+ const senderId = uuidv4 ( ) ;
122132
123- await eventPublisher . sendEvents (
124- [
125- {
126- ...baseEvent ,
127- id : eventId ,
128- dataschema :
129- 'https://notify.nhs.uk/cloudevents/schemas/digital-letters/2025-10-draft/data/digital-letters-pdm-resource-unavailable-data.schema.json' ,
130- type : 'uk.nhs.notify.digital.letters.pdm.resource.unavailable.v1' ,
131- data : {
132- resourceId : documentResourceId ,
133- messageReference,
134- senderId,
135- retryCount : 9 ,
133+ await eventPublisher . sendEvents (
134+ [
135+ {
136+ ...unavailableEvent ,
137+ id : eventId ,
138+ data : {
139+ resourceId : documentResourceId ,
140+ messageReference,
141+ senderId,
142+ retryCount : 0 ,
143+ } ,
136144 } ,
137- } ,
138- ] ,
139- pdmResourceUnavailableValidator ,
140- ) ;
145+ ] ,
146+ pdmResourceUnavailableValidator ,
147+ ) ;
141148
142- await expectToPassEventually ( async ( ) => {
143- const eventLogEntry = await getLogsFromCloudwatch (
144- EVENT_BUS_LOG_GROUP_NAME ,
149+ await expectToPassEventually ( async ( ) => {
150+ const eventLogEntry = await getLogsFromCloudwatch (
151+ EVENT_BUS_LOG_GROUP_NAME ,
152+ [
153+ '$.message_type = "EVENT_RECEIPT"' ,
154+ '$.details.detail_type = "uk.nhs.notify.digital.letters.pdm.resource.unavailable.v1"' ,
155+ `$.details.event_detail = "*\\"messageReference\\":\\"${ messageReference } \\"*"` ,
156+ `$.details.event_detail = "*\\"retryCount\\":1*"` ,
157+ ] ,
158+ ) ;
159+
160+ expect ( eventLogEntry . length ) . toEqual ( 1 ) ;
161+ } , 120 ) ;
162+ } ) ;
163+
164+ test ( 'should send a pdm.resource.retries.exceeded event when unavailable in PDM after 10 retries' , async ( ) => {
165+ const eventId = uuidv4 ( ) ;
166+ const documentResourceId = 'unavailable-response' ;
167+ const messageReference = uuidv4 ( ) ;
168+ const senderId = uuidv4 ( ) ;
169+
170+ await eventPublisher . sendEvents (
145171 [
146- '$.message_type = "EVENT_RECEIPT"' ,
147- '$.details.detail_type = "uk.nhs.notify.digital.letters.pdm.resource.retries.exceeded.v1"' ,
148- `$.details.event_detail = "*\\"messageReference\\":\\"${ messageReference } \\"*"` ,
149- `$.details.event_detail = "*\\"retryCount\\":10*"` ,
172+ {
173+ ...unavailableEvent ,
174+ id : eventId ,
175+ data : {
176+ resourceId : documentResourceId ,
177+ messageReference,
178+ senderId,
179+ retryCount : 9 ,
180+ } ,
181+ } ,
150182 ] ,
183+ pdmResourceUnavailableValidator ,
151184 ) ;
152185
153- expect ( eventLogEntry . length ) . toEqual ( 1 ) ;
154- } , 120 ) ;
186+ await expectToPassEventually ( async ( ) => {
187+ const eventLogEntry = await getLogsFromCloudwatch (
188+ EVENT_BUS_LOG_GROUP_NAME ,
189+ [
190+ '$.message_type = "EVENT_RECEIPT"' ,
191+ '$.details.detail_type = "uk.nhs.notify.digital.letters.pdm.resource.retries.exceeded.v1"' ,
192+ `$.details.event_detail = "*\\"messageReference\\":\\"${ messageReference } \\"*"` ,
193+ `$.details.event_detail = "*\\"retryCount\\":10*"` ,
194+ ] ,
195+ ) ;
196+
197+ expect ( eventLogEntry . length ) . toEqual ( 1 ) ;
198+ } , 120 ) ;
199+ } ) ;
155200 } ) ;
156201
157202 test ( 'should send invalid event to poll dlq' , async ( ) => {
0 commit comments