Skip to content

Commit 709cab7

Browse files
committed
CCM-12616: Adjust component test
1 parent bf613ce commit 709cab7

5 files changed

Lines changed: 40 additions & 50 deletions

File tree

lambdas/mesh-download/mesh_download/__tests__/test_processor.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from unittest.mock import Mock, patch
99
from datetime import datetime, timezone
1010
from pydantic import ValidationError
11+
from mesh_download.errors import MeshMessageNotFound
1112

1213

1314
def setup_mocks():
@@ -238,9 +239,11 @@ def test_download_and_store_message_not_found(self):
238239

239240
config.mesh_client.retrieve_message.return_value = None
240241
sqs_record = create_sqs_record()
241-
processor.process_sqs_message(sqs_record)
242-
config.mesh_client.retrieve_message.assert_called_once_with('test_message_123')
243242

243+
with pytest.raises(MeshMessageNotFound, match="MESH message with ID test_message_123 not found"):
244+
processor.process_sqs_message(sqs_record)
245+
246+
config.mesh_client.retrieve_message.assert_called_once_with('test_message_123')
244247
document_store.store_document.assert_not_called()
245248
event_publisher.send_events.assert_not_called()
246249
config.download_metric.record.assert_not_called()

lambdas/mesh-download/mesh_download/errors.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ def format_exception(exception):
1111
"""
1212
return ''.join(traceback.format_exception(
1313
type(exception), exception, exception.__traceback__))
14+
15+
class MeshMessageNotFound(Exception):
16+
"""
17+
Indicates an invalid MESH message could not be retrieved
18+
"""

lambdas/mesh-download/mesh_download/processor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from pydantic import ValidationError
66
from event_publisher.models import MeshInboxMessageEvent, MeshDownloadMessageEvent
7+
from mesh_download.errors import MeshMessageNotFound
78

89

910
class MeshDownloadProcessor:
@@ -57,7 +58,7 @@ def _handle_download(self, event, logger):
5758
message = self.__mesh_client.retrieve_message(data.meshMessageId)
5859
if not message:
5960
logger.error("Message not found in MESH inbox")
60-
return
61+
raise MeshMessageNotFound(f"MESH message with ID {data.meshMessageId} not found")
6162

6263
logger.info(
6364
"Retrieved MESH message",

tests/playwright/constants/backend-constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export const TTL_POLL_LAMBDA_NAME = `${CSI}-ttl-poll`;
1616
export const TTL_QUEUE_NAME = `${CSI}-ttl-queue`;
1717
export const TTL_DLQ_NAME = `${CSI}-ttl-dlq`;
1818
export const PDM_UPLOADER_DLQ_NAME = `${CSI}-pdm-uploader-dlq`;
19-
export const MESH_POLL_DLQ_NAME = `${CSI}-mesh-poll-dlq`;
2019
export const MESH_DOWNLOAD_DLQ_NAME = `${CSI}-mesh-download-dlq`;
2120
export const PDM_POLL_DLQ_NAME = `${CSI}-pdm-poll-dlq`;
2221

tests/playwright/digital-letters-component-tests/mesh-poll-download.component.spec.ts

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { expect, test } from '@playwright/test';
22
import {
33
ENV,
44
MESH_DOWNLOAD_DLQ_NAME,
5-
MESH_POLL_DLQ_NAME,
65
MESH_POLL_LAMBDA_NAME,
76
NON_PII_S3_BUCKET_NAME,
7+
PII_S3_BUCKET_NAME,
88
} from 'constants/backend-constants';
99
import { getLogsFromCloudwatch } from 'helpers/cloudwatch-helpers';
10+
import eventPublisher from 'helpers/event-bus-helpers';
1011
import expectToPassEventually from 'helpers/expectations';
1112
import { invokeLambda } from 'helpers/lambda-helpers';
1213
import { downloadFromS3, uploadToS3 } from 'helpers/s3-helpers';
@@ -72,7 +73,6 @@ test.describe('Digital Letters - MESH Poll and Download', () => {
7273
}
7374

7475
async function expectMeshInboxMessageDownloadedEvent(
75-
meshMessageId: string,
7676
messageReference: string,
7777
): Promise<void> {
7878
await expectToPassEventually(async () => {
@@ -81,7 +81,6 @@ test.describe('Digital Letters - MESH Poll and Download', () => {
8181
[
8282
'$.message_type = "EVENT_RECEIPT"',
8383
'$.details.detail_type = "uk.nhs.notify.digital.letters.mesh.inbox.message.downloaded.v1"',
84-
`$.details.event_detail = "*\\"meshMessageId\\":\\"${meshMessageId}\\"*"`,
8584
`$.details.event_detail = "*\\"messageReference\\":\\"${messageReference}\\"*"`,
8685
`$.details.event_detail = "*\\"senderId\\":\\"${senderId}\\"*"`,
8786
],
@@ -107,14 +106,13 @@ test.describe('Digital Letters - MESH Poll and Download', () => {
107106

108107
await expectMeshInboxMessageReceivedEvent(meshMessageId);
109108
await expectMeshInboxMessageDownloadedEvent(
110-
meshMessageId,
111109
messageReference,
112110
);
113111

114112
await expectToPassEventually(async () => {
115113
const storedMessage = await downloadFromS3(
116-
NON_PII_S3_BUCKET_NAME,
117-
`mesh-downloads/${senderId}/${messageReference}`,
114+
PII_S3_BUCKET_NAME,
115+
`document-reference/${senderId}_${messageReference}`,
118116
);
119117

120118
expect(storedMessage.body).toContain(messageContent);
@@ -130,55 +128,39 @@ test.describe('Digital Letters - MESH Poll and Download', () => {
130128
}, 60_000);
131129
});
132130

133-
test('should handle invalid sender and send to DLQ', async () => {
134-
test.setTimeout(300_000);
135-
136-
const meshMessageId = `${Date.now()}_INVALID_${uuidv4().slice(0, 8)}`;
137-
const messageReference = uuidv4();
138-
const messageContent = JSON.stringify({
139-
senderId: 'unknown-sender',
140-
messageReference,
141-
testData: 'This should fail validation',
142-
});
143-
144-
await uploadMeshMessageWithSender(
145-
meshMessageId,
146-
messageReference,
147-
messageContent,
148-
'unknown-mesh-sender',
149-
);
150-
151-
await invokeLambda(MESH_POLL_LAMBDA_NAME);
152-
153-
await expectMessageContainingString(MESH_POLL_DLQ_NAME, meshMessageId, 240);
154-
});
155-
156131
test('should send message to mesh-download DLQ when download fails', async () => {
157132
test.setTimeout(400_000);
158133

159-
const meshMessageId = `${Date.now()}_DLQ_${uuidv4().slice(0, 8)}`;
134+
const invalidMeshMessageId = `${Date.now()}_DLQ_${uuidv4().slice(0, 8)}`;
160135
const messageReference = uuidv4();
161-
const invalidMessageUri =
162-
'https://example.com/invalid/nonexistent-resource';
163136

164-
await uploadMeshMessage(
165-
meshMessageId,
166-
messageReference,
167-
JSON.stringify({
168-
senderId,
169-
messageReference,
170-
messageUri: invalidMessageUri,
171-
testData: 'This message has an invalid URI',
172-
}),
137+
await eventPublisher.sendEvents(
138+
[
139+
{
140+
id: uuidv4(),
141+
specversion: '1.0',
142+
source: '/nhs/england/notify/development/primary/data-plane/digitalletters/mesh',
143+
subject: 'customer/00000000-0000-0000-0000-000000000000/recipient/00000000-0000-0000-0000-000000000000',
144+
type: 'uk.nhs.notify.digital.letters.mesh.inbox.message.received.v1',
145+
time: '2026-01-20T15:48:21.636284+00:00',
146+
recordedtime: '2026-01-20T15:48:21.636284+00:00',
147+
severitynumber: 2,
148+
severitytext: 'INFO',
149+
traceparent: '00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01',
150+
dataschema: 'https://notify.nhs.uk/cloudevents/schemas/digital-letters/2025-10-draft/data/digital-letters-mesh-inbox-message-received-data.schema.json',
151+
data: {
152+
meshMessageId: invalidMeshMessageId,
153+
senderId,
154+
messageReference,
155+
},
156+
}
157+
],
158+
() => true,
173159
);
174160

175-
await invokeLambda(MESH_POLL_LAMBDA_NAME);
176-
177-
await expectMeshInboxMessageReceivedEvent(meshMessageId);
178-
179161
await expectMessageContainingString(
180162
MESH_DOWNLOAD_DLQ_NAME,
181-
meshMessageId,
163+
invalidMeshMessageId,
182164
300,
183165
);
184166
});

0 commit comments

Comments
 (0)