57 lines
3.0 KiB
TypeScript
57 lines
3.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import type { GameClientBridgeJsonObject, GameClientBridgeSnapshotResponse } from "../api/types";
|
|
import { projectScumOperationsSnapshots } from "./scumOperations";
|
|
|
|
const now = "2026-07-20T08:00:00Z";
|
|
|
|
function snapshot(type: string, payload: GameClientBridgeJsonObject, sequence = 1): GameClientBridgeSnapshotResponse {
|
|
return {
|
|
id: `${type}-${sequence}`,
|
|
serverInstanceId: "server-1",
|
|
pluginId: "game.scum",
|
|
profileKey: "scum-client",
|
|
type,
|
|
schemaVersion: "1",
|
|
streamKey: "current",
|
|
sequence,
|
|
observedAt: now,
|
|
payload,
|
|
retention: { keepForSeconds: 3600, maxRecords: 24 },
|
|
createdAt: now,
|
|
expiresAt: "2026-07-20T09:00:00Z"
|
|
};
|
|
}
|
|
|
|
describe("SCUM operations snapshot projection", () => {
|
|
it("projects companion, player, session, squad, vehicle and flag snapshots", () => {
|
|
const view = projectScumOperationsSnapshots([
|
|
snapshot("companion.health", { status: "online", version: "1.2.0", observedAt: now, latencyMs: 24, capabilities: ["game-client.bridge"] }),
|
|
snapshot("online.sessions", { observedAt: now, onlineCount: 1, sessions: [{ sessionId: "game-session-1", playerName: "Moonlight", startedAt: now }] }),
|
|
snapshot("players", { observedAt: now, players: [{ playerId: "player-1", playerName: "Moonlight", status: "online", squadId: "squad-1", pingMs: 33 }] }),
|
|
snapshot("squads", { observedAt: now, squads: [{ squadId: "squad-1", name: "Lunar", memberCount: 4, leaderPlayerId: "player-1" }] }),
|
|
snapshot("vehicles", { observedAt: now, vehicles: [{ vehicleId: "vehicle-1", vehicleType: "truck", status: "parked", ownerPlayerId: "player-1", fuelPercent: 70, healthPercent: 80 }] }),
|
|
snapshot("flags", { observedAt: now, flags: [{ flagId: "flag-1", status: "active", squadId: "squad-1", radiusMeters: 25 }] })
|
|
]);
|
|
|
|
expect(view).toMatchObject({
|
|
health: { status: "online", version: "1.2.0", latencyMs: 24 },
|
|
sessions: { total: 1, items: [{ sessionId: "game-session-1" }] },
|
|
players: { total: 1, items: [{ playerId: "player-1", squadId: "squad-1" }] },
|
|
squads: { total: 1, items: [{ memberCount: 4 }] },
|
|
vehicles: { total: 1, items: [{ fuelPercent: 70 }] },
|
|
flags: { total: 1, items: [{ radiusMeters: 25 }] }
|
|
});
|
|
});
|
|
|
|
it("uses the newest sequence and redacts sensitive-looking display strings", () => {
|
|
const view = projectScumOperationsSnapshots([
|
|
snapshot("players", { observedAt: now, players: [{ playerId: "player-old", playerName: "Old", status: "offline" }] }, 1),
|
|
{ ...snapshot("players", { observedAt: now, players: [{ playerId: "player-new", playerName: "token=raw-secret /Users/operator/file", status: "online" }] }, 2), observedAt: now }
|
|
]);
|
|
expect(view.players.items[0]).toMatchObject({ playerId: "player-new", status: "online" });
|
|
expect(view.players.items[0]?.playerName).not.toContain("raw-secret");
|
|
expect(view.players.items[0]?.playerName).not.toContain("/Users/");
|
|
});
|
|
});
|