Skip to content

Commit 6080fb0

Browse files
committed
chore(testing): stub IdempotencyService.createWebhookIdempotencyKey in the central mock
1 parent 5fc969c commit 6080fb0

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎packages/testing/src/mocks/idempotency-service.mock.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { vi } from 'vitest'
66
* Every `IdempotencyService` instance and the exported singletons (`webhookIdempotency`,
77
* `pollingIdempotency`, `chatSendIdempotency`) share these functions. `executeWithIdempotency`
88
* runs the operation once, as a first claim would; `executeOrSkipInProgress` resolves with its
9-
* result. `atomicallyClaim` is a bare `vi.fn()`; `release` resolves `undefined`.
9+
* result. `atomicallyClaim` is a bare `vi.fn()`; `release` resolves `undefined`. The static
10+
* `IdempotencyService.createWebhookIdempotencyKey` returns `<webhookId>:idempotency-key`.
1011
* `mockConstructor` records each `new IdempotencyService(config)`. Defaults are
1112
* `vi.fn(impl)`, so `mockReset()` restores them.
1213
*
@@ -19,6 +20,9 @@ import { vi } from 'vitest'
1920
*/
2021
export const idempotencyServiceMockFns = {
2122
mockConstructor: vi.fn((_config?: unknown): void => {}),
23+
mockCreateWebhookIdempotencyKey: vi.fn(
24+
(webhookId: string, ..._args: unknown[]): string => `${webhookId}:idempotency-key`
25+
),
2226
mockAtomicallyClaim: vi.fn(),
2327
mockRelease: vi.fn(async (..._args: unknown[]): Promise<void> => {}),
2428
mockExecuteWithIdempotency: vi.fn(
@@ -48,6 +52,9 @@ const idempotencyMethods = {
4852
}
4953

5054
class IdempotencyService {
55+
static createWebhookIdempotencyKey = (webhookId: string, ...args: unknown[]) =>
56+
idempotencyServiceMockFns.mockCreateWebhookIdempotencyKey(webhookId, ...args)
57+
5158
constructor(config?: unknown) {
5259
idempotencyServiceMockFns.mockConstructor(config)
5360
}

0 commit comments

Comments
 (0)