67 lines
2.2 KiB
TypeScript
67 lines
2.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { buildRconCommandHistory, normalizeRconHistoryFilters } from "./rcon-command-history";
|
|
|
|
const correlationId = "11111111-1111-4111-8111-111111111111";
|
|
|
|
function event(overrides: Record<string, unknown> = {}) {
|
|
return {
|
|
id: "22222222-2222-4222-8222-222222222222",
|
|
time: new Date("2026-08-14T01:00:00Z"),
|
|
correlationId,
|
|
data: {
|
|
command: "say hello operators",
|
|
serverId: "33333333-3333-4333-8333-333333333333",
|
|
name: "Season 4",
|
|
adminEmail: "admin@example.test",
|
|
adminName: "Admin",
|
|
},
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("RCON command history", () => {
|
|
it("normalizes bounded search filters and accepts only known servers", () => {
|
|
expect(normalizeRconHistoryFilters({
|
|
command: [" say hello ", "ignored"],
|
|
admin: " admin@example.test ",
|
|
server: "33333333-3333-4333-8333-333333333333",
|
|
}, ["33333333-3333-4333-8333-333333333333"])).toEqual({
|
|
command: "say hello",
|
|
admin: "admin@example.test",
|
|
serverId: "33333333-3333-4333-8333-333333333333",
|
|
});
|
|
|
|
expect(normalizeRconHistoryFilters({ server: "unknown" }, [])).toEqual({
|
|
command: "",
|
|
admin: "",
|
|
serverId: "",
|
|
});
|
|
});
|
|
|
|
it("pairs requested commands with their completion outcome without exposing responses", () => {
|
|
const requested = event();
|
|
const completed = event({
|
|
id: "44444444-4444-4444-8444-444444444444",
|
|
data: { success: false, reason: "timeout", durationMs: 5001 },
|
|
});
|
|
|
|
expect(buildRconCommandHistory([requested], [completed])).toEqual([{
|
|
eventId: requested.id,
|
|
time: requested.time,
|
|
command: "say hello operators",
|
|
serverId: "33333333-3333-4333-8333-333333333333",
|
|
serverName: "Season 4",
|
|
adminEmail: "admin@example.test",
|
|
adminName: "Admin",
|
|
status: "failed",
|
|
reason: "timeout",
|
|
durationMs: 5001,
|
|
}]);
|
|
expect(JSON.stringify(buildRconCommandHistory([requested], [completed]))).not.toContain("response");
|
|
});
|
|
|
|
it("marks a requested command pending when no completion event exists", () => {
|
|
expect(buildRconCommandHistory([event()], [event({ correlationId: null })])[0]?.status).toBe("pending");
|
|
});
|
|
});
|