~james/core

core/web/src/lib/components/profile/pagesPinned.test.ts -rw-r--r-- 1.8 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 15 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { describe, expect, it, vi } from "vitest";
import { createBobbinClient } from "#lib/api/client.ts";
import {
	fetchPinned,
	fetchPinnedByKey,
	type PinnedOptions
} from "#lib/components/profile/pages.ts";
import type { Fetch } from "#lib/fetch.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<Fetch>(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"
} satisfies PinnedOptions;

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"]);
	});
});