fix: sanitise Zod validation error messages in game controller
This commit is contained in:
parent
c081e632cf
commit
6eaf282651
2 changed files with 13 additions and 2 deletions
|
|
@ -119,6 +119,17 @@ describe("POST /api/v1/game/start", () => {
|
|||
expect(res.status).toBe(404);
|
||||
expect(body.success).toBe(false);
|
||||
});
|
||||
|
||||
it("returns a sanitised error message when the body is invalid", 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.error).toBe("Invalid game settings");
|
||||
expect(body.error).not.toContain("Invalid literal value");
|
||||
expect(body.error).not.toContain("Invalid enum value");
|
||||
});
|
||||
});
|
||||
|
||||
describe("POST /api/v1/game/answer", () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue