20 lines
727 B
TypeScript
20 lines
727 B
TypeScript
import { expect, spyOn, test } from "bun:test";
|
|
import { apiKeyRequest } from "../../command/ci";
|
|
|
|
test("CI requester supplies an API key without session authentication", async () => {
|
|
const fetch = spyOn(globalThis, "fetch").mockResolvedValue(
|
|
new Response(JSON.stringify({ ok: true }), { status: 200 }),
|
|
);
|
|
try {
|
|
await apiKeyRequest("ci-secret")("/workspaces/shop/resources/plan", {
|
|
headers: { "x-kuber-trust-project": "shop" },
|
|
});
|
|
const [, init] = fetch.mock.calls[0]!;
|
|
const headers = new Headers(init?.headers);
|
|
expect(headers.get("authorization")).toBe("Bearer ci-secret");
|
|
expect(headers.get("x-kuber-trust-project")).toBe("shop");
|
|
} finally {
|
|
fetch.mockRestore();
|
|
}
|
|
});
|