Something went wrong. Try again.
The logic for serving and storing associations between users and apps
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import { describe, expect, it } from "vitest";import { parseSaveQuery } from "./save";
const did = "did:plc:z72i7hdynmk6r22z27h6tvur";
function saveUrl(params: Record<string, string>): URL { const url = new URL("https://loggedin.fyi/save"); for (const [key, value] of Object.entries(params)) { url.searchParams.set(key, value); } return url;}
describe("parseSaveQuery", () => { it("accepts a well-formed save origin", () => { expect(parseSaveQuery(saveUrl({ did, origin: "https://lightbox-loggedin.val.run" }))).toEqual({ ok: true, did, origin: "https://lightbox-loggedin.val.run", action: "save", }); });
it("accepts logout", () => { expect( parseSaveQuery(saveUrl({ did, origin: "http://localhost:3001", action: "logout" })), ).toEqual({ ok: true, did, origin: "http://localhost:3001", action: "logout", }); });
it("rejects missing or invalid fields", () => { expect(parseSaveQuery(saveUrl({ origin: "https://lightbox-loggedin.val.run" })).ok).toBe(false); expect(parseSaveQuery(saveUrl({ did })).ok).toBe(false); expect(parseSaveQuery(saveUrl({ did, origin: "http://evil.example" })).ok).toBe(false); expect(parseSaveQuery(saveUrl({ did, origin: "not-a-url" })).ok).toBe(false); expect( parseSaveQuery(saveUrl({ did, origin: "https://lightbox-loggedin.val.run/path" })).ok, ).toBe(false); expect( parseSaveQuery(saveUrl({ did, origin: "https://lightbox-loggedin.val.run", action: "wipe" })) .ok, ).toBe(false); });});