generated from nhcarrigan/template
fix: unlock exploration areas on zone unlock, correct quest_eternal count, fix quest status filter in timers
This commit is contained in:
@@ -294,6 +294,52 @@ describe("boss route", () => {
|
||||
expect(body.won).toBe(true);
|
||||
});
|
||||
|
||||
it("handles zone unlock gracefully when exploration state is undefined", async () => {
|
||||
const state = makeState({
|
||||
bosses: [makeBoss({ currentHp: 100, maxHp: 100, damagePerSecond: 1 })] as GameState["bosses"],
|
||||
adventurers: [makeAdventurer()] as GameState["adventurers"],
|
||||
zones: [{ id: "test_zone", status: "locked", unlockBossId: "test_boss", unlockQuestId: null }] as GameState["zones"],
|
||||
quests: [],
|
||||
exploration: undefined,
|
||||
});
|
||||
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
|
||||
vi.mocked(prisma.gameState.update).mockResolvedValueOnce({} as never);
|
||||
const res = await challenge({ bossId: "test_boss" });
|
||||
expect(res.status).toBe(200);
|
||||
const body = await res.json() as { won: boolean };
|
||||
expect(body.won).toBe(true);
|
||||
});
|
||||
|
||||
it("unlocks exploration areas when a zone is unlocked on boss defeat", async () => {
|
||||
const state = makeState({
|
||||
bosses: [makeBoss({ currentHp: 100, maxHp: 100, damagePerSecond: 1 })] as GameState["bosses"],
|
||||
adventurers: [makeAdventurer()] as GameState["adventurers"],
|
||||
zones: [{ id: "test_zone", status: "locked", unlockBossId: "test_boss", unlockQuestId: null }] as GameState["zones"],
|
||||
quests: [],
|
||||
exploration: {
|
||||
areas: [{ id: "test_area", status: "locked" as const }],
|
||||
materials: [],
|
||||
craftedRecipeIds: [],
|
||||
craftedGoldMultiplier: 1,
|
||||
craftedEssenceMultiplier: 1,
|
||||
craftedClickMultiplier: 1,
|
||||
craftedCombatMultiplier: 1,
|
||||
},
|
||||
});
|
||||
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
|
||||
let savedState: GameState | undefined;
|
||||
vi.mocked(prisma.gameState.update).mockImplementationOnce(async (args) => {
|
||||
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Test assertion */
|
||||
savedState = (args as { data: { state: GameState } }).data.state;
|
||||
return {} as never;
|
||||
});
|
||||
const res = await challenge({ bossId: "test_boss" });
|
||||
expect(res.status).toBe(200);
|
||||
// Exploration area should remain locked — no matching defaultExploration for "test_area"
|
||||
const area = savedState?.exploration?.areas.find((a) => a.id === "test_area");
|
||||
expect(area?.status).toBe("locked");
|
||||
});
|
||||
|
||||
it("returns 500 when the database throws", async () => {
|
||||
vi.mocked(prisma.gameState.findUnique).mockRejectedValueOnce(new Error("DB error"));
|
||||
const res = await challenge({ bossId: "test_boss" });
|
||||
|
||||
Reference in New Issue
Block a user