fix: change GAME_ROUNDS from strings to numbers

This commit is contained in:
lila 2026-04-28 12:29:46 +02:00
parent 7d3c456efe
commit 02ccc88d24
8 changed files with 181 additions and 14 deletions

View file

@ -60,7 +60,7 @@ const validBody = {
target_language: "it",
pos: "noun",
difficulty: "easy",
rounds: "3",
rounds: 3,
};
const fakeTerms = [
@ -177,4 +177,22 @@ describe("POST /api/v1/game/answer", () => {
expect(body.success).toBe(false);
expect(body.error).toContain("Question not found");
});
it("returns 400 when a field has an invalid value", async () => {
const res = await request(app)
.post("/api/v1/game/start")
.send({ ...validBody, difficulty: "impossible" });
const body = res.body as ErrorResponse;
expect(res.status).toBe(400);
expect(body.success).toBe(false);
});
it("returns 400 when rounds has an invalid value", async () => {
const res = await request(app)
.post("/api/v1/game/start")
.send({ ...validBody, rounds: "invalid" });
const body = res.body as ErrorResponse;
expect(res.status).toBe(400);
expect(body.success).toBe(false);
});
});

View file

@ -14,7 +14,7 @@ const validRequest: GameRequest = {
target_language: "it",
pos: "noun",
difficulty: "easy",
rounds: "3",
rounds: 3,
};
const fakeTerms = [

View file

@ -21,7 +21,7 @@ export const createGameSession = async (
request.target_language,
request.pos,
request.difficulty,
Number(request.rounds),
request.rounds,
);
const answerKey = new Map<string, number>();