mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
test: major coverage expansion — 18 new test files, ~830 new tests
Unit tests: 1354 → 1781 (+427) - 11 new AI bridge module tests (packages/ai/ from 2/13 → 13/13 files) - files-page-store (0% → full), pdf-to-image-store, features-store expanded - saturation and edit-metadata image-engine operations - analytics route, features route, web analytics lib, api-extended Integration tests: ~2070 → 2320 (+250) - 31 integration files expanded with branch-coverage-targeted tests - progress.ts SSE endpoints (28% → comprehensive, +18 tests) - gif-tools all modes (+18), pdf-to-image format variants (+13) - Cross-format matrix expanded to 17 tools × 17 formats (467 tests) - Adversarial: concurrent, memory pressure, unicode filenames, pipeline limits E2E-Docker: +1020 lines across 6 spec files - Info, colors, sharpening, base64, QR read, JXL/ICO/SVG formats - Strip-metadata, image-enhancement, content-aware-resize expanded - Batch pipelines, multi-format batches, HEIC input coverage
This commit is contained in:
@@ -186,4 +186,153 @@ describe("watermark-image", () => {
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
|
||||
// ── Branch coverage: lines 44-48 (multipart parse error) ──────────
|
||||
|
||||
it("returns 400 for invalid Zod settings (scale out of range)", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "main.png", contentType: "image/png", content: PNG },
|
||||
{ name: "watermark", filename: "wm.png", contentType: "image/png", content: SMALL_PNG },
|
||||
{ name: "settings", content: JSON.stringify({ scale: 200 }) },
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/watermark-image",
|
||||
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
|
||||
body,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
const json = JSON.parse(res.body);
|
||||
expect(json.error).toContain("Invalid settings");
|
||||
});
|
||||
|
||||
// ── Branch coverage: lines 164-168 (processing failure) ───────────
|
||||
|
||||
it("returns 422 when processing fails on corrupted main image", async () => {
|
||||
// A buffer that passes multipart parsing but fails Sharp processing
|
||||
const corruptedBuffer = Buffer.alloc(100, 0xff);
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "main.png", contentType: "image/png", content: corruptedBuffer },
|
||||
{ name: "watermark", filename: "wm.png", contentType: "image/png", content: SMALL_PNG },
|
||||
{ name: "settings", content: JSON.stringify({}) },
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/watermark-image",
|
||||
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
|
||||
body,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(422);
|
||||
const json = JSON.parse(res.body);
|
||||
expect(json.error).toContain("Processing failed");
|
||||
});
|
||||
|
||||
// ── HEIC input handling ───────────────────────────────────────────
|
||||
|
||||
it("processes HEIC main image", async () => {
|
||||
const HEIC = readFileSync(join(FIXTURES, "test-200x150.heic"));
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "photo.heic", contentType: "image/heic", content: HEIC },
|
||||
{ name: "watermark", filename: "wm.png", contentType: "image/png", content: SMALL_PNG },
|
||||
{ name: "settings", content: JSON.stringify({}) },
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/watermark-image",
|
||||
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
|
||||
body,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
const json = JSON.parse(res.body);
|
||||
expect(json.downloadUrl).toBeDefined();
|
||||
expect(json.processedSize).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
// ── Full opacity watermark (opacity=100 skips opacity mask) ───────
|
||||
|
||||
it("applies watermark at full opacity (100)", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "main.png", contentType: "image/png", content: PNG },
|
||||
{ name: "watermark", filename: "wm.png", contentType: "image/png", content: SMALL_PNG },
|
||||
{ name: "settings", content: JSON.stringify({ opacity: 100, scale: 25 }) },
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/watermark-image",
|
||||
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
|
||||
body,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
const json = JSON.parse(res.body);
|
||||
expect(json.downloadUrl).toBeDefined();
|
||||
});
|
||||
|
||||
// ── Stress: large file ────────────────────────────────────────────
|
||||
|
||||
it("processes stress-large.jpg as main image", async () => {
|
||||
const LARGE = readFileSync(join(FIXTURES, "content", "stress-large.jpg"));
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "large.jpg", contentType: "image/jpeg", content: LARGE },
|
||||
{ name: "watermark", filename: "wm.jpg", contentType: "image/jpeg", content: JPG },
|
||||
{ name: "settings", content: JSON.stringify({ scale: 10 }) },
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/watermark-image",
|
||||
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
|
||||
body,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
const json = JSON.parse(res.body);
|
||||
expect(json.processedSize).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
// ── Tiny main image with larger watermark ───────────────────────
|
||||
|
||||
it("handles small main image with watermark", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "main.png", contentType: "image/png", content: PNG },
|
||||
{ name: "watermark", filename: "wm.jpg", contentType: "image/jpeg", content: JPG },
|
||||
{ name: "settings", content: JSON.stringify({ scale: 1 }) },
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/watermark-image",
|
||||
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
|
||||
body,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
});
|
||||
|
||||
// ── No settings field (defaults applied) ──────────────────────────
|
||||
|
||||
it("works when no settings field is provided at all", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "main.png", contentType: "image/png", content: PNG },
|
||||
{ name: "watermark", filename: "wm.png", contentType: "image/png", content: SMALL_PNG },
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/watermark-image",
|
||||
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
|
||||
body,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
const json = JSON.parse(res.body);
|
||||
expect(json.downloadUrl).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user