45 lines
1.9 KiB
TypeScript
45 lines
1.9 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
|
|
import { PlatformApiClient } from "./client";
|
|
import type { SourceRCONCommandRequest } from "./types";
|
|
|
|
describe("PlatformApiClient Source RCON command dispatch", () => {
|
|
afterEach(() => vi.unstubAllGlobals());
|
|
|
|
it("posts the typed server-scoped request and projects only safe queue state", async () => {
|
|
const request: SourceRCONCommandRequest = {
|
|
kind: "chat",
|
|
chatType: 4,
|
|
message: "Maintenance complete",
|
|
targetSteamId: "76561198000000001",
|
|
idempotencyKey: "web:source-rcon:chat:server-1:12"
|
|
};
|
|
const calls: Array<{ url: string; method: string; body?: unknown; authorization: string | null }> = [];
|
|
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,
|
|
authorization: new Headers(init?.headers).get("Authorization")
|
|
});
|
|
return new Response(JSON.stringify({ jobId: "job-source-rcon", serverInstanceId: "server-1", status: "queued", message: "SCUM RCON command queued" }), {
|
|
status: 202,
|
|
headers: { "Content-Type": "application/json" }
|
|
});
|
|
}));
|
|
|
|
const response = await new PlatformApiClient("/api/v1", () => "operator-session").sendSourceRCONCommand("server/1", request);
|
|
|
|
expect(calls).toEqual([{
|
|
url: "/api/v1/server-instances/server%2F1/rcon/commands",
|
|
method: "POST",
|
|
body: request,
|
|
authorization: "Bearer operator-session"
|
|
}]);
|
|
expect(response).toEqual({ jobId: "job-source-rcon", serverInstanceId: "server-1", status: "queued", message: "SCUM RCON command queued" });
|
|
for (const forbidden of ["command", "password", "host", "configRef", "response"]) {
|
|
expect(Object.keys(response)).not.toContain(forbidden);
|
|
}
|
|
});
|
|
});
|