42 lines
2.4 KiB
TypeScript
42 lines
2.4 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
|
|
import { PlatformApiClient } from "./client";
|
|
|
|
describe("PlatformApiClient production operations", () => {
|
|
afterEach(() => vi.unstubAllGlobals());
|
|
|
|
it("uses Platform-only governance 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, endpoints: [], totalMaxJobs: 0, totalRunningJobs: 0, totalQueuedJobs: 0, activeAlerts: 0, generatedAt: "2026-07-18T00:00:00Z", status: "queued", installation: {}, job: {}, decision: {}, alert: {} }), { status: 200, headers: { "Content-Type": "application/json" } });
|
|
}));
|
|
const client = new PlatformApiClient("/api/v1", () => "session-token");
|
|
|
|
await client.getProductionCapacity();
|
|
await client.listAlerts({ state: "active" });
|
|
await client.acknowledgeAlert("alert-1", "reviewed");
|
|
await client.resolveAlert("alert-1", "resolved");
|
|
await client.retryAlert("alert-1", "retry-1");
|
|
await client.listPluginLifecycles({ pluginId: "game.scum" });
|
|
await client.runPluginLifecycle("game.scum", { serverInstanceId: "server-1", operation: "upgrade", targetVersion: "1.2.0", idempotencyKey: "upgrade-1", confirmed: false });
|
|
await client.listAIConfigDiffs({ state: "pending" });
|
|
await client.approveAIConfigDiff("diff-1", "approve-1");
|
|
|
|
expect(calls.map((call) => `${call.method} ${call.url}`)).toEqual([
|
|
"GET /api/v1/production/capacity",
|
|
"GET /api/v1/alerts?state=active",
|
|
"POST /api/v1/alerts/alert-1/acknowledge",
|
|
"POST /api/v1/alerts/alert-1/resolve",
|
|
"POST /api/v1/alerts/alert-1/retry",
|
|
"GET /api/v1/plugin-lifecycles?pluginId=game.scum",
|
|
"POST /api/v1/plugin-lifecycles/game.scum/actions",
|
|
"GET /api/v1/ai/config-diffs?state=pending",
|
|
"POST /api/v1/ai/config-diffs/diff-1/approve"
|
|
]);
|
|
const serialized = JSON.stringify(calls);
|
|
expect(serialized).not.toMatch(/apiKey|token|secret|providerBaseUrl|runSocket|runEndpointUrl|hostPath|credential|dsn|rcon/i);
|
|
expect(calls[6]?.body).toEqual({ serverInstanceId: "server-1", operation: "upgrade", targetVersion: "1.2.0", idempotencyKey: "upgrade-1", confirmed: false });
|
|
});
|
|
});
|