Files
piik/tests/creation-profile.test.ts
T
AAA b76d2cc0a5 feat(rooms): replace SQLite with leased memory rooms (#211)
Implements the accepted memory-resident room and access model on the single piik-v8 Browser wire. Local repository, full Web, build, and Chrome access/privacy gates passed before merge.
2026-08-23 21:47:49 +08:00

65 lines
1.7 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "vitest";
import {
readCreationProfile,
saveCreationProfile,
} from "../src/client/lib/creation-profile.ts";
describe("Host creation profile", () => {
afterEach(() => {
vi.unstubAllGlobals();
});
it("defaults to open code entry without a room password", () => {
vi.stubGlobal("window", {
localStorage: { getItem: () => null },
});
expect(readCreationProfile()).toEqual({
codeEntryPolicy: "open",
roomPassword: null,
});
});
it("persists the accepted creation preferences in same-origin storage", () => {
const values = new Map<string, string>();
vi.stubGlobal("window", {
localStorage: {
getItem: (key: string) => values.get(key) ?? null,
setItem: (key: string, value: string) => values.set(key, value),
removeItem: (key: string) => values.delete(key),
},
});
saveCreationProfile({
codeEntryPolicy: "password",
roomPassword: "room-password",
});
expect(readCreationProfile()).toEqual({
codeEntryPolicy: "password",
roomPassword: "room-password",
});
expect(values.get("screener:host-creation-profile:v1")).not.toContain(
"SITE_ACCESS_PASSWORD",
);
});
it("discards malformed or incomplete password-policy records", () => {
const removeItem = vi.fn();
vi.stubGlobal("window", {
localStorage: {
getItem: () =>
JSON.stringify({ codeEntryPolicy: "password", roomPassword: null }),
removeItem,
},
});
expect(readCreationProfile()).toEqual({
codeEntryPolicy: "open",
roomPassword: null,
});
expect(removeItem).toHaveBeenCalledOnce();
});
});