@@ -2,13 +2,15 @@ import { expect, test } from '@playwright/test';
22import {
33 EVENT_BUS_LOG_GROUP_NAME ,
44 LETTERS_S3_BUCKET_NAME ,
5+ PDM_UPLOADER_DLQ_NAME ,
56 PDM_UPLOADER_LAMBDA_LOG_GROUP_NAME ,
67} from 'constants/backend-constants' ;
78import messageDownloadedValidator from 'digital-letters-events/MESHInboxMessageDownloaded.js' ;
89import { getLogsFromCloudwatch } from 'helpers/cloudwatch-helpers' ;
910import eventPublisher from 'helpers/event-bus-helpers' ;
1011import expectToPassEventually from 'helpers/expectations' ;
1112import { uploadToS3 } from 'helpers/s3-helpers' ;
13+ import { expectMessageContainingString , purgeQueue } from 'helpers/sqs-helpers' ;
1214import { v4 as uuidv4 } from 'uuid' ;
1315
1416const pdmRequest = {
@@ -31,7 +33,32 @@ const pdmRequest = {
3133 ] ,
3234} ;
3335
36+ const baseEvent = {
37+ profileversion : '1.0.0' ,
38+ profilepublished : '2025-10' ,
39+ specversion : '1.0' ,
40+ source :
41+ '/nhs/england/notify/production/primary/data-plane/digitalletters/mesh' ,
42+ subject :
43+ 'customer/920fca11-596a-4eca-9c47-99f624614658/recipient/769acdd4-6a47-496f-999f-76a6fd2c3959' ,
44+ type : 'uk.nhs.notify.digital.letters.mesh.inbox.message.downloaded.v1' ,
45+ time : '2023-06-20T12:00:00Z' ,
46+ recordedtime : '2023-06-20T12:00:00.250Z' ,
47+ severitynumber : 2 ,
48+ traceparent :
49+ '00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01' ,
50+ datacontenttype : 'application/json' ,
51+ dataschema :
52+ 'https://notify.nhs.uk/cloudevents/schemas/digital-letters/2025-10-draft/data/digital-letters-mesh-inbox-message-downloaded-data.schema.json' ,
53+ dataschemaversion : '1.0' ,
54+ severitytext : 'INFO' ,
55+ }
56+
3457test . describe ( 'Digital Letters - Upload to PDM' , ( ) => {
58+ test . beforeAll ( async ( ) => {
59+ await purgeQueue ( PDM_UPLOADER_DLQ_NAME ) ;
60+ } ) ;
61+
3562 test ( 'should send to PDM following downloaded message event' , async ( ) => {
3663 const eventId = uuidv4 ( ) ;
3764 const letterId = uuidv4 ( ) ;
@@ -45,25 +72,8 @@ test.describe('Digital Letters - Upload to PDM', () => {
4572 await eventPublisher . sendEvents (
4673 [
4774 {
48- profileversion : '1.0.0' ,
49- profilepublished : '2025-10' ,
75+ ...baseEvent ,
5076 id : eventId ,
51- specversion : '1.0' ,
52- source :
53- '/nhs/england/notify/production/primary/data-plane/digitalletters/mesh' ,
54- subject :
55- 'customer/920fca11-596a-4eca-9c47-99f624614658/recipient/769acdd4-6a47-496f-999f-76a6fd2c3959' ,
56- type : 'uk.nhs.notify.digital.letters.mesh.inbox.message.downloaded.v1' ,
57- time : '2023-06-20T12:00:00Z' ,
58- recordedtime : '2023-06-20T12:00:00.250Z' ,
59- severitynumber : 2 ,
60- traceparent :
61- '00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01' ,
62- datacontenttype : 'application/json' ,
63- dataschema :
64- 'https://notify.nhs.uk/cloudevents/schemas/digital-letters/2025-10-draft/data/digital-letters-mesh-inbox-message-downloaded-data.schema.json' ,
65- dataschemaversion : '1.0' ,
66- severitytext : 'INFO' ,
6777 data : {
6878 messageUri,
6979 messageReference,
@@ -99,4 +109,44 @@ test.describe('Digital Letters - Upload to PDM', () => {
99109 expect ( eventLogEntry . length ) . toEqual ( 1 ) ;
100110 } ) ;
101111 } ) ;
112+
113+ test ( 'should send invalid event to dlq' , async ( ) => {
114+ // Sadly it takes longer than expected to go through the 3 retries before it's sent to the DLQ.
115+ test . setTimeout ( 360_000 ) ;
116+
117+ const eventId = uuidv4 ( ) ;
118+ const messageUri = `not-a-valid-s3-uri` ;
119+ const messageReference = uuidv4 ( ) ;
120+ const senderId = uuidv4 ( ) ;
121+
122+ await eventPublisher . sendEvents (
123+ [
124+ {
125+ ...baseEvent ,
126+ id : eventId ,
127+ data : {
128+ messageUri,
129+ messageReference,
130+ senderId,
131+ } ,
132+ } ,
133+ ] ,
134+ messageDownloadedValidator ,
135+ ) ;
136+
137+ await expectToPassEventually ( async ( ) => {
138+ const eventLogEntry = await getLogsFromCloudwatch (
139+ EVENT_BUS_LOG_GROUP_NAME ,
140+ [
141+ '$.message_type = "EVENT_RECEIPT"' ,
142+ '$.details.detail_type = "uk.nhs.notify.digital.letters.pdm.resource.submission.rejected.v1"' ,
143+ `$.details.event_detail = "*\\"messageReference\\":\\"${ messageReference } \\"*"` ,
144+ ] ,
145+ ) ;
146+
147+ expect ( eventLogEntry . length ) . toEqual ( 1 ) ;
148+ } ) ;
149+
150+ await expectMessageContainingString ( PDM_UPLOADER_DLQ_NAME , eventId , 300 ) ;
151+ } ) ;
102152} ) ;
0 commit comments