npm workspaces (packages/*, apps/*) with shared TypeScript, ESLint and
Jest setup and `npm run check`. @crosscode/contracts builds to CommonJS
and ESM (tsup) with the crosscode.<name>/<major> schema-name helpers.
packages/ui and apps/{accounts,website,app} are placeholders.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { isSchema, parseSchemaName, schemaName } from "../src";
|
|
|
|
describe("schemaName", () => {
|
|
it("builds crosscode.<name>/<major>", () => {
|
|
expect(schemaName("event", 1)).toBe("crosscode.event/1");
|
|
expect(schemaName("church", 2)).toBe("crosscode.church/2");
|
|
});
|
|
|
|
it("refuses names and versions that don't fit the pattern", () => {
|
|
expect(() => schemaName("Event", 1)).toThrow();
|
|
expect(() => schemaName("event", 0)).toThrow();
|
|
expect(() => schemaName("event", 1.5)).toThrow();
|
|
expect(() => schemaName("", 1)).toThrow();
|
|
});
|
|
});
|
|
|
|
describe("parseSchemaName", () => {
|
|
it("splits a schema name", () => {
|
|
expect(parseSchemaName("crosscode.event/1")).toEqual({ name: "event", major: 1 });
|
|
expect(parseSchemaName("crosscode.hub-protocol/3")).toEqual({ name: "hub-protocol", major: 3 });
|
|
});
|
|
|
|
it.each([undefined, null, 1, "", "crosscode.event", "crosscode.event/0", "crosscode.event/01", "other.event/1", "crosscode.event/1 ", "crosscode.Event/1"])(
|
|
"returns null for %p",
|
|
(value) => {
|
|
expect(parseSchemaName(value)).toBeNull();
|
|
},
|
|
);
|
|
});
|
|
|
|
describe("isSchema", () => {
|
|
it("matches name and major", () => {
|
|
expect(isSchema("crosscode.event/1", "event", 1)).toBe(true);
|
|
expect(isSchema("crosscode.event/2", "event", 1)).toBe(false);
|
|
expect(isSchema("crosscode.church/1", "event", 1)).toBe(false);
|
|
expect(isSchema(undefined, "event", 1)).toBe(false);
|
|
});
|
|
});
|