@@ -43,14 +43,14 @@ describe('createHandler', () => {
4343 } ;
4444
4545 beforeEach ( ( ) => {
46- ttlActions = { delete : jest . fn ( ) } ;
46+ ttlActions = { markWithdrawn : jest . fn ( ) } ;
4747 eventPublisher = { sendEvents : jest . fn ( ) . mockResolvedValue ( [ ] ) } ;
4848 logger = { error : jest . fn ( ) , info : jest . fn ( ) , warn : jest . fn ( ) } ;
4949 handler = createHandler ( { ttlActions, eventPublisher, logger } ) ;
5050 } ) ;
5151
5252 it ( 'processes a valid SQS event and returns success' , async ( ) => {
53- ttlActions . delete . mockResolvedValue ( {
53+ ttlActions . markWithdrawn . mockResolvedValue ( {
5454 result : 'success' ,
5555 ttlItem : { event : messageDownloadedEvent } ,
5656 } ) ;
@@ -61,7 +61,7 @@ describe('createHandler', () => {
6161 const res = await handler ( event ) ;
6262
6363 expect ( res . batchItemFailures ) . toEqual ( [ ] ) ;
64- expect ( ttlActions . delete ) . toHaveBeenCalledWith ( nhsAppStatusEvent ) ;
64+ expect ( ttlActions . markWithdrawn ) . toHaveBeenCalledWith ( nhsAppStatusEvent ) ;
6565 expect ( eventPublisher . sendEvents ) . toHaveBeenCalledWith (
6666 [ digitalLetterReadEvent ] ,
6767 validateDigitalLetterRead ,
@@ -131,14 +131,16 @@ describe('createHandler', () => {
131131 } ) ;
132132 } ) ;
133133
134- it ( 'handles ttlActions.delete failure' , async ( ) => {
135- ttlActions . delete . mockResolvedValue ( { result : 'failed' } ) ;
134+ it ( 'handles ttlActions.markWithdrawn failure' , async ( ) => {
135+ ttlActions . markWithdrawn . mockResolvedValue ( { result : 'failed' } ) ;
136136 const event : SQSEvent = {
137137 Records : [ { body : JSON . stringify ( eventBusEvent ) , messageId : 'msg1' } ] ,
138138 } as any ;
139139
140140 const res = await handler ( event ) ;
141141
142+ expect ( ttlActions . markWithdrawn ) . toHaveBeenCalledWith ( nhsAppStatusEvent ) ;
143+ expect ( eventPublisher . sendEvents ) . not . toHaveBeenCalled ( ) ;
142144 expect ( res . batchItemFailures ) . toEqual ( [ { itemIdentifier : 'msg1' } ] ) ;
143145 expect ( logger . info ) . toHaveBeenCalledWith ( {
144146 description : 'Processed SQS Event.' ,
@@ -202,7 +204,7 @@ describe('createHandler', () => {
202204 } ) ;
203205
204206 it ( 'processes multiple successful events and sends them as a batch' , async ( ) => {
205- ttlActions . delete . mockResolvedValue ( {
207+ ttlActions . markWithdrawn . mockResolvedValue ( {
206208 result : 'success' ,
207209 ttlItem : { event : messageDownloadedEvent } ,
208210 } ) ;
@@ -217,7 +219,7 @@ describe('createHandler', () => {
217219 const res = await handler ( sqsEvent ) ;
218220
219221 expect ( res . batchItemFailures ) . toEqual ( [ ] ) ;
220- expect ( ttlActions . delete ) . toHaveBeenCalledTimes ( 3 ) ;
222+ expect ( ttlActions . markWithdrawn ) . toHaveBeenCalledTimes ( 3 ) ;
221223 expect ( eventPublisher . sendEvents ) . toHaveBeenCalledWith (
222224 [ digitalLetterReadEvent , digitalLetterReadEvent , digitalLetterReadEvent ] ,
223225 validateDigitalLetterRead ,
@@ -231,7 +233,7 @@ describe('createHandler', () => {
231233 } ) ;
232234
233235 it ( 'handles partial event publishing failures and logs warning' , async ( ) => {
234- ttlActions . delete . mockResolvedValue ( {
236+ ttlActions . markWithdrawn . mockResolvedValue ( {
235237 result : 'success' ,
236238 ttlItem : { event : messageDownloadedEvent } ,
237239 } ) ;
@@ -260,7 +262,7 @@ describe('createHandler', () => {
260262 } ) ;
261263
262264 it ( 'handles event publishing exception and logs warning' , async ( ) => {
263- ttlActions . delete . mockResolvedValue ( {
265+ ttlActions . markWithdrawn . mockResolvedValue ( {
264266 result : 'success' ,
265267 ttlItem : { event : messageDownloadedEvent } ,
266268 } ) ;
@@ -286,7 +288,7 @@ describe('createHandler', () => {
286288 } ) ;
287289
288290 it ( 'does not call eventPublisher when no successful events' , async ( ) => {
289- ttlActions . delete . mockResolvedValue ( { result : 'failed' } ) ;
291+ ttlActions . markWithdrawn . mockResolvedValue ( { result : 'failed' } ) ;
290292
291293 const event : SQSEvent = {
292294 Records : [ { body : JSON . stringify ( eventBusEvent ) , messageId : 'msg1' } ] ,
@@ -305,7 +307,7 @@ describe('createHandler', () => {
305307 } ) ;
306308
307309 it ( 'does not call eventPublisher when no TTL record is found' , async ( ) => {
308- ttlActions . delete . mockResolvedValue ( { result : 'success' } ) ;
310+ ttlActions . markWithdrawn . mockResolvedValue ( { result : 'success' } ) ;
309311
310312 const event : SQSEvent = {
311313 Records : [ { body : JSON . stringify ( eventBusEvent ) , messageId : 'msg1' } ] ,
@@ -324,7 +326,7 @@ describe('createHandler', () => {
324326 } ) ;
325327
326328 it ( 'handles mixed success and failure scenarios' , async ( ) => {
327- ttlActions . delete
329+ ttlActions . markWithdrawn
328330 . mockResolvedValueOnce ( {
329331 result : 'success' ,
330332 ttlItem : { event : messageDownloadedEvent } ,
0 commit comments