Skip to content

Commit 4dff002

Browse files
feat: branch coverage and cleaning up imports
1 parent a237cf9 commit 4dff002

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

packages/idempotency/src/persistence/DynamoDbPersistenceLayer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-empty-function */
2-
import { IdempotencyRecord, PersistenceLayer } from './PersistenceLayer';
2+
import { PersistenceLayer } from './PersistenceLayer';
3+
import { IdempotencyRecord } from './IdempotencyRecord';
34

45
class DynamoDBPersistenceLayer extends PersistenceLayer {
56
public constructor(_tableName: string, _key_attr: string = 'id') {

packages/idempotency/src/persistence/PersistenceLayer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,5 @@ abstract class PersistenceLayer implements PersistenceLayerInterface {
125125
}
126126

127127
export {
128-
IdempotencyRecord,
129128
PersistenceLayer
130129
};

packages/idempotency/src/persistence/PersistenceLayerInterface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IdempotencyRecord } from './PersistenceLayer';
1+
import { IdempotencyRecord } from './IdempotencyRecord';
22

33
interface PersistenceLayerInterface {
44
configure(functionName: string): void

packages/idempotency/tests/unit/PersistenceLayer.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,29 @@ describe('Class: Persistence Layer', ()=> {
8080
expect(savedIdempotencyRecord.idempotencyKey).toEqual(expectedIdempotencyKey);
8181
});
8282

83+
test('When called without a function name it creates an idempotency key from the Lambda name only and a digest of the md5 hash of the data', async ()=> {
84+
const data = 'someData';
85+
const lambdaFunctionName = 'LambdaName';
86+
jest.spyOn(EnvironmentVariablesService.prototype, 'getLambdaFunctionName').mockReturnValue(lambdaFunctionName);
87+
88+
const expectedIdempotencyKey = lambdaFunctionName + '.' + '#' + mockDigest;
89+
const persistenceLayer: PersistenceLayer = new PersistenceLayerTestClass();
90+
persistenceLayer.configure();
91+
92+
await persistenceLayer.saveInProgress(data);
93+
94+
const savedIdempotencyRecord: IdempotencyRecord = putRecord.mock.calls[0][0];
95+
96+
expect(createHash).toHaveBeenCalledWith(
97+
expect.stringMatching('md5'),
98+
);
99+
expect(cryptoUpdateMock).toHaveBeenCalledWith(expect.stringMatching(data));
100+
expect(cryptoDigestMock).toHaveBeenCalledWith(
101+
expect.stringMatching('base64')
102+
);
103+
expect(savedIdempotencyRecord.idempotencyKey).toEqual(expectedIdempotencyKey);
104+
});
105+
83106
test('When called it sets the expiry timestamp to one hour in the future', async ()=> {
84107
const persistenceLayer: PersistenceLayer = new PersistenceLayerTestClass();
85108
const data = 'someData';

0 commit comments

Comments
 (0)