citation-evidence/src/shared/ids.test.ts

22 lines
869 B
TypeScript
Raw Normal View History

import { describe, it, expect } from "vitest";
import { newId } from "./ids";
describe("newId", () => {
it("returns ids with the expected prefix for each kind", () => {
expect(newId("document")).toMatch(/^doc_[0-9a-f-]{36}$/);
expect(newId("representation")).toMatch(/^rep_[0-9a-f-]{36}$/);
expect(newId("annotation")).toMatch(/^ann_[0-9a-f-]{36}$/);
expect(newId("evidence")).toMatch(/^ev_[0-9a-f-]{36}$/);
expect(newId("evidence-set")).toMatch(/^evset_[0-9a-f-]{36}$/);
expect(newId("evidence-link")).toMatch(/^evlink_[0-9a-f-]{36}$/);
expect(newId("citation-card")).toMatch(/^card_[0-9a-f-]{36}$/);
expect(newId("citation-recovery")).toMatch(/^crec_[0-9a-f-]{36}$/);
});
it("returns a unique id on every call", () => {
const a = newId("annotation");
const b = newId("annotation");
expect(a).not.toBe(b);
});
});