@@ -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 */
2021export 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
5054class 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