File tree Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -29,8 +29,19 @@ abstract class PersistenceLayer implements PersistenceLayerInterface {
29
29
this . functionName = this . getEnvVarsService ( ) . getLambdaFunctionName ( ) + '.' + functionName ;
30
30
}
31
31
32
- public async deleteRecord ( ) : Promise < void > { }
33
-
32
+ public async deleteRecord ( data : unknown ) : Promise < void > {
33
+ const idempotencyRecord : IdempotencyRecord =
34
+ new IdempotencyRecord ( this . getHashedIdempotencyKey ( data ) ,
35
+ IdempotencyRecordStatus . EXPIRED ,
36
+ undefined ,
37
+ undefined ,
38
+ undefined ,
39
+ undefined
40
+ ) ;
41
+
42
+ this . _deleteRecord ( idempotencyRecord ) ;
43
+ }
44
+
34
45
public async getRecord ( data : unknown ) : Promise < IdempotencyRecord > {
35
46
const idempotencyKey : string = this . getHashedIdempotencyKey ( data ) ;
36
47
Original file line number Diff line number Diff line change @@ -197,4 +197,32 @@ describe('Class: Persistence Layer', ()=> {
197
197
expect ( getRecord ) . toHaveBeenCalledWith ( expectedIdempotencyKey ) ;
198
198
} ) ;
199
199
} ) ;
200
+
201
+ describe ( 'Method: deleteRecord' , ( ) => {
202
+ beforeEach ( ( ) => {
203
+ putRecord . mockClear ( ) ;
204
+ ( createHash as jest . MockedFunction < typeof createHash > ) . mockReturnValue (
205
+ {
206
+ update : cryptoUpdateMock ,
207
+ digest : cryptoDigestMock . mockReturnValue ( mockDigest )
208
+ } as unknown as Hash
209
+ ) ;
210
+ } ) ;
211
+
212
+ test ( 'When called it deletes the record with the idempotency key for the data passed in' , ( ) => {
213
+ const persistenceLayer : PersistenceLayer = new PersistenceLayerTestClass ( ) ;
214
+ const data = 'someData' ;
215
+ const lambdaFunctionName = 'LambdaName' ;
216
+ jest . spyOn ( EnvironmentVariablesService . prototype , 'getLambdaFunctionName' ) . mockReturnValue ( lambdaFunctionName ) ;
217
+
218
+ const functionName = 'functionName' ;
219
+ const expectedIdempotencyKey = lambdaFunctionName + '.' + functionName + '#' + mockDigest ;
220
+ persistenceLayer . configure ( functionName ) ;
221
+
222
+ persistenceLayer . deleteRecord ( data ) ;
223
+ const deletedIdempotencyRecord : IdempotencyRecord = deleteRecord . mock . calls [ 0 ] [ 0 ] ;
224
+
225
+ expect ( deletedIdempotencyRecord . idempotencyKey ) . toEqual ( expectedIdempotencyKey ) ;
226
+ } ) ;
227
+ } ) ;
200
228
} ) ;
You can’t perform that action at this time.
0 commit comments