fix: update corrupted image test expectations from 422 to 400

validateImageBuffer catches corrupt image data before processing
reaches the tool handler, so the correct status code is 400 (bad
request) rather than 422 (processing failure). Also fix SVGZ
watermark validation by returning early for compressed SVG (Sharp
cannot read gzip-compressed SVGZ directly) and passing the actual
watermark filename to validateImageBuffer for correct format
detection.
This commit is contained in:
SnapOtter
2026-05-14 00:09:31 +08:00
parent 2f41629a14
commit cd24bb92b6
4 changed files with 18 additions and 12 deletions
+3 -2
View File
@@ -158,7 +158,7 @@ describe("Error handling", () => {
expect(result.error).toBeDefined();
});
it("returns 422 for corrupted image data", async () => {
it("returns 400 for corrupted image data", async () => {
const badBuffer = Buffer.from("not an image at all");
const { body: payload, contentType } = makeFilePayload(badBuffer, "bad.png", "image/png");
const res = await app.inject({
@@ -170,7 +170,8 @@ describe("Error handling", () => {
authorization: `Bearer ${adminToken}`,
},
});
expect(res.statusCode).toBe(422);
// validateImageBuffer catches corrupt data before processing
expect(res.statusCode).toBe(400);
});
});
+8 -7
View File
@@ -463,7 +463,7 @@ describe("Compare", () => {
// ── Branch coverage: multipart parse error (lines 35-39) ────────────
it("returns 422 when corrupt image data fails processing", async () => {
it("returns 400 when corrupt image data fails validation", async () => {
// Create a buffer that looks like an image but corrupts Sharp
const corruptBuffer = Buffer.from("not a real image content at all");
const { body, contentType } = createMultipartPayload([
@@ -481,10 +481,10 @@ describe("Compare", () => {
body,
});
// Should return 422 due to processing failure
expect(res.statusCode).toBe(422);
// validateImageBuffer catches corrupt data before processing
expect(res.statusCode).toBe(400);
const result = JSON.parse(res.body);
expect(result.error).toMatch(/comparison failed/i);
expect(result.error).toBeDefined();
});
// ── Branch coverage: 1x1 tiny images (line 117-121 area) ───────────
@@ -649,7 +649,7 @@ describe("Compare", () => {
// ── Branch coverage: both corrupt images fail processing ───────────
it("returns 422 when both images are corrupt", async () => {
it("returns 400 when both images are corrupt", async () => {
const corrupt1 = Buffer.from("this is not an image");
const corrupt2 = Buffer.from("neither is this one");
const { body, contentType } = createMultipartPayload([
@@ -667,9 +667,10 @@ describe("Compare", () => {
body,
});
expect(res.statusCode).toBe(422);
// validateImageBuffer catches corrupt data before processing
expect(res.statusCode).toBe(400);
const result = JSON.parse(res.body);
expect(result.error).toMatch(/comparison failed/i);
expect(result.error).toBeDefined();
});
// ── Branch coverage: HEIF content format input ─────────────────────