Files
2D6-Dungeon/src/rules/recovery.test.ts

83 lines
2.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { sampleContentPack } from "@/data/sampleContentPack";
import { createStartingAdventurer } from "./character";
import { createRunState, returnToTown } from "./runState";
import { getConsumableCounts, restWithRation, usePotion, useScroll } from "./recovery";
function createAdventurer() {
return createStartingAdventurer(sampleContentPack, {
name: "Aster",
weaponId: "weapon.short-sword",
armourId: "armour.leather-vest",
scrollId: "scroll.lesser-heal",
});
}
describe("recovery and consumables", () => {
it("uses a healing potion and restores hp", () => {
const run = createRunState({
content: sampleContentPack,
campaignId: "campaign.1",
adventurer: createAdventurer(),
});
run.adventurerSnapshot.hp.current = 6;
const result = usePotion({
content: sampleContentPack,
run,
definitionId: "potion.healing",
at: "2026-03-18T22:00:00.000Z",
});
expect(result.run.adventurerSnapshot.hp.current).toBe(9);
expect(getConsumableCounts(result.run).healingPotion).toBe(0);
expect(result.run.log.at(-1)?.text).toContain("recovered 3 HP");
});
it("casts a healing scroll and consumes it on success", () => {
const run = createRunState({
content: sampleContentPack,
campaignId: "campaign.1",
adventurer: createAdventurer(),
});
run.adventurerSnapshot.hp.current = 7;
const result = useScroll({
content: sampleContentPack,
run,
definitionId: "scroll.lesser-heal",
roller: () => 5,
at: "2026-03-18T22:05:00.000Z",
});
expect(result.run.adventurerSnapshot.hp.current).toBe(9);
expect(getConsumableCounts(result.run).lesserHealScroll).toBe(0);
expect(result.run.log.at(-1)?.text).toContain("roll 5");
});
it("uses a ration in town to recover hp and reduce rations", () => {
const run = createRunState({
content: sampleContentPack,
campaignId: "campaign.1",
adventurer: createAdventurer(),
});
run.adventurerSnapshot.hp.current = 5;
const inTown = returnToTown(run, "2026-03-18T22:10:00.000Z").run;
const result = restWithRation({
content: sampleContentPack,
run: inTown,
definitionId: "item.ration",
at: "2026-03-18T22:12:00.000Z",
});
expect(result.run.adventurerSnapshot.hp.current).toBe(7);
expect(result.run.adventurerSnapshot.inventory.rationCount).toBe(2);
expect(getConsumableCounts(result.run).ration).toBe(2);
});
});