CI / verify (pull_request) Successful in 1m0s
CI / infrastructure-smoke (pull_request) Successful in 36s
CI / migration-smoke (pull_request) Successful in 1m53s
CI / image-build (pull_request) Successful in 23s
CI / deploy-smoke (same-origin) (pull_request) Successful in 50s
CI / deploy-smoke (split) (pull_request) Successful in 1m30s
45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { parseModuleSchemaMetadataDefinition } from "../src/index.js";
|
|
|
|
describe("module schema metadata contract", () => {
|
|
it("accepts and freezes plain ABI-v1 metadata", () => {
|
|
const definition = parseModuleSchemaMetadataDefinition({
|
|
moduleId: "calendar",
|
|
tables: [
|
|
{ name: "calendar_events" },
|
|
{ name: "calendar_attendees", foreignKeys: [{ table: "calendar_events" }] },
|
|
],
|
|
});
|
|
|
|
expect(definition).toEqual({
|
|
moduleId: "calendar",
|
|
tables: [
|
|
{ name: "calendar_events", foreignKeys: [] },
|
|
{ name: "calendar_attendees", foreignKeys: [{ table: "calendar_events" }] },
|
|
],
|
|
});
|
|
expect(Object.isFrozen(definition)).toBe(true);
|
|
expect(Object.isFrozen(definition.tables)).toBe(true);
|
|
expect(Object.isFrozen(definition.tables[1]?.foreignKeys)).toBe(true);
|
|
});
|
|
|
|
it("strictly rejects malformed, executable, and class-backed metadata", () => {
|
|
class Metadata {
|
|
moduleId = "calendar";
|
|
tables = [{ name: "calendar_events" }];
|
|
}
|
|
|
|
for (const value of [
|
|
{ moduleId: "calendar", tables: [] },
|
|
{ moduleId: "calendar", tables: [{ name: "calendar_events", unknown: true }] },
|
|
{ moduleId: "calendar", tables: [{ name: "calendar_events", foreignKeys: [{}] }] },
|
|
{ moduleId: "calendar", tables: [{ name: "calendar_events", inspect: () => undefined }] },
|
|
new Metadata(),
|
|
]) {
|
|
expect(() => parseModuleSchemaMetadataDefinition(value)).toThrow(
|
|
"Invalid Ekklesia module schema metadata definition.",
|
|
);
|
|
}
|
|
});
|
|
});
|