Skip to content

Commit 903e833

Browse files
CCM-12858: adding negative test in component testing
1 parent 92e043e commit 903e833

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

tests/playwright/digital-letters-component-tests/core-notify.component.spec.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ test.describe('Digital Letters - Core Notify', () => {
104104
CORE_NOTIFIER_LAMBDA_LOG_GROUP_NAME,
105105
[
106106
'$.message.description = "Successfully processed request and sent to Notify"',
107+
`$.message.messageReference = "${messageReference}"`,
107108
],
108109
);
109110

@@ -127,6 +128,57 @@ test.describe('Digital Letters - Core Notify', () => {
127128
}, 240);
128129
});
129130

131+
test('given PDMResourceAvailable event with INVALID NHS Number, when client has routingConfigId then a message is sent to core Notify', async () => {
132+
const eventId = uuidv4();
133+
const messageReference = uuidv4();
134+
135+
await eventPublisher.sendEvents<PDMResourceAvailable>(
136+
[
137+
{
138+
...baseEvent,
139+
id: eventId,
140+
data: {
141+
messageReference,
142+
senderId: senderIdInvokingNotify,
143+
resourceId: 'resource-123',
144+
nhsNumber: 'invalidNHSNumber',
145+
odsCode: 'A12345',
146+
},
147+
},
148+
],
149+
messagePDMResourceAvailableValidator,
150+
);
151+
152+
// Verify the event is processed and a message appears in the Lambda logs
153+
await expectToPassEventually(async () => {
154+
const filteredLogs = await getLogsFromCloudwatch(
155+
CORE_NOTIFIER_LAMBDA_LOG_GROUP_NAME,
156+
[
157+
'$.message.description = "Failed sending request to Notify API"',
158+
`$.message.messageReference = "${messageReference}"`,
159+
],
160+
);
161+
162+
expect(filteredLogs.length).toEqual(1);
163+
}, 240);
164+
165+
// Verify the event is published in the event bus
166+
await expectToPassEventually(async () => {
167+
const eventLogEntry = await getLogsFromCloudwatch(
168+
EVENT_BUS_LOG_GROUP_NAME,
169+
[
170+
'$.message_type = "EVENT_RECEIPT"',
171+
'$.details.detail_type = "uk.nhs.notify.digital.letters.messages.request.rejected.v1"',
172+
`$.details.event_detail = "*\\"failureCode\\":\\"CM_INVALID_NHS_NUMBER\\"*"`,
173+
`$.details.event_detail = "*\\"messageUri\\":\\"https://www.nhsapp.service.nhs.uk/digital-letters?letterid=resource-123\\"*"`,
174+
`$.details.event_detail = "*\\"messageReference\\":\\"${messageReference}\\"*"`,
175+
],
176+
);
177+
178+
expect(eventLogEntry.length).toEqual(1);
179+
}, 240);
180+
});
181+
130182
test('given PDMResourceAvailable event, when client does NOT have routingConfigId then a message is NOT sent to core Notify', async () => {
131183
const eventId = uuidv4();
132184
const messageReference = uuidv4();

0 commit comments

Comments
 (0)