Something went wrong. Try again.
The Social Wire — a comprehensive client for creating on the atmosphere thesocialwire.app
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162import { describe, expect, it } from "bun:test";import { parseReadStateJson, READ_STATE_STORAGE_KEY, loadReadState, saveReadState,} from "@/lib/entryReadStateStorage";
describe("parseReadStateJson", () => { it("returns empty object for null or empty", () => { expect(parseReadStateJson(null)).toEqual({}); expect(parseReadStateJson("")).toEqual({}); });
it("parses valid string map", () => { const uri = "at://did:plc:abc/site.standard.entry/xyz"; expect( parseReadStateJson(JSON.stringify({ [uri]: "2026-01-01T00:00:00.000Z" })) ).toEqual({ [uri]: "2026-01-01T00:00:00.000Z" }); });
it("drops non-string values", () => { expect( parseReadStateJson( JSON.stringify({ ok: "2026-01-01T00:00:00.000Z", bad: 1, x: null }) ) ).toEqual({ ok: "2026-01-01T00:00:00.000Z" }); });
it("returns {} for invalid JSON", () => { expect(parseReadStateJson("not-json")).toEqual({}); });});
describe("loadReadState / saveReadState", () => { it("round-trips via Storage", () => { const mem = new Map<string, string>(); const storage = { getItem: (k: string) => mem.get(k) ?? null, setItem: (k: string, v: string) => { mem.set(k, v); }, }; const uri = "at://did:plc:abc/site.standard.entry/xyz"; saveReadState(storage, { [uri]: "2026-05-12T12:00:00.000Z" }); expect(mem.get(READ_STATE_STORAGE_KEY)).toContain(uri); expect(loadReadState(storage)).toEqual({ [uri]: "2026-05-12T12:00:00.000Z" }); });});
it("isolates authenticated viewer caches from other accounts and the former shared cache", async () => { const { viewerReadStateStorageKey } = await import("@/lib/entryReadStateStorage"); const items = new Map<string, string>(); const storage = { getItem: (key: string) => items.get(key) ?? null, setItem: (key: string, value: string) => { items.set(key, value); } }; saveReadState(storage, { shared: "old" }); saveReadState(storage, { alice: "today" }, viewerReadStateStorageKey("did:plc:alice")); expect(loadReadState(storage, viewerReadStateStorageKey("did:plc:bob"))).toEqual({}); expect(loadReadState(storage, viewerReadStateStorageKey())).toEqual({}); expect(loadReadState(storage, viewerReadStateStorageKey("did:plc:alice"))).toEqual({ alice: "today" }); expect(loadReadState(storage)).toEqual({ shared: "old" });});