-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidempotency.test.ts
More file actions
37 lines (32 loc) · 1.07 KB
/
Copy pathidempotency.test.ts
File metadata and controls
37 lines (32 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { beforeEach, describe, expect, it } from 'vitest';
import {
__resetIdempotencyStore,
checkIdempotency,
compositeKey,
markIdempotent,
} from './idempotency';
beforeEach(() => {
__resetIdempotencyStore();
});
describe('idempotency store', () => {
it('builds composite keys scoped by partner', () => {
expect(compositeKey('adjoe', 'evt_1')).toBe('adjoe:evt_1');
expect(compositeKey('gokart', 'evt_1')).toBe('gokart:evt_1');
expect(compositeKey('adjoe', 'evt_1')).not.toBe(compositeKey('gokart', 'evt_1'));
});
it('returns null for an unseen key', () => {
expect(checkIdempotency('adjoe:unseen')).toBeNull();
});
it('returns the stored record for a seen key', () => {
markIdempotent('adjoe:k', { seq: 42, at: '2026-04-22T12:00:00.000Z' });
expect(checkIdempotency('adjoe:k')).toEqual({
seq: 42,
at: '2026-04-22T12:00:00.000Z',
});
});
it('reset clears all records', () => {
markIdempotent('adjoe:k', { seq: 1, at: 'now' });
__resetIdempotencyStore();
expect(checkIdempotency('adjoe:k')).toBeNull();
});
});