fix: improve error semantics, clarify answer key type

This commit is contained in:
lila 2026-04-28 16:07:19 +02:00
parent 6eaf282651
commit 648c5d2979
6 changed files with 62 additions and 34 deletions

View file

@ -111,12 +111,12 @@ describe("POST /api/v1/game/start", () => {
expect(body.success).toBe(false);
});
it("returns 404 when no terms are found for the given filters", async () => {
it("returns 422 when no terms are found for the given filters", async () => {
mockGetGameTerms.mockResolvedValue([]);
const res = await request(app).post("/api/v1/game/start").send(validBody);
const body = res.body as ErrorResponse;
expect(res.status).toBe(404);
expect(res.status).toBe(422);
expect(body.success).toBe(false);
});
@ -178,7 +178,7 @@ describe("POST /api/v1/game/answer", () => {
expect(body.error).toContain("Game session not found");
});
it("returns 404 when the question does not exist in the session", async () => {
it("returns 409 when the question does not exist in the session", async () => {
const startRes = await request(app)
.post("/api/v1/game/start")
.send(validBody);
@ -193,11 +193,11 @@ describe("POST /api/v1/game/answer", () => {
selectedOptionId: 0,
});
const body = res.body as ErrorResponse;
expect(res.status).toBe(404);
expect(res.status).toBe(409);
expect(body.success).toBe(false);
expect(body.error).toContain("Question not found");
expect(body.error).toContain("Question already answered");
});
it("returns 400 when a field has an invalid value", async () => {
const res = await request(app)
.post("/api/v1/game/start")