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:
SnapOtter
2026-04-26 12:03:08 +08:00
parent dee9452c48
commit 733ebe8010
61 changed files with 12791 additions and 4 deletions
+171
View File
@@ -465,4 +465,175 @@ describe("image-to-base64", () => {
expect(json.results[0].width).toBeLessThanOrEqual(50);
expect(json.results[0].height).toBeLessThanOrEqual(50);
});
// ── Branch coverage: line 83 (ignored invalid settings JSON) ──────
it("ignores invalid settings JSON (uses defaults)", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{ name: "settings", content: "not-json-at-all" },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/image-to-base64",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
// The route silently ignores invalid JSON and uses defaults
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.results).toHaveLength(1);
expect(json.results[0].mimeType).toContain("image/");
});
// ── Branch coverage: lines 149-150 (default case in outputFormat switch) ──
it("handles unknown outputFormat falling through to default", async () => {
// Testing the "original" path with a non-HEIC, non-SVG format and no resize
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.jpg", contentType: "image/jpeg", content: JPG },
{ name: "settings", content: JSON.stringify({ outputFormat: "original" }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/image-to-base64",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.results[0].mimeType).toBe("image/jpeg");
});
// ── Branch coverage: line 180 (overheadPercent = 0 for empty) ─────
it("handles 1x1 tiny image", async () => {
const TINY = readFileSync(join(FIXTURES, "test-1x1.png"));
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "tiny.png", contentType: "image/png", content: TINY },
{ name: "settings", content: JSON.stringify({}) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/image-to-base64",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.results[0].width).toBe(1);
expect(json.results[0].height).toBe(1);
expect(typeof json.results[0].overheadPercent).toBe("number");
});
// ── HEIC with resize ──────────────────────────────────────────────
it("converts HEIC to JPEG with resize applied", async () => {
const HEIC = readFileSync(join(FIXTURES, "test-200x150.heic"));
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "photo.heic", contentType: "image/heic", content: HEIC },
{ name: "settings", content: JSON.stringify({ maxWidth: 50 }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/image-to-base64",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.results[0].mimeType).toBe("image/jpeg");
expect(json.results[0].width).toBeLessThanOrEqual(50);
});
// ── HEIC with explicit format conversion ──────────────────────────
it("converts HEIC to PNG when outputFormat is png", async () => {
const HEIC = readFileSync(join(FIXTURES, "test-200x150.heic"));
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "photo.heic", contentType: "image/heic", content: HEIC },
{ name: "settings", content: JSON.stringify({ outputFormat: "png" }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/image-to-base64",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.results[0].mimeType).toBe("image/png");
});
// ── Original format with resize (no format conversion) ────────────
it("preserves original format when only resize is requested", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{ name: "settings", content: JSON.stringify({ maxWidth: 100 }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/image-to-base64",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.results[0].mimeType).toContain("image/");
expect(json.results[0].width).toBeLessThanOrEqual(100);
});
// ── Large stress file ─────────────────────────────────────────────
it("converts stress-large.jpg to base64", 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: "settings", content: JSON.stringify({ maxWidth: 200 }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/image-to-base64",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.results[0].base64.length).toBeGreaterThan(0);
expect(json.results[0].width).toBeLessThanOrEqual(200);
});
// ── No settings at all ────────────────────────────────────────────
it("works when no settings field is provided at all", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/image-to-base64",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.results).toHaveLength(1);
});
});