Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657import { describe, expect, it, vi } from "vitest";import type { ResourceUri } from "@atcute/lexicons/syntax";import type { OAuthUserAgent } from "@atcute/oauth-browser-client";
vi.mock("$lib/auth/agent", () => ({ createClient: () => ({}), mintServiceAuth: async () => "token", serviceDidForHost: (host: string) => `did:web:${host}`, hostForServiceDid: () => null}));
const { addSecret, listSecrets, removeSecret } = await import("$lib/api/secrets");
const agent = { sub: "did:plc:owner" } as unknown as OAuthUserAgent;const repo = "at://did:plc:owner/sh.tangled.repo/core" as ResourceUri;
const spindle = (body: unknown) => { const fetch = vi.fn<typeof globalThis.fetch>( async () => new Response(JSON.stringify(body), { status: 200, headers: { "content-type": "application/json" } }) ); vi.stubGlobal("fetch", fetch); return fetch;};
describe("pipeline secrets", () => { it("asks the repo's spindle over https and tolerates a null list", async () => { const fetch = spindle({ secrets: null });
await expect(listSecrets(agent, "spindle.test", repo)).resolves.toEqual([]); const asked = new URL(String(fetch.mock.calls[0][0])); expect(new Headers(fetch.mock.calls[0][1]?.headers).get("authorization")).toBe( "Bearer token" ); expect(asked.origin).toBe("https://spindle.test"); expect(asked.pathname).toBe("/xrpc/sh.tangled.repo.listSecrets"); expect(asked.searchParams.get("repo")).toBe(repo); });
it("keys writes by the repo record uri", async () => { const fetch = spindle({});
await addSecret(agent, "https://spindle.test", repo, "API_KEY", "value"); expect(JSON.parse(String(fetch.mock.calls[0][1]?.body))).toEqual({ repo, key: "API_KEY", value: "value" });
await removeSecret(agent, "https://spindle.test", repo, "API_KEY"); expect(JSON.parse(String(fetch.mock.calls[1][1]?.body))).toEqual({ repo, key: "API_KEY" }); });});