task ep.1.3.md

This commit is contained in:
phaichayon
2026-07-13 11:00:49 +07:00
parent e96320a24d
commit d78c56148e
18 changed files with 2944 additions and 8 deletions

View File

@@ -0,0 +1,31 @@
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');
});