Skip to content

Commit 06bb1cc

Browse files
committed
test(idempotency): add keyPrefix test for middy and wrapper
1 parent 7f8a1f4 commit 06bb1cc

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ describe('Given a class with a function to decorate', () => {
6161

6262
// Act
6363
const result = await handler({}, context);
64-
6564

6665
// Assert
6766
expect(result).toBeTruthy();

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,45 @@ describe('Function: makeIdempotent', () => {
393393
expect(saveSuccessSpy).toHaveBeenCalledTimes(0);
394394
}
395395
);
396+
397+
it.each([
398+
{
399+
type: 'wrapper',
400+
},
401+
{ type: 'middleware' },
402+
])(
403+
'passes keyPrefix correctly in idempotency handler ($type)',
404+
async ({ type }) => {
405+
// Prepare
406+
const keyPrefix = 'my-custom-prefix';
407+
const options = {
408+
...mockIdempotencyOptions,
409+
keyPrefix,
410+
config: new IdempotencyConfig({
411+
eventKeyJmesPath: 'idempotencyKey',
412+
}),
413+
};
414+
const handler =
415+
type === 'wrapper'
416+
? makeIdempotent(fnSuccessfull, options)
417+
: middy(fnSuccessfull).use(makeHandlerIdempotent(options));
418+
419+
const configureSpy = vi.spyOn(
420+
mockIdempotencyOptions.persistenceStore,
421+
'configure'
422+
);
423+
424+
// Act
425+
const result = await handler(event, context);
426+
427+
// Assess
428+
expect(result).toBe(true);
429+
expect(configureSpy).toHaveBeenCalledWith(
430+
expect.objectContaining({ keyPrefix })
431+
);
432+
}
433+
);
434+
396435
it('uses the first argument when when wrapping an arbitrary function', async () => {
397436
// Prepare
398437
const config = new IdempotencyConfig({});

0 commit comments

Comments
 (0)