import { describe, expect, it } from "@suaveplan/testing/runner"; import { BatchMigratorConfigSchema, DistributedLockConfigSchema, MemoryStorageOptionsSchema, MigrationRunnerOptionsSchema, RedisLockConfigSchema, RunOptionsSchema, } from "./migration.schemas.js"; describe("RunOptionsSchema", () => { it("parses empty object", { timeout: 5000 }, () => { const r = RunOptionsSchema.parse({}); expect(r.signal).toBeUndefined(); expect(r.target).toBeUndefined(); }); it("parses with target", { timeout: 5000 }, () => { const r = RunOptionsSchema.parse({ target: "001_init" }); expect(r.target).toBe("001_init"); }); it("parses with signal", { timeout: 5000 }, () => { const ctrl = new AbortController(); const r = RunOptionsSchema.parse({ signal: ctrl.signal }); expect(r.signal).toBe(ctrl.signal); }); it("rejects extra keys", { timeout: 5000 }, () => { expect(() => RunOptionsSchema.parse({ unknown: true })).toThrow(); }); }); describe("MigrationRunnerOptionsSchema", () => { it("applies defaults", { timeout: 5000 }, () => { const r = MigrationRunnerOptionsSchema.parse({}); expect(r.dryRun).toBe(false); expect(r.checksumValidation).toBe(true); }); it("accepts overrides", { timeout: 5000 }, () => { const r = MigrationRunnerOptionsSchema.parse({ dryRun: true, checksumValidation: false, }); expect(r.dryRun).toBe(true); expect(r.checksumValidation).toBe(false); }); }); describe("DistributedLockConfigSchema", () => { it("parses empty object", { timeout: 5000 }, () => { const r = DistributedLockConfigSchema.parse({}); expect(r.key).toBeUndefined(); }); it("rejects negative ttl", { timeout: 5000 }, () => { expect(() => DistributedLockConfigSchema.parse({ ttl: -1 })).toThrow(); }); it("accepts positive ttl", { timeout: 5000 }, () => { const r = DistributedLockConfigSchema.parse({ ttl: 5000 }); expect(r.ttl).toBe(5000); }); }); describe("RedisLockConfigSchema", () => { it("parses with key", { timeout: 5000 }, () => { const r = RedisLockConfigSchema.parse({ key: "my-lock" }); expect(r.key).toBe("my-lock"); }); it("rejects zero ttl", { timeout: 5000 }, () => { expect(() => RedisLockConfigSchema.parse({ ttl: 0 })).toThrow(); }); }); describe("BatchMigratorConfigSchema", () => { it("defaults concurrency to 5", { timeout: 5000 }, () => { const r = BatchMigratorConfigSchema.parse({}); expect(r.concurrency).toBe(5); }); it("rejects concurrency of 0", { timeout: 5000 }, () => { expect(() => BatchMigratorConfigSchema.parse({ concurrency: 0 }) ).toThrow(); }); it("accepts positive concurrency", { timeout: 5000 }, () => { const r = BatchMigratorConfigSchema.parse({ concurrency: 3 }); expect(r.concurrency).toBe(3); }); }); describe("MemoryStorageOptionsSchema", () => { it("parses empty", { timeout: 5000 }, () => { const r = MemoryStorageOptionsSchema.parse({}); expect(r.maxSize).toBeUndefined(); }); it("accepts maxSize", { timeout: 5000 }, () => { const r = MemoryStorageOptionsSchema.parse({ maxSize: 100 }); expect(r.maxSize).toBe(100); }); it("rejects negative maxSize", { timeout: 5000 }, () => { expect(() => MemoryStorageOptionsSchema.parse({ maxSize: -1 }) ).toThrow(); }); });