test: deepen integration tests for 8 complex tools (HEIC, large file, batch, edge cases)

This commit is contained in:
SnapOtter
2026-05-01 03:05:08 +08:00
parent 710b580cee
commit c9ed48b30e
7 changed files with 578 additions and 0 deletions
+97
View File
@@ -1386,4 +1386,101 @@ describe("Split", () => {
expect(res.statusCode).toBe(200);
});
// ── HEIF format input ─────────────────────────────────────────────
it("splits a HEIF input image", async () => {
const HEIF = readFileSync(join(FIXTURES, "content", "motorcycle.heif"));
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "photo.heif", contentType: "image/heif", content: HEIF },
{
name: "settings",
content: JSON.stringify({ columns: 2, rows: 2, outputFormat: "png" }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/split",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(200);
const zip = new AdmZip(res.rawPayload);
const entries = zip.getEntries();
expect(entries.length).toBe(4);
for (const entry of entries) {
expect(entry.entryName).toMatch(/\.png$/);
const meta = await sharp(entry.getData()).metadata();
expect(meta.format).toBe("png");
expect(meta.width).toBeGreaterThan(0);
expect(meta.height).toBeGreaterThan(0);
}
});
// ── Animated GIF input ────────────────────────────────────────────
it("splits an animated GIF input image", async () => {
const GIF = readFileSync(join(FIXTURES, "animated.gif"));
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "anim.gif", contentType: "image/gif", content: GIF },
{
name: "settings",
content: JSON.stringify({ columns: 2, rows: 2, outputFormat: "png" }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/split",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(200);
const zip = new AdmZip(res.rawPayload);
const entries = zip.getEntries();
expect(entries.length).toBe(4);
});
// ── SVG input ─────────────────────────────────────────────────────
it("splits an SVG input image", async () => {
const SVG = readFileSync(join(FIXTURES, "test-100x100.svg"));
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "icon.svg", contentType: "image/svg+xml", content: SVG },
{
name: "settings",
content: JSON.stringify({ columns: 2, rows: 2, outputFormat: "png" }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/split",
headers: {
authorization: `Bearer ${adminToken}`,
"content-type": contentType,
},
body,
});
expect(res.statusCode).toBe(200);
const zip = new AdmZip(res.rawPayload);
const entries = zip.getEntries();
expect(entries.length).toBe(4);
for (const entry of entries) {
const meta = await sharp(entry.getData()).metadata();
expect(meta.format).toBe("png");
expect(meta.width).toBeGreaterThan(0);
expect(meta.height).toBeGreaterThan(0);
}
});
});