Files
buzz-sheet/lib/editor/local-draft.test.ts
gunshiz 7708a2df31
CI / Verify (push) Successful in 59s
CI / Build immutable images and deploy (push) Successful in 1m58s
feat(admin) : persist drafts and add constellation conditions
2026-09-02 12:40:13 +07:00

28 lines
1.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { adminDraftKey, parseLocalDraft, serializeLocalDraft } from "./local-draft";
describe("local admin drafts", () => {
it("isolates drafts by guide and section", () => {
expect(adminDraftKey("guide-1", "team")).toBe("buzz-sheet:admin-draft:guide-1:team");
expect(adminDraftKey("guide-1", "weapon")).not.toBe(adminDraftKey("guide-1", "team"));
expect(adminDraftKey("guide-2", "team")).not.toBe(adminDraftKey("guide-1", "team"));
});
it("round trips a versioned draft", () => {
const serialized = serializeLocalDraft({ title: "Recovered team" }, 7);
const parsed = parseLocalDraft(serialized, (value) => {
if (!value || typeof value !== "object" || typeof (value as { title?: unknown }).title !== "string") return null;
return value as { title: string };
});
expect(parsed).toMatchObject({ schemaVersion: 1, serverVersion: 7, draft: { title: "Recovered team" } });
});
it("rejects corrupt, incompatible, and invalid drafts", () => {
const parse = (value: unknown) => typeof value === "string" ? value : null;
expect(parseLocalDraft("not-json", parse)).toBeNull();
expect(parseLocalDraft(JSON.stringify({ schemaVersion: 2, serverVersion: 1, updatedAt: "now", draft: "x" }), parse)).toBeNull();
expect(parseLocalDraft(JSON.stringify({ schemaVersion: 1, serverVersion: 1, updatedAt: "now", draft: 5 }), parse)).toBeNull();
});
});