import { describe, expect, it, vi } from "vitest"; import { createBobbinClient } from "#lib/api/client.ts"; import { fetchPinned, fetchPinnedByKey } from "#lib/components/profile/pages.ts"; const manifest = (uri: string, name: string) => ({ uri, value: { declaration: { owner: "did:plc:alice", name }, createdAt: "2026-08-01T00:00:00Z" } }); const didKey = "did:plc:repo"; const legacyA = "at://did:plc:alice/sh.tangled.repo/legacy-a"; const legacyB = "at://did:plc:alice/sh.tangled.repo/legacy-b"; const ctx = () => { const fetch = vi.fn(async (_input, init) => { const { xrpc } = JSON.parse(String(init?.body)) as { xrpc: string }; const items = xrpc === "org.tangled.repo.getReposByRepoDids" ? [manifest(`at://${didKey}/org.tangled.repo.manifest/self`, "modern")] : [manifest(legacyA, "legacy-a"), manifest(legacyB, "legacy-b")]; return Response.json({ output: { items }, data: {} }); }); return createBobbinClient({ serviceUrl: "https://bobbin.test", fetch }); }; const options = { keys: [legacyB, didKey, legacyA], did: "did:plc:alice", handle: "alice.test" }; describe("fetchPinnedByKey", () => { it("files a did pin and legacy uri pins under the key they were asked for", async () => { const cards = await fetchPinnedByKey(ctx(), options); expect([...cards.keys()].sort()).toEqual([didKey, legacyA, legacyB].sort()); expect(cards.get(didKey)?.name).toBe("modern"); expect(cards.get(legacyA)?.name).toBe("legacy-a"); expect(cards.get(legacyB)?.name).toBe("legacy-b"); }); }); describe("fetchPinned", () => { it("keeps the order of the keys, legacy pins included", async () => { const cards = await fetchPinned(ctx(), options); expect(cards.map((card) => card.name)).toEqual(["legacy-b", "modern", "legacy-a"]); }); });