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:
@@ -412,4 +412,160 @@ describe("Error handling", () => {
|
||||
});
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
|
||||
it("returns 400 for invalid settings JSON", async () => {
|
||||
const { body: payload, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "test.jpg", contentType: "image/jpeg", content: EXIF_JPG },
|
||||
{ name: "settings", content: "not-json" },
|
||||
]);
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/strip-metadata",
|
||||
payload,
|
||||
headers: {
|
||||
"content-type": contentType,
|
||||
authorization: `Bearer ${adminToken}`,
|
||||
},
|
||||
});
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
});
|
||||
|
||||
// ── Format-specific re-encoding paths ────���────────────────────
|
||||
describe("Format-specific re-encoding", () => {
|
||||
it("re-encodes AVIF format after stripping", async () => {
|
||||
// Create a small AVIF buffer from PNG using Sharp
|
||||
const avifBuffer = await sharp(PNG).avif({ quality: 50 }).toBuffer();
|
||||
const res = await postTool({ stripAll: true }, avifBuffer, "test.avif", "image/avif");
|
||||
expect(res.statusCode).toBe(200);
|
||||
const result = JSON.parse(res.body);
|
||||
expect(result.downloadUrl).toBeDefined();
|
||||
expect(result.processedSize).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("handles default format case (non-standard format)", async () => {
|
||||
// Using a GIF triggers the default case in the switch
|
||||
const gifBuffer = await sharp(PNG).gif().toBuffer();
|
||||
const res = await postTool({ stripAll: true }, gifBuffer, "test.gif", "image/gif");
|
||||
expect(res.statusCode).toBe(200);
|
||||
const result = JSON.parse(res.body);
|
||||
expect(result.downloadUrl).toBeDefined();
|
||||
});
|
||||
|
||||
it("re-encodes TIFF format after stripping", async () => {
|
||||
const tiffBuffer = await sharp(PNG).tiff().toBuffer();
|
||||
const res = await postTool({ stripAll: true }, tiffBuffer, "test.tiff", "image/tiff");
|
||||
expect(res.statusCode).toBe(200);
|
||||
const result = JSON.parse(res.body);
|
||||
expect(result.downloadUrl).toBeDefined();
|
||||
expect(result.processedSize).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
// ── Inspect endpoint: ICC profile parsing ──────────────────────
|
||||
describe("Inspect endpoint: ICC and XMP parsing", () => {
|
||||
it("inspect returns ICC info when present", async () => {
|
||||
const { body: payload, contentType } = createMultipartPayload([
|
||||
{
|
||||
name: "file",
|
||||
filename: "test-with-exif.jpg",
|
||||
contentType: "image/jpeg",
|
||||
content: EXIF_JPG,
|
||||
},
|
||||
]);
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/strip-metadata/inspect",
|
||||
payload,
|
||||
headers: {
|
||||
"content-type": contentType,
|
||||
authorization: `Bearer ${adminToken}`,
|
||||
},
|
||||
});
|
||||
expect(res.statusCode).toBe(200);
|
||||
const result = JSON.parse(res.body);
|
||||
// ICC may or may not be present in the fixture, but the response should be valid
|
||||
if (result.icc) {
|
||||
expect(typeof result.icc).toBe("object");
|
||||
}
|
||||
});
|
||||
|
||||
it("inspect handles EXIF with GPS data", async () => {
|
||||
const { body: payload, contentType } = createMultipartPayload([
|
||||
{
|
||||
name: "file",
|
||||
filename: "test-with-exif.jpg",
|
||||
contentType: "image/jpeg",
|
||||
content: EXIF_JPG,
|
||||
},
|
||||
]);
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/strip-metadata/inspect",
|
||||
payload,
|
||||
headers: {
|
||||
"content-type": contentType,
|
||||
authorization: `Bearer ${adminToken}`,
|
||||
},
|
||||
});
|
||||
expect(res.statusCode).toBe(200);
|
||||
const result = JSON.parse(res.body);
|
||||
expect(result.filename).toBe("test-with-exif.jpg");
|
||||
// GPS may or may not be in fixture, but exif object should exist
|
||||
if (result.exif) {
|
||||
expect(typeof result.exif).toBe("object");
|
||||
}
|
||||
});
|
||||
|
||||
it("inspect returns empty metadata for image without any metadata", async () => {
|
||||
const blankPng = readFileSync(join(FIXTURES, "test-blank.png"));
|
||||
const { body: payload, contentType } = createMultipartPayload([
|
||||
{
|
||||
name: "file",
|
||||
filename: "blank.png",
|
||||
contentType: "image/png",
|
||||
content: blankPng,
|
||||
},
|
||||
]);
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/strip-metadata/inspect",
|
||||
payload,
|
||||
headers: {
|
||||
"content-type": contentType,
|
||||
authorization: `Bearer ${adminToken}`,
|
||||
},
|
||||
});
|
||||
expect(res.statusCode).toBe(200);
|
||||
const result = JSON.parse(res.body);
|
||||
expect(result.filename).toBe("blank.png");
|
||||
expect(result.fileSize).toBeGreaterThan(0);
|
||||
// No EXIF, ICC, or XMP expected
|
||||
expect(result.exif).toBeUndefined();
|
||||
expect(result.icc).toBeUndefined();
|
||||
expect(result.xmp).toBeUndefined();
|
||||
});
|
||||
|
||||
it("inspect handles empty file buffer", async () => {
|
||||
const { body: payload, contentType } = createMultipartPayload([
|
||||
{
|
||||
name: "file",
|
||||
filename: "empty.png",
|
||||
contentType: "image/png",
|
||||
content: Buffer.alloc(0),
|
||||
},
|
||||
]);
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/strip-metadata/inspect",
|
||||
payload,
|
||||
headers: {
|
||||
"content-type": contentType,
|
||||
authorization: `Bearer ${adminToken}`,
|
||||
},
|
||||
});
|
||||
expect(res.statusCode).toBe(400);
|
||||
const result = JSON.parse(res.body);
|
||||
expect(result.error).toMatch(/no image/i);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user