Files
2D6-Dungeon/src/rules/town.test.ts
T

75 lines
2.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { sampleContentPack } from "@/data/sampleContentPack";
import { createStartingAdventurer } from "./character";
import { createRunState } from "./runState";
import { queueTreasureForSale, sellPendingTreasure, sendTreasureToStash } from "./town";
function createAdventurer() {
return createStartingAdventurer(sampleContentPack, {
name: "Aster",
weaponId: "weapon.short-sword",
armourId: "armour.leather-vest",
scrollId: "scroll.lesser-heal",
});
}
describe("town flow", () => {
it("moves treasure from carried inventory into the stash", () => {
const run = createRunState({
content: sampleContentPack,
campaignId: "campaign.1",
adventurer: createAdventurer(),
});
run.adventurerSnapshot.inventory.carried.push({
definitionId: "item.silver-clasp",
quantity: 1,
});
const result = sendTreasureToStash(
sampleContentPack,
run,
"item.silver-clasp",
"2026-03-15T15:00:00.000Z",
);
expect(result.run.townState.stash).toEqual([
{ definitionId: "item.silver-clasp", quantity: 1 },
]);
expect(result.run.adventurerSnapshot.inventory.carried).not.toEqual(
expect.arrayContaining([expect.objectContaining({ definitionId: "item.silver-clasp" })]),
);
});
it("queues treasure and sells it for item value", () => {
const run = createRunState({
content: sampleContentPack,
campaignId: "campaign.1",
adventurer: createAdventurer(),
});
run.adventurerSnapshot.inventory.carried.push({
definitionId: "item.keeper-keyring",
quantity: 1,
});
const queued = queueTreasureForSale(
sampleContentPack,
run,
"item.keeper-keyring",
"2026-03-15T15:05:00.000Z",
).run;
const sold = sellPendingTreasure(
sampleContentPack,
queued,
"2026-03-15T15:06:00.000Z",
).run;
expect(sold.townState.pendingSales).toEqual([]);
expect(sold.adventurerSnapshot.inventory.currency.gold).toBe(5);
expect(sold.log.at(-1)?.text).toContain("for 5 gold");
});
});