72 lines
2.1 KiB
TypeScript
72 lines
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { sampleContentPack } from "@/data/sampleContentPack";
|
|
|
|
import { createStartingAdventurer } from "./character";
|
|
import { createRunState, returnToTown } from "./runState";
|
|
import { useTownService } from "./townServices";
|
|
|
|
function createAdventurer() {
|
|
return createStartingAdventurer(sampleContentPack, {
|
|
name: "Aster",
|
|
weaponId: "weapon.short-sword",
|
|
armourId: "armour.leather-vest",
|
|
scrollId: "scroll.lesser-heal",
|
|
});
|
|
}
|
|
|
|
describe("town services", () => {
|
|
it("heals the adventurer to full at the healer", () => {
|
|
const run = createRunState({
|
|
content: sampleContentPack,
|
|
campaignId: "campaign.1",
|
|
adventurer: createAdventurer(),
|
|
});
|
|
|
|
run.adventurerSnapshot.hp.current = 3;
|
|
run.adventurerSnapshot.inventory.currency.gold = 3;
|
|
|
|
const inTown = returnToTown(run, "2026-03-18T21:00:00.000Z").run;
|
|
const result = useTownService({
|
|
content: sampleContentPack,
|
|
run: inTown,
|
|
serviceId: "service.healer",
|
|
at: "2026-03-18T21:05:00.000Z",
|
|
});
|
|
|
|
expect(result.run.adventurerSnapshot.hp.current).toBe(
|
|
result.run.adventurerSnapshot.hp.max,
|
|
);
|
|
expect(result.run.adventurerSnapshot.inventory.currency.gold).toBe(1);
|
|
expect(result.run.log.at(-1)?.text).toContain("restored the party to full health");
|
|
});
|
|
|
|
it("buys a ration at the market", () => {
|
|
const run = createRunState({
|
|
content: sampleContentPack,
|
|
campaignId: "campaign.1",
|
|
adventurer: createAdventurer(),
|
|
});
|
|
|
|
run.adventurerSnapshot.inventory.currency.gold = 2;
|
|
|
|
const inTown = returnToTown(run).run;
|
|
const result = useTownService({
|
|
content: sampleContentPack,
|
|
run: inTown,
|
|
serviceId: "service.market",
|
|
});
|
|
|
|
expect(result.run.adventurerSnapshot.inventory.currency.gold).toBe(1);
|
|
expect(result.run.adventurerSnapshot.inventory.rationCount).toBe(4);
|
|
expect(result.run.adventurerSnapshot.inventory.carried).toEqual(
|
|
expect.arrayContaining([
|
|
expect.objectContaining({
|
|
definitionId: "item.ration",
|
|
quantity: 4,
|
|
}),
|
|
]),
|
|
);
|
|
});
|
|
});
|