@@ -50,7 +50,6 @@ describe('Class: DynamoDBPersistenceLayer', () => {
50
50
51
51
afterEach ( ( ) => {
52
52
vi . clearAllMocks ( ) ;
53
- vi . resetAllMocks ( ) ;
54
53
client . reset ( ) ;
55
54
} ) ;
56
55
@@ -306,9 +305,9 @@ describe('Class: DynamoDBPersistenceLayer', () => {
306
305
307
306
it ( 'puts record in DynamoDB table when using payload validation' , async ( ) => {
308
307
// Prepare
309
- vi . spyOn ( persistenceLayer , 'isPayloadValidationEnabled' ) . mockReturnValue (
310
- true
311
- ) ;
308
+ const persistenceLayerSpy = vi
309
+ . spyOn ( persistenceLayer , 'isPayloadValidationEnabled' )
310
+ . mockReturnValue ( true ) ;
312
311
const status = IdempotencyRecordStatus . EXPIRED ;
313
312
const expiryTimestamp = 0 ;
314
313
const record = new IdempotencyRecord ( {
@@ -344,6 +343,7 @@ describe('Class: DynamoDBPersistenceLayer', () => {
344
343
ConditionExpression :
345
344
'attribute_not_exists(#id) OR #expiry < :now OR (#status = :inprogress AND attribute_exists(#in_progress_expiry) AND #in_progress_expiry < :now_in_millis)' ,
346
345
} ) ;
346
+ persistenceLayerSpy . mockRestore ( ) ;
347
347
} ) ;
348
348
349
349
it ( 'throws when called with a record that fails any condition' , async ( ) => {
@@ -353,6 +353,7 @@ describe('Class: DynamoDBPersistenceLayer', () => {
353
353
status : IdempotencyRecordStatus . EXPIRED ,
354
354
expiryTimestamp : 0 ,
355
355
} ) ;
356
+ const expiration = Date . now ( ) ;
356
357
client . on ( PutItemCommand ) . rejects (
357
358
new ConditionalCheckFailedException ( {
358
359
$metadata : {
@@ -363,7 +364,7 @@ describe('Class: DynamoDBPersistenceLayer', () => {
363
364
Item : {
364
365
id : { S : 'test-key' } ,
365
366
status : { S : 'INPROGRESS' } ,
366
- expiration : { N : Date . now ( ) . toString ( ) } ,
367
+ expiration : { N : expiration . toString ( ) } ,
367
368
} ,
368
369
} )
369
370
) ;
@@ -373,9 +374,9 @@ describe('Class: DynamoDBPersistenceLayer', () => {
373
374
new IdempotencyItemAlreadyExistsError (
374
375
`Failed to put record for already existing idempotency key: ${ record . idempotencyKey } ` ,
375
376
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 ,
379
380
} )
380
381
)
381
382
) ;
@@ -575,10 +576,9 @@ describe('Class: DynamoDBPersistenceLayer', () => {
575
576
576
577
it ( 'uses the payload hash in the expression when payload validation is enabled' , async ( ) => {
577
578
// Prepare
578
- vi . spyOn (
579
- persistenceLayer ,
580
- 'isPayloadValidationEnabled'
581
- ) . mockImplementation ( ( ) => true ) ;
579
+ const persistenceLayerSpy = vi
580
+ . spyOn ( persistenceLayer , 'isPayloadValidationEnabled' )
581
+ . mockImplementation ( ( ) => true ) ;
582
582
const expiryTimestamp = Date . now ( ) ;
583
583
const record = new IdempotencyRecord ( {
584
584
idempotencyKey : dummyKey ,
@@ -612,6 +612,7 @@ describe('Class: DynamoDBPersistenceLayer', () => {
612
612
':validation_key' : record . payloadHash ,
613
613
} ) ,
614
614
} ) ;
615
+ persistenceLayerSpy . mockRestore ( ) ;
615
616
} ) ;
616
617
} ) ;
617
618
0 commit comments