Something went wrong. Try again.
Monorepo for Tangled
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495import { describe, expect, it, vi } from "vitest";import { createBobbinClient } from "$lib/api/client";import { listCollaborators } from "$lib/api/collaborators";
const owner = "did:plc:owner";const repoDid = "did:plc:repo";
const bobbin = (pages: Record<string, unknown>) => { const fetch = vi.fn<typeof globalThis.fetch>(async (input) => { const asked = new URL(String(input)); const page = pages[asked.pathname]; return new Response(JSON.stringify(page ?? { error: "MethodNotImplemented" }), { status: page ? 200 : 501, headers: { "content-type": "application/json" } }); }); return createBobbinClient({ serviceUrl: "https://bobbin.test", fetch });};
describe("listCollaborators", () => { it("lists the owner first, then accepted collaborators, then open invites", async () => { const ctx = bobbin({ "/xrpc/sh.tangled.repo.listCollaborators": { items: [ { subject: "did:plc:friend", addedBy: owner, createdAt: "a", effectiveSince: "b" }, { subject: owner, addedBy: owner, createdAt: "a", effectiveSince: "b" } ] }, "/xrpc/sh.tangled.repo.listCollaboratorInvites": { items: [ { subject: "did:plc:pending", addedBy: owner, createdAt: "c" }, { subject: "did:plc:friend", addedBy: owner, createdAt: "c" } ] }, "/xrpc/blue.microcosm.identity.resolveMiniDoc": { did: "x", handle: "someone.test" } });
await expect(listCollaborators(ctx, { ownerDid: owner, repoDid })).resolves.toEqual([ { did: owner, handle: "someone.test", standing: "owner", since: undefined }, { did: "did:plc:friend", handle: "someone.test", standing: "collaborator", since: "b" }, { did: "did:plc:pending", handle: "someone.test", standing: "invited", since: "c" } ]); });
it("falls back to the did when the handle will not resolve", async () => { const unresolvable = "did:plc:nohandle"; const ctx = bobbin({ "/xrpc/sh.tangled.repo.listCollaborators": { items: [] }, "/xrpc/sh.tangled.repo.listCollaboratorInvites": { items: [] } });
await expect(listCollaborators(ctx, { ownerDid: unresolvable, repoDid })).resolves.toEqual([ { did: unresolvable, handle: unresolvable, standing: "owner", since: undefined } ]); });
it("shows just the owner for a repo without a DID", async () => { const solo = "did:plc:solo"; const ctx = bobbin({ "/xrpc/blue.microcosm.identity.resolveMiniDoc": { did: solo, handle: "solo.test" } });
await expect(listCollaborators(ctx, { ownerDid: solo })).resolves.toEqual([ { did: solo, handle: "solo.test", standing: "owner", since: undefined } ]); });
it("keeps the roster when the knot has no invites endpoint", async () => { const ctx = bobbin({ "/xrpc/sh.tangled.repo.listCollaborators": { items: [ { subject: "did:plc:friend", addedBy: owner, createdAt: "a", effectiveSince: "b" } ] }, "/xrpc/blue.microcosm.identity.resolveMiniDoc": { did: "x", handle: "someone.test" } });
await expect( listCollaborators(ctx, { ownerDid: owner, repoDid }).then((rows) => rows.map((row) => row.standing) ) ).resolves.toEqual(["owner", "collaborator"]); });});