95 lines
3.5 KiB
TypeScript
95 lines
3.5 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { BITE_SIZED_STOCKADES_DUNGEON_ID } from "../game/dungeonContentSource";
|
|
import type { DungeonRunProgress } from "../game/dungeonRunTypes";
|
|
import { canStartAnotherBiteSizedDungeon, startAnotherBiteSizedDungeon } from "./biteSizedDungeonRuntime";
|
|
import { useOnlineGroupStore } from "./onlineGroupStore";
|
|
import { useOnlineSessionStore } from "./onlineSessionStore";
|
|
import { useShellStore } from "./shellStore";
|
|
|
|
const progress: DungeonRunProgress = {
|
|
id: "completed-bite-sized-run",
|
|
dungeonId: BITE_SIZED_STOCKADES_DUNGEON_ID,
|
|
difficultyId: "normal",
|
|
bossDifficulty: 1,
|
|
startedAt: 1_000,
|
|
finishedAt: 9_000,
|
|
durationMs: 8_000,
|
|
timed: true,
|
|
killedBossIds: ["creature-84027"],
|
|
party: [{ name: "Tester", classId: "priest", level: 17, role: "healer", npc: false }],
|
|
};
|
|
|
|
const originalShell = useShellStore.getState();
|
|
const originalGroup = useOnlineGroupStore.getState();
|
|
const originalOnline = useOnlineSessionStore.getState();
|
|
|
|
beforeEach(() => {
|
|
useOnlineGroupStore.getState().reset();
|
|
useOnlineSessionStore.getState().reset();
|
|
});
|
|
|
|
afterEach(() => {
|
|
useShellStore.setState(originalShell, true);
|
|
useOnlineGroupStore.setState(originalGroup, true);
|
|
useOnlineSessionStore.setState(originalOnline, true);
|
|
});
|
|
|
|
describe("bite-sized replay", () => {
|
|
it("starts a fresh local run and treats the local player as party leader", async () => {
|
|
const enterDungeon = vi.fn(() => true);
|
|
const saveCheckpoint = vi.fn();
|
|
useShellStore.setState({
|
|
session: { kind: "offline", ownerId: "local-owner", displayName: "Tester" },
|
|
activeDungeonRole: "healer",
|
|
enterDungeon,
|
|
saveActiveDungeonRunCheckpoint: saveCheckpoint,
|
|
});
|
|
|
|
expect(canStartAnotherBiteSizedDungeon()).toBe(true);
|
|
await expect(startAnotherBiteSizedDungeon(progress)).resolves.toBe(true);
|
|
expect(saveCheckpoint).toHaveBeenCalledWith(null);
|
|
expect(enterDungeon).toHaveBeenCalledWith(BITE_SIZED_STOCKADES_DUNGEON_ID, "healer", {
|
|
difficultyId: "normal",
|
|
bossDifficulty: 1,
|
|
freshRun: true,
|
|
});
|
|
});
|
|
|
|
it("lets only the online group leader publish the next shared activity", async () => {
|
|
const startActivity = vi.fn(async () => true);
|
|
const saveCheckpoint = vi.fn();
|
|
const activity = {
|
|
id: "shared-bite-sized-run",
|
|
type: "dungeon" as const,
|
|
contentId: BITE_SIZED_STOCKADES_DUNGEON_ID,
|
|
fillWithAi: true,
|
|
partySize: 4,
|
|
startingLevel: null,
|
|
startedAt: 1_000,
|
|
};
|
|
useShellStore.setState({
|
|
session: { kind: "account", ownerId: "leader", displayName: "Leader", accessToken: "test-token" },
|
|
saveActiveDungeonRunCheckpoint: saveCheckpoint,
|
|
});
|
|
useOnlineGroupStore.setState({
|
|
startActivity,
|
|
snapshot: { invitations: [], group: { id: "group", leaderAccountId: "leader", members: [], activity,
|
|
activityRevision: 1, createdAt: 1, updatedAt: 1 } },
|
|
});
|
|
|
|
expect(canStartAnotherBiteSizedDungeon()).toBe(true);
|
|
await expect(startAnotherBiteSizedDungeon(progress)).resolves.toBe(true);
|
|
expect(startActivity).toHaveBeenCalledWith(expect.objectContaining({ ownerId: "leader" }), {
|
|
type: "dungeon",
|
|
contentId: BITE_SIZED_STOCKADES_DUNGEON_ID,
|
|
difficultyId: "normal",
|
|
bossDifficulty: 1,
|
|
partySize: 4,
|
|
});
|
|
expect(saveCheckpoint).toHaveBeenCalledWith(null);
|
|
|
|
useShellStore.setState({ session: { kind: "account", ownerId: "follower", displayName: "Follower", accessToken: "test-token" } });
|
|
expect(canStartAnotherBiteSizedDungeon()).toBe(false);
|
|
});
|
|
});
|