@@ -411,36 +411,20 @@ describe('Class: BasePersistenceLayer', () => {
411
411
await persistenceLayer . saveSuccess ( { foo : 'bar' } , { bar : 'baz' } ) ;
412
412
413
413
// Act & Assess
414
- await expect (
415
- persistenceLayer . saveInProgress ( { foo : 'bar' } )
416
- ) . rejects . toThrow ( IdempotencyItemAlreadyExistsError ) ;
417
414
expect ( putRecordSpy ) . toHaveBeenCalledTimes ( 0 ) ;
418
- } ) ;
419
-
420
- test ( 'when called and there is an in-progress record in the cache, it returns' , async ( ) => {
421
- // Prepare
422
- const persistenceLayer = new PersistenceLayerTestClass ( ) ;
423
- persistenceLayer . configure ( {
424
- config : new IdempotencyConfig ( {
425
- useLocalCache : true ,
426
- } ) ,
427
- } ) ;
428
- jest . spyOn ( persistenceLayer , '_getRecord' ) . mockImplementationOnce (
429
- ( ) =>
430
- new IdempotencyRecord ( {
431
- idempotencyKey : 'my-lambda-function#mocked-hash' ,
432
- status : IdempotencyRecordStatus . INPROGRESS ,
433
- payloadHash : 'different-hash' ,
434
- expiryTimestamp : Date . now ( ) / 1000 + 3600 ,
435
- inProgressExpiryTimestamp : Date . now ( ) + 2000 ,
436
- } )
437
- ) ;
438
- await persistenceLayer . getRecord ( { foo : 'bar' } ) ;
439
-
440
- // Act & Assess
441
- await expect (
442
- persistenceLayer . saveInProgress ( { foo : 'bar' } )
443
- ) . resolves . toBeUndefined ( ) ;
415
+ try {
416
+ await persistenceLayer . saveInProgress ( { foo : 'bar' } ) ;
417
+ } catch ( error ) {
418
+ if ( error instanceof IdempotencyItemAlreadyExistsError ) {
419
+ expect ( error . existingRecord ) . toEqual (
420
+ expect . objectContaining ( {
421
+ idempotencyKey : 'my-lambda-function#mocked-hash' ,
422
+ status : IdempotencyRecordStatus . COMPLETED ,
423
+ } )
424
+ ) ;
425
+ }
426
+ }
427
+ expect . assertions ( 2 ) ;
444
428
} ) ;
445
429
} ) ;
446
430
@@ -500,6 +484,7 @@ describe('Class: BasePersistenceLayer', () => {
500
484
persistenceLayer . configure ( {
501
485
config : new IdempotencyConfig ( {
502
486
payloadValidationJmesPath : 'foo' ,
487
+ useLocalCache : true ,
503
488
} ) ,
504
489
} ) ;
505
490
const existingRecord = new IdempotencyRecord ( {
0 commit comments