forked from Lilly-Protocol/lily-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmalformed-json.test.ts
More file actions
30 lines (24 loc) · 988 Bytes
/
Copy pathmalformed-json.test.ts
File metadata and controls
30 lines (24 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import request from "supertest";
import { describe, expect, it } from "vitest";
import { createApp } from "../src/app";
describe("malformed JSON body handling", () => {
const app = createApp();
it("returns 400 with success false for invalid JSON syntax", async () => {
const response = await request(app)
.post("/api/v1/agents")
.set("Content-Type", "application/json")
.send("{invalid json");
expect(response.status).toBe(400);
expect(response.body.success).toBe(false);
expect(response.body.message).toBeDefined();
});
it("returns 400 for empty body with application/json content-type", async () => {
const response = await request(app)
.post("/api/v1/agents")
.set("Content-Type", "application/json")
.send("");
// Express json parser treats empty body as valid (undefined), so this may be 400 or pass to validation.
// We assert it does not return 500.
expect(response.status).not.toBe(500);
});
});