Skip to content

Commit ae91615

Browse files
committed
CCM-12613: add pdm.resource.submission.rejected component test
1 parent 4bb566a commit ae91615

File tree

1 file changed

+61
-4
lines changed

1 file changed

+61
-4
lines changed

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

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ const baseEvent = {
5656
test.describe('Digital Letters - Upload to PDM', () => {
5757
test.beforeAll(async () => {
5858
await purgeQueue(PDM_UPLOADER_DLQ_NAME);
59+
test.setTimeout(250_000);
5960
});
6061

61-
test('should send to PDM following downloaded message event', async () => {
62+
test('should send a pdm.resource.submitted event following a successful upload to PDM', async () => {
6263
const eventId = uuidv4();
6364
const letterId = uuidv4();
6465
const resourceKey = `test/${letterId}`;
@@ -106,12 +107,68 @@ test.describe('Digital Letters - Upload to PDM', () => {
106107
);
107108

108109
expect(eventLogEntry.length).toEqual(1);
109-
});
110+
}, 120);
111+
});
112+
113+
test('should send a pdm.resource.submission.rejected event following an error from PDM', async () => {
114+
// Note: I suspect this will fail once we are using the PDM Mock and will need amending.
115+
const eventId = uuidv4();
116+
const letterId = uuidv4();
117+
const resourceKey = `test/${letterId}`;
118+
const messageUri = `s3://${LETTERS_S3_BUCKET_NAME}/${resourceKey}`;
119+
const messageReference = uuidv4();
120+
const senderId = uuidv4();
121+
const invalidPdmRequest = {
122+
...pdmRequest,
123+
unexpectedField: 'I should not be here',
124+
}
125+
126+
uploadToS3(JSON.stringify(invalidPdmRequest), LETTERS_S3_BUCKET_NAME, resourceKey);
127+
128+
await eventPublisher.sendEvents(
129+
[
130+
{
131+
...baseEvent,
132+
id: eventId,
133+
data: {
134+
messageUri,
135+
messageReference,
136+
senderId,
137+
},
138+
},
139+
],
140+
messageDownloadedValidator,
141+
);
142+
143+
await expectToPassEventually(async () => {
144+
const filteredLogs = await getLogsFromCloudwatch(
145+
PDM_UPLOADER_LAMBDA_LOG_GROUP_NAME,
146+
[
147+
'$.message.description = "Failed sending PDM request"',
148+
`$.message.requestId = "${messageReference}"`,
149+
],
150+
);
151+
152+
expect(filteredLogs.length).toEqual(1);
153+
}, 120);
154+
155+
await expectToPassEventually(async () => {
156+
const eventLogEntry = await getLogsFromCloudwatch(
157+
EVENT_BUS_LOG_GROUP_NAME,
158+
[
159+
'$.message_type = "EVENT_RECEIPT"',
160+
'$.details.detail_type = "uk.nhs.notify.digital.letters.pdm.resource.submission.rejected.v1"',
161+
`$.details.event_detail = "*\\"messageReference\\":\\"${messageReference}\\"*"`,
162+
],
163+
);
164+
165+
expect(eventLogEntry.length).toEqual(1);
166+
}, 120);
110167
});
111168

112169
test('should send invalid event to dlq', async () => {
113170
// Sadly it takes longer than expected to go through the 3 retries before it's sent to the DLQ.
114-
test.setTimeout(500_000);
171+
test.setTimeout(550_000);
115172

116173
const eventId = uuidv4();
117174
const messageUri = `not-a-valid-s3-uri`;
@@ -144,7 +201,7 @@ test.describe('Digital Letters - Upload to PDM', () => {
144201
);
145202

146203
expect(eventLogEntry.length).toEqual(1);
147-
}, 60);
204+
}, 120);
148205

149206
await expectMessageContainingString(PDM_UPLOADER_DLQ_NAME, eventId, 420);
150207
});

0 commit comments

Comments
 (0)