generated from nhcarrigan/template
fix: save character name correctly and show story on character sheet
- Load route syncs characterName from Player record so profile updates are reflected immediately on next load - Save route preserves Player record's characterName so auto-saves cannot overwrite profile updates - Public profile response now includes completedChapters - Character sheet panel displays completed story chapters with outcome - Removed stale CSS for old achievement/codex toast classes
This commit is contained in:
@@ -233,6 +233,16 @@ describe("game route", () => {
|
||||
expect(body.savedAt).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("falls back to state characterName when playerRecord is null", async () => {
|
||||
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce(null);
|
||||
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(null);
|
||||
vi.mocked(prisma.player.update).mockResolvedValueOnce({} as never);
|
||||
vi.mocked(prisma.gameState.upsert).mockResolvedValueOnce({} as never);
|
||||
const state = makeState();
|
||||
const res = await save({ state });
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
|
||||
it("validates and sanitizes state when previous record exists", async () => {
|
||||
const prevState = makeState({ resources: { gold: 0, essence: 0, crystals: 0, runestones: 0 } });
|
||||
const incomingState = makeState({ resources: { gold: 1e400, essence: 0, crystals: 0, runestones: 9999 } });
|
||||
|
||||
@@ -181,6 +181,24 @@ describe("profile route", () => {
|
||||
const unknown = body.unlockedTitles.find((t) => t.id === "unknown_title_id");
|
||||
expect(unknown?.name).toBe("unknown_title_id");
|
||||
});
|
||||
|
||||
it("includes completed story chapters in profile response", async () => {
|
||||
const state = makeState({
|
||||
story: {
|
||||
unlockedChapterIds: [ "boss_troll_king" ],
|
||||
completedChapters: [ { chapterId: "boss_troll_king", choiceId: "fight" } ],
|
||||
},
|
||||
});
|
||||
vi.mocked(prisma.player.findUnique).mockResolvedValueOnce(makePlayer() as never);
|
||||
vi.mocked(prisma.gameState.findUnique).mockResolvedValueOnce({ state } as never);
|
||||
const res = await app.fetch(new Request(`http://localhost/profile/${DISCORD_ID}`));
|
||||
expect(res.status).toBe(200);
|
||||
const body = await res.json() as {
|
||||
completedChapters: Array<{ chapterId: string; choiceId: string }>;
|
||||
};
|
||||
expect(body.completedChapters).toHaveLength(1);
|
||||
expect(body.completedChapters[0]).toMatchObject({ chapterId: "boss_troll_king", choiceId: "fight" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("PUT /", () => {
|
||||
|
||||
Reference in New Issue
Block a user