import { describe, expect, it } from "vitest"; import { authorDidOf, rkeyFromUri } from "$lib/api/uri"; const repoDid = "did:plc:barnacle"; describe("authorDidOf", () => { it("names the writer the knot stamped into a repo-hosted record", () => { const record = { uri: `at://${repoDid}/sh.tangled.repo.issue/3lk`, value: { title: "kelp", "x-tngl-editor": "did:plc:limpet" } }; expect(authorDidOf(record)).toBe("did:plc:limpet"); }); it("falls back to the uri authority for a record on its writer's pds", () => { expect(authorDidOf({ uri: "at://did:plc:limpet/sh.tangled.repo.issue/3lk" })).toBe( "did:plc:limpet" ); }); it("ignores an editor field that isn't a string", () => { const record = { uri: "at://did:plc:limpet/sh.tangled.repo.issue/3lk", value: { "x-tngl-editor": 7 } }; expect(authorDidOf(record)).toBe("did:plc:limpet"); }); }); describe("rkeyFromUri", () => { it("picks record keys out of canonical URIs", () => { expect(rkeyFromUri("at://did:plc:limpet/sh.tangled.repo.issue/3lk2a")).toBe("3lk2a"); }); it("rejects final segments that aren't record keys instead of returning junk", () => { expect(() => rkeyFromUri("at://did:plc:limpet/sh.tangled.repo.issue/has space")).toThrow( /is not a valid rkey/ ); }); });