Files
browser/plugins/tests/scum-feature-module.test.ts
T

31 lines
2.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { migratePlayerRecord, migrateTrajectoryRecord } from "../examples/scum-server-plugin/features/migration.js";
import { renderPluginPage } from "../examples/scum-server-plugin/page-bundle/index.js";
import { configurationCatalog, validateConfigPatch, validateStatePatch } from "../examples/scum-server-plugin/features/schemas.js";
describe("SCUM plugin feature module", () => {
it("owns the versioned configuration and state field catalogs", () => {
expect(configurationCatalog("0.9.700.90357").map((field) => field.key)).toContain("welcome-message");
expect(validateConfigPatch({ version: "0.9.700.90357", reason: "adjust capacity", idempotencyKey: "cfg-1", changes: [{ key: "max-players", value: "129" }] })).toContain("超出允许范围");
expect(validateStatePatch("0.9.700.90357", [{ fieldKey: "skills.running", before: 1, after: 2 }])).toBeNull();
expect(validateStatePatch("unknown", [{ fieldKey: "skills.running", before: 1, after: 2 }])).toContain("未受当前版本支持");
});
it("maps transitional records only as read-only provenance", () => {
expect(migratePlayerRecord({ id: "p-1", gamePlayerId: "steam-1", displayName: "Mira", updatedAt: "2026-07-29T00:00:00Z" })).toMatchObject({ provenance: "transitional-read-only", payload: { gamePlayerId: "steam-1" } });
expect(migrateTrajectoryRecord({ playerRecordId: "p-1", points: [{ recordedAt: "2026-07-29T00:00:00Z", mapX: 10, mapY: 20 }] })).toMatchObject({ provenance: "transitional-read-only", points: [{ x: 10, y: 20 }] });
});
it("renders plugin-owned configuration, player, reward, state, and trajectory panels with scoped permissions", () => {
const nodes: string[] = [];
const react = { createElement: (type: unknown, props: Record<string, unknown> | null, ...children: unknown[]) => { if (typeof type === "string") nodes.push(`${type}:${String(props?.["aria-label"] ?? "")}`); return { type, props, children }; } };
renderPluginPage(react, { context: { serverInstanceId: "server-1", permissions: ["server.game-client.read", "server.game-client.command", "server.game-client.maintenance"] }, availability: { available: true }, workspace: {} });
expect(nodes).toContain("section:SCUM 配置工作台");
expect(nodes).toContain("section:SCUM 玩家档案");
expect(nodes).toContain("section:SCUM 礼物与通知");
expect(nodes).toContain("section:SCUM 受控状态修改");
expect(nodes).toContain("section:SCUM 地图轨迹");
});
});