1
+ import { IdempotencyInvalidStatusError } from '../../../src/Exceptions' ;
1
2
import { IdempotencyRecord } from '../../../src/persistence/IdempotencyRecord' ;
2
3
import { IdempotencyRecordStatus } from '../../../src/types/IdempotencyRecordStatus' ;
3
4
/**
@@ -38,15 +39,38 @@ describe('Given an idempotency record that is not expired', () => {
38
39
Date . now = jest . fn ( ( ) => mockNowBeforeExiryTime ) ;
39
40
idempotencyRecord = new IdempotencyRecord ( mockIdempotencyKey , IdempotencyRecordStatus . INPROGRESS , expiryTimeAfterNow , mockInProgressExpiry , mockData , mockPayloadHash ) ;
40
41
} ) ;
42
+ describe ( 'When checking the status of the idempotency record' , ( ) => {
43
+ test ( 'Then the status is EXPIRED' , ( ) => {
44
+ expect ( idempotencyRecord . getStatus ( ) ) . toEqual ( IdempotencyRecordStatus . INPROGRESS ) ;
45
+ } ) ;
46
+
47
+ test ( 'Then the record is returned' , ( ) => {
48
+ expect ( idempotencyRecord . getResponse ( ) ) . toEqual ( mockData ) ;
49
+ } ) ;
50
+ } ) ;
51
+ } ) ;
52
+
53
+ describe ( 'Given an idempotency record that has a status not in the IdempotencyRecordStatus enum' , ( ) => {
54
+ let idempotencyRecord : IdempotencyRecord ;
55
+ beforeEach ( ( ) => {
56
+ const mockNowBeforeExiryTime = 1487076707000 ;
57
+ const expiryTimeAfterNow = 1487076708000 ;
58
+ Date . now = jest . fn ( ( ) => mockNowBeforeExiryTime ) ;
59
+ idempotencyRecord = new IdempotencyRecord ( mockIdempotencyKey , 'NOT_A_STATUS' as IdempotencyRecordStatus , expiryTimeAfterNow , mockInProgressExpiry , mockData , mockPayloadHash ) ;
60
+ } ) ;
41
61
describe ( 'When checking the status of the idempotency record' , ( ) => {
42
- let resultingStatus : IdempotencyRecordStatus ;
62
+ let resultingError : Error ;
43
63
beforeEach ( ( ) => {
44
- resultingStatus = idempotencyRecord . getStatus ( ) ;
64
+ try {
65
+ idempotencyRecord . getStatus ( ) ;
66
+ } catch ( e : unknown ) {
67
+ resultingError = e as Error ;
68
+ }
69
+
45
70
} ) ;
46
-
47
- test ( 'Then the status is EXPIRED ' , ( ) => {
48
- expect ( resultingStatus ) . toEqual ( IdempotencyRecordStatus . INPROGRESS ) ;
71
+
72
+ test ( 'Then an IdempotencyInvalidStatusError is thrown ' , ( ) => {
73
+ expect ( resultingError ) . toBeInstanceOf ( IdempotencyInvalidStatusError ) ;
49
74
} ) ;
50
75
} ) ;
51
- } ) ;
52
-
76
+ } ) ;
0 commit comments