import { describe, expect, it } from "vitest"; import { moduleTableName, physicalModuleTableNameSchema } from "../src/index.js"; describe("module schema contract", () => { it("creates deterministic physical names from module and local identifiers", () => { expect(moduleTableName("calendar", "events")).toBe("calendar_events"); expect(moduleTableName("care-team", "member_notes")).toBe("care_team_member_notes"); }); it("rejects unsafe logical names and PostgreSQL identifiers beyond 63 characters", () => { expect(() => moduleTableName("calendar", "EventItems")).toThrow(); expect(() => moduleTableName("calendar", "event-items")).toThrow(); expect(physicalModuleTableNameSchema.safeParse("a".repeat(63)).success).toBe(true); expect(physicalModuleTableNameSchema.safeParse("a".repeat(64)).success).toBe(false); expect(() => moduleTableName("a".repeat(60), "rows")).toThrow( "The namespaced PostgreSQL table name is invalid or too long.", ); }); });