Files
alla-allaos-fullstack/src/features/foundation/business-events/replay.test.ts
2026-07-13 11:00:49 +07:00

32 lines
1.0 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { assertReplayRequestIsScoped, createReplayPlan } from './replay.ts';
import type { ReplaySource } from './types.ts';
const source: ReplaySource = {
sourceName: 'test-source',
async *listEvents() {}
};
test('replay request requires organization scope and valid dates', () => {
assert.doesNotThrow(() =>
assertReplayRequestIsScoped({
organizationId: 'org-1',
occurredFrom: '2026-07-13T00:00:00.000Z'
})
);
assert.throws(() => assertReplayRequestIsScoped({ organizationId: '' }), /organizationId/);
assert.throws(
() => assertReplayRequestIsScoped({ organizationId: 'org-1', occurredTo: 'bad-date' }),
/valid ISO/
);
});
test('replay plan is dry-run and idempotent by default', () => {
const plan = createReplayPlan({ organizationId: 'org-1' }, source);
assert.equal(plan.dryRun, true);
assert.equal(plan.idempotencyRequired, true);
assert.equal(plan.ordering, 'occurred_at_then_event_id');
});