Skip to content

Commit e4f15b8

Browse files
committed
CCM-12613: add test to check that invalid events are sent to the DLQ
1 parent 00cad81 commit e4f15b8

File tree

3 files changed

+71
-19
lines changed

3 files changed

+71
-19
lines changed

tests/playwright/constants/backend-constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const TTL_POLL_LAMBDA_NAME = `${CSI}-ttl-poll`;
1515
// Queue Names
1616
export const TTL_QUEUE_NAME = `${CSI}-ttl-queue`;
1717
export const TTL_DLQ_NAME = `${CSI}-ttl-dlq`;
18+
export const PDM_UPLOADER_DLQ_NAME = `${CSI}-pdm-uploader-dlq`;
1819

1920
// Queue Url Prefix
2021
export const SQS_URL_PREFIX = `https://sqs.${REGION}.amazonaws.com/${AWS_ACCOUNT_ID}/`;

tests/playwright/digital-letters-component-tests/pdm-uploader.component.spec.ts

Lines changed: 68 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import { expect, test } from '@playwright/test';
22
import {
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';
78
import messageDownloadedValidator from 'digital-letters-events/MESHInboxMessageDownloaded.js';
89
import { getLogsFromCloudwatch } from 'helpers/cloudwatch-helpers';
910
import eventPublisher from 'helpers/event-bus-helpers';
1011
import expectToPassEventually from 'helpers/expectations';
1112
import { uploadToS3 } from 'helpers/s3-helpers';
13+
import { expectMessageContainingString, purgeQueue } from 'helpers/sqs-helpers';
1214
import { v4 as uuidv4 } from 'uuid';
1315

1416
const 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+
3457
test.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
});

tests/playwright/helpers/sqs-helpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function getQueueUrl(queueName: string) {
1515
export async function expectMessageContainingString(
1616
queueName: string,
1717
searchTerm: string,
18+
timeout: number = 30,
1819
) {
1920
const input: ReceiveMessageCommandInput = {
2021
QueueUrl: getQueueUrl(queueName),
@@ -28,7 +29,7 @@ export async function expectMessageContainingString(
2829
const polledMessages = result.Messages || [];
2930

3031
expect(polledMessages.some((m) => m.Body?.includes(searchTerm))).toBe(true);
31-
});
32+
}, timeout);
3233
}
3334

3435
export async function purgeQueue(queueName: string) {

0 commit comments

Comments
 (0)