Skip to content

Commit d240a41

Browse files
committed
CCM-13768: attempt to get messageReference for invalid events
1 parent d97cbad commit d240a41

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

lambdas/print-analyser/src/__tests__/apis/sqs-handler.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { randomUUID } from 'node:crypto';
33
import { createHandler } from 'apis/sqs-handler';
44
import { EventPublisher, Logger } from 'utils';
55
import { fileSafeEvent, fivePagePdf, recordEvent } from '__tests__/test-data';
6+
import { FileSafe } from 'digital-letters-events';
67

78
const logger = mock<Logger>();
89
const eventPublisher = mock<EventPublisher>();
@@ -102,7 +103,7 @@ describe('SQS Handler', () => {
102103
});
103104
});
104105

105-
it('should return failed items to the queue if an invalid file.safe event is received', async () => {
106+
it('should return failed items to the queue if a mildly invalid file.safe event is received', async () => {
106107
const invalidFileSafeEvent = {
107108
...fileSafeEvent,
108109
source: 'invalid file.safe source',
@@ -118,6 +119,32 @@ describe('SQS Handler', () => {
118119
}),
119120
]),
120121
description: 'Error parsing print analyser queue entry',
122+
messageReference: invalidFileSafeEvent.data.messageReference,
123+
});
124+
125+
expect(logger.info).toHaveBeenCalledWith(
126+
'0 of 1 records processed successfully',
127+
);
128+
129+
expect(result).toEqual({
130+
batchItemFailures: [{ itemIdentifier: '1' }],
131+
});
132+
});
133+
134+
it('should return failed items to the queue if a very invalid file.safe event is received', async () => {
135+
const invalidFileSafeEvent = {} as FileSafe;
136+
const event = recordEvent([invalidFileSafeEvent]);
137+
138+
const result = await handler(event);
139+
140+
expect(logger.warn).toHaveBeenCalledWith({
141+
err: expect.arrayContaining([
142+
expect.objectContaining({
143+
message: `must have required property 'specversion'`,
144+
}),
145+
]),
146+
description: 'Error parsing print analyser queue entry',
147+
messageReference: 'not present',
121148
});
122149

123150
expect(logger.info).toHaveBeenCalledWith(

lambdas/print-analyser/src/apis/sqs-handler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function validateRecord(
3838
logger.warn({
3939
err: fileSafeValidator.errors,
4040
description: 'Error parsing print analyser queue entry',
41+
messageReference: sqsEventDetail?.data?.messageReference || 'not present',
4142
});
4243

4344
return null;

0 commit comments

Comments
 (0)