Files
healer-man/src/game/dungeonRunCheckpoint.test.ts
T
2026-09-09 11:21:33 -04:00

57 lines
1.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { createDungeonEncounterSnapshot } from "./dungeonEncounterRuntime";
import type { DungeonEncounterDefinition } from "./dungeonEncounterTypes";
import {
DUNGEON_RUN_CHECKPOINT_VERSION,
normalizeDungeonRunCheckpoint,
} from "./dungeonRunCheckpoint";
const definition: DungeonEncounterDefinition = {
id: "test:boss",
dungeonId: "test",
initialPhase: "ready",
rules: [],
};
describe("dungeon run checkpoints", () => {
it("normalizes JSON-safe encounter progress and world spawn", () => {
const result = normalizeDungeonRunCheckpoint({
version: DUNGEON_RUN_CHECKPOINT_VERSION,
dungeonId: "test",
difficultyId: "normal",
checkpointId: "entrance",
spawn: { footPosition: [1, 2, 3], yaw: 0.5 },
encounters: [createDungeonEncounterSnapshot(definition)],
savedAt: 123,
});
expect(result).toMatchObject({ dungeonId: "test", checkpointId: "entrance" });
expect(result?.encounters[0]?.encounterId).toBe("test:boss");
});
it("fails closed on malformed or unbounded data", () => {
expect(normalizeDungeonRunCheckpoint({})).toBeNull();
expect(normalizeDungeonRunCheckpoint({
version: DUNGEON_RUN_CHECKPOINT_VERSION,
dungeonId: "test",
difficultyId: "normal",
checkpointId: null,
spawn: { footPosition: [Number.NaN, 2, 3], yaw: 0 },
encounters: [],
savedAt: 1,
})).toBeNull();
});
it("fails closed on legacy checkpoints whose sorted action history cannot be reconstructed", () => {
const currentSnapshot = createDungeonEncounterSnapshot(definition);
expect(normalizeDungeonRunCheckpoint({
version: 1,
dungeonId: "test",
difficultyId: "normal",
checkpointId: null,
spawn: { footPosition: [1, 2, 3], yaw: 0 },
encounters: [{ ...currentSnapshot, schemaVersion: 1 }],
savedAt: 1,
})).toBeNull();
});
});