mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-14 14:57:28 +00:00
Handle invalid JSON request bodies (#7)
This commit is contained in:
parent
850cf5ea44
commit
ad9f3a2a29
2 changed files with 31 additions and 1 deletions
|
|
@ -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" });
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue