@@ -50,7 +50,6 @@ describe('Class: DynamoDBPersistenceLayer', () => {
5050
5151 afterEach ( ( ) => {
5252 vi . clearAllMocks ( ) ;
53- vi . resetAllMocks ( ) ;
5453 client . reset ( ) ;
5554 } ) ;
5655
@@ -306,9 +305,9 @@ describe('Class: DynamoDBPersistenceLayer', () => {
306305
307306 it ( 'puts record in DynamoDB table when using payload validation' , async ( ) => {
308307 // Prepare
309- vi . spyOn ( persistenceLayer , 'isPayloadValidationEnabled' ) . mockReturnValue (
310- true
311- ) ;
308+ const persistenceLayerSpy = vi
309+ . spyOn ( persistenceLayer , 'isPayloadValidationEnabled' )
310+ . mockReturnValue ( true ) ;
312311 const status = IdempotencyRecordStatus . EXPIRED ;
313312 const expiryTimestamp = 0 ;
314313 const record = new IdempotencyRecord ( {
@@ -344,6 +343,7 @@ describe('Class: DynamoDBPersistenceLayer', () => {
344343 ConditionExpression :
345344 'attribute_not_exists(#id) OR #expiry < :now OR (#status = :inprogress AND attribute_exists(#in_progress_expiry) AND #in_progress_expiry < :now_in_millis)' ,
346345 } ) ;
346+ persistenceLayerSpy . mockRestore ( ) ;
347347 } ) ;
348348
349349 it ( 'throws when called with a record that fails any condition' , async ( ) => {
@@ -353,6 +353,7 @@ describe('Class: DynamoDBPersistenceLayer', () => {
353353 status : IdempotencyRecordStatus . EXPIRED ,
354354 expiryTimestamp : 0 ,
355355 } ) ;
356+ const expiration = Date . now ( ) ;
356357 client . on ( PutItemCommand ) . rejects (
357358 new ConditionalCheckFailedException ( {
358359 $metadata : {
@@ -363,7 +364,7 @@ describe('Class: DynamoDBPersistenceLayer', () => {
363364 Item : {
364365 id : { S : 'test-key' } ,
365366 status : { S : 'INPROGRESS' } ,
366- expiration : { N : Date . now ( ) . toString ( ) } ,
367+ expiration : { N : expiration . toString ( ) } ,
367368 } ,
368369 } )
369370 ) ;
@@ -373,9 +374,9 @@ describe('Class: DynamoDBPersistenceLayer', () => {
373374 new IdempotencyItemAlreadyExistsError (
374375 `Failed to put record for already existing idempotency key: ${ record . idempotencyKey } ` ,
375376 new IdempotencyRecord ( {
376- idempotencyKey : record . idempotencyKey ,
377- status : IdempotencyRecordStatus . EXPIRED ,
378- expiryTimestamp : Date . now ( ) / 1000 - 1 ,
377+ idempotencyKey : 'test-key' ,
378+ status : IdempotencyRecordStatus . INPROGRESS ,
379+ expiryTimestamp : expiration ,
379380 } )
380381 )
381382 ) ;
@@ -575,10 +576,9 @@ describe('Class: DynamoDBPersistenceLayer', () => {
575576
576577 it ( 'uses the payload hash in the expression when payload validation is enabled' , async ( ) => {
577578 // Prepare
578- vi . spyOn (
579- persistenceLayer ,
580- 'isPayloadValidationEnabled'
581- ) . mockImplementation ( ( ) => true ) ;
579+ const persistenceLayerSpy = vi
580+ . spyOn ( persistenceLayer , 'isPayloadValidationEnabled' )
581+ . mockImplementation ( ( ) => true ) ;
582582 const expiryTimestamp = Date . now ( ) ;
583583 const record = new IdempotencyRecord ( {
584584 idempotencyKey : dummyKey ,
@@ -612,6 +612,7 @@ describe('Class: DynamoDBPersistenceLayer', () => {
612612 ':validation_key' : record . payloadHash ,
613613 } ) ,
614614 } ) ;
615+ persistenceLayerSpy . mockRestore ( ) ;
615616 } ) ;
616617 } ) ;
617618
0 commit comments