Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103import { describe, expect, it, vi } from "vitest";import type { Did } from "@atcute/lexicons/syntax";import { createBobbinClient, type BobbinContext } from "$lib/api/client";import { availableKnots, availableSpindles } from "$lib/api/repoCreationTargets";
const did = "did:plc:alice" as Did;
describe("availableSpindles", () => { it("merges owned spindles and memberships across pages", async () => { const responses = [ { items: [ { uri: "at://did:plc:alice/sh.tangled.spindle/owned.example", value: {} } ], cursor: "next" }, { items: [ { uri: "at://did:plc:owner/sh.tangled.spindle.member/one", value: { instance: "member.example" } }, { uri: "at://did:plc:owner/sh.tangled.spindle.member/two", value: { instance: "owned.example" } }, { uri: "at://did:plc:owner/sh.tangled.spindle.member/bad", value: {} } ] }, { items: [ { uri: "at://did:plc:alice/sh.tangled.spindle/another.example", value: {} } ] } ]; const call = vi.fn(async (_schema: unknown, _options: unknown) => ({ ok: true, data: responses.shift() })); const ctx = { xrpc: { call } } as unknown as BobbinContext;
await expect(availableSpindles(ctx, did)).resolves.toEqual([ "another.example", "member.example", "owned.example" ]); expect(call).toHaveBeenCalledTimes(3); expect(call.mock.calls[0][1]).toMatchObject({ params: { subject: did, limit: 1_000 } }); expect(call.mock.calls[2][1]).toMatchObject({ params: { cursor: "next" } }); });});
describe("availableKnots", () => { it("offers the shared knot alongside the knots this account owns", async () => { const fetch = vi.fn<typeof globalThis.fetch>(async (input) => { const asked = new URL(String(input)); const page = asked.pathname === "/xrpc/sh.tangled.knot.listKnots" ? { items: [ { uri: "at://did:plc:alice/sh.tangled.knot/owned.example", value: {} } ] } : null; return new Response(JSON.stringify(page ?? { error: "MethodNotImplemented" }), { status: page ? 200 : 501, headers: { "content-type": "application/json" } }); }); const ctx = createBobbinClient({ serviceUrl: "https://bobbin.oyster.cafe", fetch });
await expect(availableKnots(ctx, did)).resolves.toEqual([ "knot2.tngl.boltless.dev", "owned.example" ]); expect(fetch.mock.calls.map(([input]) => new URL(String(input)).pathname)).toEqual([ "/xrpc/sh.tangled.knot.listKnots" ]); });
it("still offers the shared knot when this account owns none", async () => { const fetch = vi.fn<typeof globalThis.fetch>( async () => new Response(JSON.stringify({ items: [] }), { status: 200, headers: { "content-type": "application/json" } }) ); const ctx = createBobbinClient({ serviceUrl: "https://bobbin.oyster.cafe", fetch });
await expect(availableKnots(ctx, did)).resolves.toEqual(["knot2.tngl.boltless.dev"]); });});