@@ -3,6 +3,7 @@ import { randomUUID } from 'node:crypto';
33import { createHandler } from 'apis/sqs-handler' ;
44import { EventPublisher , Logger } from 'utils' ;
55import { fileSafeEvent , fivePagePdf , recordEvent } from '__tests__/test-data' ;
6+ import { FileSafe } from 'digital-letters-events' ;
67
78const logger = mock < Logger > ( ) ;
89const 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 (
0 commit comments