Skip to content

Commit 9544c65

Browse files
committed
CCM-13146 add extra e2e test
1 parent f24670d commit 9544c65

File tree

3 files changed

+107
-2
lines changed

3 files changed

+107
-2
lines changed

tests/playwright/constants/backend-constants.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Environment Configuration
33
export const ENV = process.env.ENVIRONMENT || 'main';
44
export const REGION = process.env.AWS_REGION || 'eu-west-2';
5+
export const { AWS_ACCOUNT_ID } = process.env;
56

67
// Compound Scope Indicator
78
export const CSI = `nhs-${ENV}-dl`;
@@ -15,9 +16,12 @@ export const TTL_POLL_LAMBDA_NAME = `${CSI}-ttl-poll`;
1516
export const TTL_QUEUE_NAME = `${CSI}-ttl-queue`;
1617
export const TTL_DLQ_NAME = `${CSI}-ttl-dlq`;
1718

19+
// Queue Url Prefix
20+
export const SQS_URL_PREFIX = `https://sqs.${REGION}.amazonaws.com/${AWS_ACCOUNT_ID}/`;
21+
1822
// Event Bus
19-
export const EVENT_BUS_ARN = `arn:aws:events:${REGION}:${process.env.AWS_ACCOUNT_ID}:event-bus/${CSI}`;
20-
export const EVENT_BUS_DLQ_URL = `https://sqs.${REGION}.amazonaws.com/${process.env.AWS_ACCOUNT_ID}/${CSI}-event-publisher-errors-queue`;
23+
export const EVENT_BUS_ARN = `arn:aws:events:${REGION}:${AWS_ACCOUNT_ID}:event-bus/${CSI}`;
24+
export const EVENT_BUS_DLQ_URL = `${SQS_URL_PREFIX}${CSI}-event-publisher-errors-queue`;
2125

2226
// DynamoDB
2327
export const TTL_TABLE_NAME = `${CSI}-ttl`;

tests/playwright/digital-letters-component-tests/handle-ttl.component.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@ import { ENV } from 'constants/backend-constants';
33
import { getLogsFromCloudwatch } from 'helpers/cloudwatch-helpers';
44
import { deleteTtl, putTtl } from 'helpers/dynamodb-helpers';
55
import expectToPassEventually from 'helpers/expectations';
6+
import { expectMessageContainingString, purgeQueue } from 'helpers/sqs-helpers';
67
import { v4 as uuidv4 } from 'uuid';
78

89
test.describe('Digital Letters - Handle TTL', () => {
10+
const handleTtlDlqName = `nhs-${ENV}-dl-ttl-handle-expiry-errors-queue`;
11+
12+
test.beforeAll(async () => {
13+
await purgeQueue(handleTtlDlqName);
14+
});
15+
916
const baseEvent = {
1017
profileversion: '1.0.0',
1118
profilepublished: '2025-10',
@@ -114,4 +121,34 @@ test.describe('Digital Letters - Handle TTL', () => {
114121
});
115122
});
116123
});
124+
125+
test('should send invalid item to dlq', async () => {
126+
const letterId = uuidv4();
127+
const messageUri = `https://example.com/ttl/resource/${letterId}`;
128+
129+
const eventWithNoMessageUri = {
130+
...baseEvent,
131+
id: letterId,
132+
data: {
133+
...baseEvent.data,
134+
'digital-letter-id': letterId,
135+
},
136+
};
137+
138+
const ttlItem = {
139+
PK: messageUri,
140+
SK: 'TTL',
141+
dateOfExpiry: '2023-12-31#0',
142+
event: eventWithNoMessageUri,
143+
ttl: Date.now() / 1000 + 3600,
144+
};
145+
146+
const putResponseCode = await putTtl(ttlItem);
147+
expect(putResponseCode).toBe(200);
148+
149+
const deleteResponseCode = await deleteTtl(messageUri);
150+
expect(deleteResponseCode).toBe(200);
151+
152+
await expectMessageContainingString(handleTtlDlqName, letterId);
153+
});
117154
});
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import {
2+
DeleteMessageBatchCommand,
3+
ReceiveMessageCommand,
4+
ReceiveMessageCommandInput,
5+
} from '@aws-sdk/client-sqs';
6+
import { expect } from '@playwright/test';
7+
import { SQS_URL_PREFIX } from 'constants/backend-constants';
8+
import { sqsClient } from 'utils';
9+
import expectToPassEventually from 'helpers/expectations';
10+
11+
function getQueueUrl(queueName: string) {
12+
return `${SQS_URL_PREFIX}${queueName}`;
13+
}
14+
15+
export async function expectMessageContainingString(
16+
queueName: string,
17+
searchTerm: string,
18+
) {
19+
const input: ReceiveMessageCommandInput = {
20+
QueueUrl: getQueueUrl(queueName),
21+
MaxNumberOfMessages: 10,
22+
WaitTimeSeconds: 1,
23+
VisibilityTimeout: 2,
24+
};
25+
26+
await expectToPassEventually(async () => {
27+
const result = await sqsClient.send(new ReceiveMessageCommand(input));
28+
const polledMessages = result.Messages || [];
29+
30+
expect(
31+
polledMessages.find((m) => (m.Body ?? '').includes(searchTerm)),
32+
).toBeDefined();
33+
});
34+
}
35+
36+
export async function purgeQueue(queueName: string) {
37+
const queueUrl = getQueueUrl(queueName);
38+
39+
for (;;) {
40+
const result = await sqsClient.send(
41+
new ReceiveMessageCommand({
42+
QueueUrl: queueUrl,
43+
MaxNumberOfMessages: 10,
44+
WaitTimeSeconds: 1,
45+
}),
46+
);
47+
48+
const messages = result.Messages || [];
49+
50+
if (messages.length === 0) {
51+
break;
52+
}
53+
54+
await sqsClient.send(
55+
new DeleteMessageBatchCommand({
56+
QueueUrl: queueUrl,
57+
Entries: messages.map((msg, index) => ({
58+
Id: index.toString(),
59+
ReceiptHandle: msg.ReceiptHandle!,
60+
})),
61+
}),
62+
);
63+
}
64+
}

0 commit comments

Comments
 (0)