Add campfireRest function with tests

This commit is contained in:
Jared Miller 2026-02-25 10:32:55 -05:00
parent febb05764b
commit 91d32a71ee
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
2 changed files with 19 additions and 0 deletions

View file

@ -23,6 +23,10 @@ export function endCombat(run, combatHp) {
return { ...run, hp, combatCount: run.combatCount + 1 };
}
export function campfireRest(run) {
return { ...run, hp: Math.min(run.hp + 3, run.maxHp) };
}
export function revealRewards(run) {
const count = Math.min(3, run.cardRewardsDeck.length);
const revealed = run.cardRewardsDeck.slice(0, count);

View file

@ -2,6 +2,7 @@ import { beforeAll, describe, expect, test } from "bun:test";
import { getAllCards, initCards } from "./cards.js";
import { initEnemies } from "./enemies.js";
import {
campfireRest,
createRunState,
endCombat,
pickReward,
@ -89,6 +90,20 @@ describe("endCombat", () => {
});
});
describe("campfireRest", () => {
test("campfireRest heals 3 HP", () => {
const run = { hp: 5, maxHp: 11 };
const result = campfireRest(run);
expect(result.hp).toBe(8);
});
test("campfireRest does not heal above maxHp", () => {
const run = { hp: 10, maxHp: 11 };
const result = campfireRest(run);
expect(result.hp).toBe(11);
});
});
describe("rewards", () => {
test("revealRewards removes 3 from rewards deck and returns them", () => {
const run = createRunState("ironclad");