Files
org_web/tests/archive-world-systems.test.cjs
gitea-actions c06af38d80
All checks were successful
Build Org Website / build (push) Successful in 39s
Harden archive-world setup and refresh site links
2026-07-30 09:08:12 +01:00

86 lines
3.9 KiB
JavaScript
Executable File

const test = require("node:test");
const assert = require("node:assert/strict");
const data = require("../assets/scripts/pages/archive-world-data.js");
const state = require("../assets/scripts/pages/archive-world-state.js");
const systems = require("../assets/scripts/pages/archive-world-systems.js");
test("movement normalization prevents faster diagonals", () => {
const straight = systems.normalizedVector(1, 0, 175);
const diagonal = systems.normalizedVector(1, 1, 175);
assert.equal(Math.round(Math.hypot(straight.x, straight.y)), 175);
assert.equal(Math.round(Math.hypot(diagonal.x, diagonal.y)), 175);
});
test("landmark discoveries deduplicate and complete at eight", () => {
let current = state.fresh("Ada", "brass");
current = systems.discover(current, "gate");
current = systems.discover(current, "gate");
assert.deepEqual(current.discovered, ["gate"]);
data.LANDMARK_IDS.forEach((id) => { current = systems.discover(current, id); });
assert.equal(current.complete, true);
});
test("quest progression and completion grant each reward once", () => {
let current = state.fresh("Ada", "brass");
current = systems.startQuest(current, "gate");
assert.equal(current.quests.gate.status, "active");
current = systems.completeQuest(current, "gate");
const xp = current.xp;
assert.equal(current.quests.gate.status, "complete");
assert.deepEqual(current.sigils, ["gate"]);
assert.equal(current.inventory.some((item) => item.id === "lantern"), true);
current = systems.completeQuest(current, "gate");
assert.equal(current.xp, xp);
assert.deepEqual(current.sigils, ["gate"]);
});
test("inventory collection caps stacks and consumables heal", () => {
let current = state.fresh("Ada", "brass");
current = systems.addItem(current, "ink_vial", 30);
assert.equal(systems.itemQuantity(current, "ink_vial"), 9);
current.health = 30;
const used = systems.consumeItem(current, "ink_vial");
assert.equal(used.used, true);
assert.equal(used.state.health, 65);
assert.equal(systems.itemQuantity(used.state, "ink_vial"), 8);
});
test("damage respects invulnerability and assist, defeat preserves progress", () => {
let current = state.fresh("Ada", "brass");
current.sigils = ["gate"];
const assisted = state.normalize({ ...current, settings: { ...current.settings, assist: true } });
const first = systems.takeDamage(assisted, 20, 2000, 0);
assert.equal(first.state.health, 90);
const ignored = systems.takeDamage(first.state, 20, 2200, 2000);
assert.equal(ignored.hit, false);
const defeated = systems.takeDamage({ ...first.state, health: 5, settings: { ...first.state.settings, assist: false } }, 20, 5000, 0);
assert.equal(defeated.defeated, true);
const respawned = systems.respawn(defeated.state);
assert.deepEqual(respawned.sigils, ["gate"]);
assert.equal(respawned.health >= 50, true);
});
test("XP levels, boss completion and sigil story stage restore correctly", () => {
let current = state.fresh("Ada", "brass");
current = systems.grantXp(current, 200);
assert.equal(current.level, 3);
assert.equal(current.maxHealth, 120);
current = systems.recordBoss(current, "sentinel");
assert.equal(current.defeatedBosses.includes("sentinel"), true);
assert.equal(current.quests.workshop.status, "complete");
data.LANDMARK_IDS.forEach((id) => {
if (!current.sigils.includes(id)) current = systems.completeQuest(current, id);
});
assert.equal(current.sigils.length, 8);
assert.equal(current.story.stage, "vault");
current = systems.recordBoss(current, "redactor");
assert.equal(current.story.stage, "postgame");
});
test("invalid collision positions resolve to a named safe spawn", () => {
assert.equal(systems.isSafe("town", 200, 150), false);
const safe = systems.nearestSafeSpawn("town", 200, 150);
assert.equal(systems.isSafe(safe.area, safe.x, safe.y), true);
assert.ok(["gate", "square", "library", "study", "inn", "workshop", "playroom", "museum", "garden"].includes(safe.spawn));
});