28 lines
1.6 KiB
TypeScript
28 lines
1.6 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
|
|
import { PlatformApiClient } from "./client";
|
|
|
|
describe("PlatformApiClient plugin operations", () => {
|
|
afterEach(() => vi.unstubAllGlobals());
|
|
|
|
it("uses Platform-only operations routes and bounded request bodies", async () => {
|
|
const calls: Array<{ url: string; method: string; body?: unknown }> = [];
|
|
vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
calls.push({ url: String(input), method: init?.method ?? "GET", body: init?.body ? JSON.parse(String(init.body)) : undefined });
|
|
return new Response(JSON.stringify({ items: [], count: 0, status: "queued", installation: {}, job: {} }), { status: 200, headers: { "Content-Type": "application/json" } });
|
|
}));
|
|
const client = new PlatformApiClient("/api/v1", () => "session-token");
|
|
|
|
await client.listPluginLifecycles({ pluginId: "game.scum" });
|
|
await client.runPluginLifecycle("game.scum", { serverInstanceId: "server-1", operation: "upgrade", targetVersion: "1.2.0", idempotencyKey: "upgrade-1" });
|
|
|
|
expect(calls.map((call) => `${call.method} ${call.url}`)).toEqual([
|
|
"GET /api/v1/plugin-lifecycles?pluginId=game.scum",
|
|
"POST /api/v1/plugin-lifecycles/game.scum/actions"
|
|
]);
|
|
const serialized = JSON.stringify(calls);
|
|
expect(serialized).not.toMatch(/apiKey|token|secret|providerBaseUrl|runSocket|runEndpointUrl|hostPath|credential|dsn|rcon/i);
|
|
expect(calls[1]?.body).toEqual({ serverInstanceId: "server-1", operation: "upgrade", targetVersion: "1.2.0", idempotencyKey: "upgrade-1" });
|
|
});
|
|
});
|