Skip to content

Commit

Permalink
feat(cb2-14233): addition unit test to cover catch block
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-Searle committed Oct 29, 2024
1 parent 39866f0 commit cd9ef8a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/unit/eventHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,30 @@ describe('eventHandler', () => {
expect(sendEvents).toHaveBeenCalledTimes(eventsProcessed);
},
);
it('GIVEN an event that throws an error THEN it should be caught and added to batch failures', async () => {
const errorMessageId = 'errorMessageId';
event = {
Records: [
{
messageId: errorMessageId,
receiptHandle: 'test',
attributes: {} as SQSRecordAttributes,
messageAttributes: {} as SQSMessageAttributes,
body: 'Invalid JSON Test',
awsRegion: '',
eventSource: '',
eventSourceARN: '',
md5OfBody: '',
},
],
};

const consoleSpy = jest.spyOn(console, 'error').mockImplementation();
const result = await eventHandler(event);

expect(result.batchItemFailures).toHaveLength(1);
expect(result.batchItemFailures[0].itemIdentifier).toBe(errorMessageId);
expect(consoleSpy).toHaveBeenCalled();
consoleSpy.mockRestore();
});
});

0 comments on commit cd9ef8a

Please sign in to comment.