Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import { describe, expect, it, vi } from "vitest";import { createBobbinClient } from "$lib/api/client";import { listNetworkVouches } from "$lib/api/graph";
const response = (items: unknown[] = []) => new Response(JSON.stringify({ items }), { status: 200, headers: { "content-type": "application/json" } });
describe("network vouches", () => { it("deduplicates actors and chunks requests at fifty", async () => { const fetch = vi.fn<typeof globalThis.fetch>(async () => response()); const ctx = createBobbinClient({ serviceUrl: "https://bobbin.test", fetch }); const actors = Array.from({ length: 55 }, (_, index) => `did:plc:actor${index}`); await listNetworkVouches(ctx, [...actors, actors[0]]); expect(fetch).toHaveBeenCalledTimes(2); expect(new URL(String(fetch.mock.calls[0][0])).searchParams.getAll("actors")).toEqual( actors.slice(0, 50) ); expect(new URL(String(fetch.mock.calls[1][0])).searchParams.getAll("actors")).toEqual( actors.slice(50) ); });
it("groups tagged items by requested actor", async () => { const alice = "did:plc:alice"; const bob = "did:plc:bob"; const item = (actor: string) => ({ actor, uri: `at://did:plc:viewer/sh.tangled.graph.vouch/${actor}`, value: { $type: "sh.tangled.graph.vouch", kind: "vouch", createdAt: "2026-01-01T00:00:00.000Z" } }); const ctx = createBobbinClient({ serviceUrl: "https://bobbin.test", fetch: async () => response([item(bob), item(alice), item(bob)]) }); const result = await listNetworkVouches(ctx, [alice, bob]); expect(result.items[alice]).toHaveLength(1); expect(result.items[bob]).toHaveLength(2); });});