Handle invalid JSON request bodies (#7)

This commit is contained in:
phucnguyen1707 2026-06-12 11:00:38 +07:00 committed by GitHub
parent 850cf5ea44
commit ad9f3a2a29
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 1 deletions

View file

@ -181,4 +181,16 @@ describe("CommandBoard API contracts", () => {
expect(response.status).toBe(422);
expect(Array.isArray(body.errors)).toBe(true);
});
it("rejects malformed JSON request bodies as client errors", async () => {
const response = await fetch(`${baseUrl}/api/tasks`, {
method: "POST",
headers: { "content-type": "application/json" },
body: "{bad"
});
const body = await response.json() as { error: string };
expect(response.status).toBe(400);
expect(body).toEqual({ error: "Invalid JSON body" });
});
});