test: cover 400 validation branches in request API

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jonathan
2026-07-10 16:51:24 +02:00
parent 15bb68bc49
commit fd9969ae17
+20
View File
@@ -25,6 +25,26 @@ describe("requests API", () => {
expect(res.status).toBe(400);
});
it("rejects a malformed JSON body", async () => {
const req = new Request("http://localhost/api/requests", {
method: "POST",
headers: { "content-type": "application/json" },
body: "{not json",
});
const res = await POST(req);
expect(res.status).toBe(400);
});
it("rejects an empty/whitespace-only artist", async () => {
const res = await POST(postReq({ artist: " ", album: "X" }));
expect(res.status).toBe(400);
});
it("rejects a non-string artist field", async () => {
const res = await POST(postReq({ artist: 123, album: "X" }));
expect(res.status).toBe(400);
});
it("lists requests newest first with job state", async () => {
await POST(postReq({ artist: "A", album: "1" }));
await POST(postReq({ artist: "B", album: "2" }));