mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
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
869 lines
35 KiB
TypeScript
869 lines
35 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
// ─── Batch Processing ──────────────────────────────────────────────
|
|
// Tests for multi-file batch uploads across every tool category.
|
|
// Verifies ZIP output, batch limits, and correct processing of all files.
|
|
|
|
const FIXTURES = join(process.cwd(), "tests", "fixtures");
|
|
const FORMATS = join(FIXTURES, "formats");
|
|
let token: string;
|
|
|
|
test.beforeAll(async ({ request }) => {
|
|
const res = await request.post("/api/auth/login", {
|
|
data: { username: "admin", password: "admin" },
|
|
});
|
|
const body = await res.json();
|
|
token = body.token;
|
|
});
|
|
|
|
function fixture(name: string): Buffer {
|
|
return readFileSync(join(FIXTURES, name));
|
|
}
|
|
|
|
function formatFixture(name: string): Buffer {
|
|
return readFileSync(join(FORMATS, name));
|
|
}
|
|
|
|
/**
|
|
* Build a raw multipart/form-data body. Playwright's `multipart` option
|
|
* does not support arrays for the same field name, so multi-file uploads
|
|
* must be assembled manually.
|
|
*/
|
|
function buildMultipart(
|
|
files: Array<{ name: string; filename: string; contentType: string; buffer: Buffer }>,
|
|
fields: Array<{ name: string; value: string }>,
|
|
): { body: Buffer; contentType: string } {
|
|
const boundary = `----PlaywrightBoundary${Date.now()}`;
|
|
const parts: Buffer[] = [];
|
|
for (const file of files) {
|
|
parts.push(
|
|
Buffer.from(
|
|
`--${boundary}\r\nContent-Disposition: form-data; name="${file.name}"; filename="${file.filename}"\r\nContent-Type: ${file.contentType}\r\n\r\n`,
|
|
),
|
|
);
|
|
parts.push(file.buffer);
|
|
parts.push(Buffer.from("\r\n"));
|
|
}
|
|
for (const field of fields) {
|
|
parts.push(
|
|
Buffer.from(
|
|
`--${boundary}\r\nContent-Disposition: form-data; name="${field.name}"\r\n\r\n${field.value}\r\n`,
|
|
),
|
|
);
|
|
}
|
|
parts.push(Buffer.from(`--${boundary}--\r\n`));
|
|
return {
|
|
body: Buffer.concat(parts),
|
|
contentType: `multipart/form-data; boundary=${boundary}`,
|
|
};
|
|
}
|
|
|
|
const PNG_200x150 = fixture("test-200x150.png");
|
|
const JPG_100x100 = fixture("test-100x100.jpg");
|
|
const WEBP_50x50 = fixture("test-50x50.webp");
|
|
const HEIC_200x150 = fixture("test-200x150.heic");
|
|
|
|
// ─── Batch Resize ──────────────────────────────────────────────────
|
|
|
|
test.describe("Batch Resize", () => {
|
|
test("batch resize 3 images returns ZIP", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "c.webp", contentType: "image/webp", buffer: WEBP_50x50 },
|
|
],
|
|
[{ name: "settings", value: JSON.stringify({ width: 80, fit: "contain" }) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/resize/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
// Binary ZIP response
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
// ZIP magic bytes: PK\x03\x04
|
|
expect(buffer[0]).toBe(0x50);
|
|
expect(buffer[1]).toBe(0x4b);
|
|
}
|
|
});
|
|
|
|
test("batch resize 5 mixed-format images", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "c.webp", contentType: "image/webp", buffer: WEBP_50x50 },
|
|
{ name: "file", filename: "d.heic", contentType: "image/heic", buffer: HEIC_200x150 },
|
|
{
|
|
name: "file",
|
|
filename: "e.jpg",
|
|
contentType: "image/jpeg",
|
|
buffer: formatFixture("sample.jpg"),
|
|
},
|
|
],
|
|
[{ name: "settings", value: JSON.stringify({ width: 64, fit: "cover" }) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/resize/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ─── Batch Crop ────────────────────────────────────────────────────
|
|
|
|
test.describe("Batch Crop", () => {
|
|
test("batch crop 3 images to same region", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "c.webp", contentType: "image/webp", buffer: WEBP_50x50 },
|
|
],
|
|
[
|
|
{
|
|
name: "settings",
|
|
value: JSON.stringify({ left: 5, top: 5, width: 40, height: 40 }),
|
|
},
|
|
],
|
|
);
|
|
const res = await request.post("/api/v1/tools/crop/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ─── Batch Rotate ──────────────────────────────────────────────────
|
|
|
|
test.describe("Batch Rotate", () => {
|
|
test("batch rotate 3 images by 90 degrees", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "c.webp", contentType: "image/webp", buffer: WEBP_50x50 },
|
|
],
|
|
[{ name: "settings", value: JSON.stringify({ angle: 90 }) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/rotate/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ─── Batch Convert ─────────────────────────────────────────────────
|
|
|
|
test.describe("Batch Convert", () => {
|
|
test("batch convert 4 images to WebP", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "c.heic", contentType: "image/heic", buffer: HEIC_200x150 },
|
|
{
|
|
name: "file",
|
|
filename: "d.jpg",
|
|
contentType: "image/jpeg",
|
|
buffer: formatFixture("sample.jpg"),
|
|
},
|
|
],
|
|
[{ name: "settings", value: JSON.stringify({ format: "webp" }) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/convert/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
|
|
test("batch convert to AVIF format", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
],
|
|
[{ name: "settings", value: JSON.stringify({ format: "avif" }) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/convert/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
});
|
|
});
|
|
|
|
// ─── Batch Compress ────────────────────────────────────────────────
|
|
|
|
test.describe("Batch Compress", () => {
|
|
test("batch compress 4 images with low quality", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "c.webp", contentType: "image/webp", buffer: WEBP_50x50 },
|
|
{
|
|
name: "file",
|
|
filename: "d.jpg",
|
|
contentType: "image/jpeg",
|
|
buffer: formatFixture("sample.jpg"),
|
|
},
|
|
],
|
|
[{ name: "settings", value: JSON.stringify({ quality: 30 }) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/compress/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ─── Batch Color Adjustments ───────────────────────────────────────
|
|
|
|
test.describe("Batch Color Adjustments", () => {
|
|
test("batch adjust colors on 3 images", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "c.webp", contentType: "image/webp", buffer: WEBP_50x50 },
|
|
],
|
|
[
|
|
{
|
|
name: "settings",
|
|
value: JSON.stringify({ brightness: 15, contrast: 10, saturation: -5 }),
|
|
},
|
|
],
|
|
);
|
|
const res = await request.post("/api/v1/tools/adjust-colors/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
|
|
test("batch grayscale conversion", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
],
|
|
[{ name: "settings", value: JSON.stringify({ grayscale: true }) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/adjust-colors/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
});
|
|
});
|
|
|
|
// ─── Batch Sharpening ──────────────────────────────────────────────
|
|
|
|
test.describe("Batch Sharpening", () => {
|
|
test("batch sharpen 3 images", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "c.webp", contentType: "image/webp", buffer: WEBP_50x50 },
|
|
],
|
|
[{ name: "settings", value: JSON.stringify({ sigma: 1.5 }) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/sharpening/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ─── Batch Watermark Text ──────────────────────────────────────────
|
|
|
|
test.describe("Batch Watermark Text", () => {
|
|
test("batch watermark 3 images with center text", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "c.webp", contentType: "image/webp", buffer: WEBP_50x50 },
|
|
],
|
|
[
|
|
{
|
|
name: "settings",
|
|
value: JSON.stringify({
|
|
text: "BATCH WM",
|
|
fontSize: 24,
|
|
color: "#ff0000",
|
|
opacity: 40,
|
|
position: "center",
|
|
}),
|
|
},
|
|
],
|
|
);
|
|
const res = await request.post("/api/v1/tools/watermark-text/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ─── Batch Strip Metadata ──────────────────────────────────────────
|
|
|
|
test.describe("Batch Strip Metadata", () => {
|
|
test("batch strip metadata from 3 images", async ({ request }) => {
|
|
const jpgExif = fixture("test-with-exif.jpg");
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.jpg", contentType: "image/jpeg", buffer: jpgExif },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "c.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
],
|
|
[{ name: "settings", value: JSON.stringify({}) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/strip-metadata/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ─── Batch Optimize for Web ────────────────────────────────────────
|
|
|
|
test.describe("Batch Optimize for Web", () => {
|
|
test("batch optimize 4 images for web", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "c.heic", contentType: "image/heic", buffer: HEIC_200x150 },
|
|
{
|
|
name: "file",
|
|
filename: "d.jpg",
|
|
contentType: "image/jpeg",
|
|
buffer: formatFixture("sample.jpg"),
|
|
},
|
|
],
|
|
[{ name: "settings", value: JSON.stringify({ maxWidth: 800, quality: 70 }) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/optimize-for-web/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ─── Batch Border ──────────────────────────────────────────────────
|
|
|
|
test.describe("Batch Border", () => {
|
|
test("batch add border to 3 images", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "c.webp", contentType: "image/webp", buffer: WEBP_50x50 },
|
|
],
|
|
[{ name: "settings", value: JSON.stringify({ size: 10, color: "#0000ff" }) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/border/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ─── Batch Replace Color ───────────────────────────────────────────
|
|
|
|
test.describe("Batch Replace Color", () => {
|
|
test("batch replace color on 3 images", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "c.webp", contentType: "image/webp", buffer: WEBP_50x50 },
|
|
],
|
|
[
|
|
{
|
|
name: "settings",
|
|
value: JSON.stringify({
|
|
targetColor: "#ffffff",
|
|
replacementColor: "#ff00ff",
|
|
tolerance: 25,
|
|
}),
|
|
},
|
|
],
|
|
);
|
|
const res = await request.post("/api/v1/tools/replace-color/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ─── Batch Enhancement ─────────────────────────────────────────────
|
|
|
|
test.describe("Batch Enhancement", () => {
|
|
test("batch enhance 3 images with auto preset", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "c.webp", contentType: "image/webp", buffer: WEBP_50x50 },
|
|
],
|
|
[{ name: "settings", value: JSON.stringify({ preset: "auto" }) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/image-enhancement/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ─── Batch Vectorize ───────────────────────────────────────────────
|
|
|
|
test.describe("Batch Vectorize", () => {
|
|
test("batch vectorize 3 images to SVG", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "c.webp", contentType: "image/webp", buffer: WEBP_50x50 },
|
|
],
|
|
[{ name: "settings", value: JSON.stringify({}) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/vectorize/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
// Vectorize does not register in the batch tool registry, so batch
|
|
// endpoint may return 404. Accept either success or 404.
|
|
if (res.status() === 404) {
|
|
const json = await res.json();
|
|
expect(json.error).toBeDefined();
|
|
return;
|
|
}
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ─── Batch Text Overlay ────────────────────────────────────────────
|
|
|
|
test.describe("Batch Text Overlay", () => {
|
|
test("batch text overlay on 3 images", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "c.webp", contentType: "image/webp", buffer: WEBP_50x50 },
|
|
],
|
|
[
|
|
{
|
|
name: "settings",
|
|
value: JSON.stringify({
|
|
text: "BATCH TEXT",
|
|
fontSize: 20,
|
|
color: "#ffffff",
|
|
position: "bottom",
|
|
}),
|
|
},
|
|
],
|
|
);
|
|
const res = await request.post("/api/v1/tools/text-overlay/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ─── Batch Favicon ────────────────────────────────────────────────
|
|
|
|
test.describe("Batch Favicon", () => {
|
|
test("batch favicon from 3 images", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "c.webp", contentType: "image/webp", buffer: WEBP_50x50 },
|
|
],
|
|
[{ name: "settings", value: JSON.stringify({}) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/favicon/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
// Favicon batch may not be registered — accept 200 or 404
|
|
if (res.status() === 404) {
|
|
const json = await res.json();
|
|
expect(json.error).toBeDefined();
|
|
return;
|
|
}
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ─── Batch Edit Metadata ──────────────────────────────────────────
|
|
|
|
test.describe("Batch Edit Metadata", () => {
|
|
test("batch edit metadata on 3 images", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "b.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "c.webp", contentType: "image/webp", buffer: WEBP_50x50 },
|
|
],
|
|
[
|
|
{
|
|
name: "settings",
|
|
value: JSON.stringify({ artist: "Batch Test", copyright: "CC0" }),
|
|
},
|
|
],
|
|
);
|
|
const res = await request.post("/api/v1/tools/edit-metadata/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
// edit-metadata batch may not be registered — accept 200 or 404
|
|
if (res.status() === 404) {
|
|
const json = await res.json();
|
|
expect(json.error).toBeDefined();
|
|
return;
|
|
}
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
});
|
|
|
|
// ─── Batch Convert to Multiple Formats ────────────────────────────
|
|
|
|
test.describe("Batch Convert — format variety", () => {
|
|
test("batch convert to PNG", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "b.webp", contentType: "image/webp", buffer: WEBP_50x50 },
|
|
{ name: "file", filename: "c.heic", contentType: "image/heic", buffer: HEIC_200x150 },
|
|
],
|
|
[{ name: "settings", value: JSON.stringify({ format: "png" }) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/convert/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
|
|
test("batch convert to TIFF", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "c.webp", contentType: "image/webp", buffer: WEBP_50x50 },
|
|
],
|
|
[{ name: "settings", value: JSON.stringify({ format: "tiff" }) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/convert/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
});
|
|
});
|
|
|
|
// ─── Batch Rotate with Various Angles ─────────────────────────────
|
|
|
|
test.describe("Batch Rotate — angles", () => {
|
|
test("batch rotate 180 degrees", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "c.webp", contentType: "image/webp", buffer: WEBP_50x50 },
|
|
],
|
|
[{ name: "settings", value: JSON.stringify({ angle: 180 }) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/rotate/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
|
|
test("batch rotate 270 degrees", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
],
|
|
[{ name: "settings", value: JSON.stringify({ angle: 270 }) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/rotate/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
});
|
|
});
|
|
|
|
// ─── Batch with HEIC Input ────────────────────────────────────────
|
|
|
|
test.describe("Batch with HEIC input", () => {
|
|
test("batch resize HEIC and other formats", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.heic", contentType: "image/heic", buffer: HEIC_200x150 },
|
|
{ name: "file", filename: "b.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ name: "file", filename: "c.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
],
|
|
[{ name: "settings", value: JSON.stringify({ width: 64, fit: "contain" }) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/resize/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
});
|
|
|
|
test("batch compress HEIC with other formats", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[
|
|
{ name: "file", filename: "a.heic", contentType: "image/heic", buffer: HEIC_200x150 },
|
|
{ name: "file", filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ name: "file", filename: "c.webp", contentType: "image/webp", buffer: WEBP_50x50 },
|
|
],
|
|
[{ name: "settings", value: JSON.stringify({ quality: 50 }) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/compress/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
});
|
|
});
|
|
|
|
// ─── Batch with Empty File List ────────────────────────────────────
|
|
|
|
test.describe("Batch validation", () => {
|
|
test("batch resize rejects empty file list", async ({ request }) => {
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[],
|
|
[{ name: "settings", value: JSON.stringify({ width: 80 }) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/resize/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
expect(res.ok()).toBe(false);
|
|
const json = await res.json();
|
|
expect(json.error).toBeDefined();
|
|
});
|
|
|
|
test("batch compress rejects single file (should use non-batch endpoint)", async ({
|
|
request,
|
|
}) => {
|
|
// Single file to batch endpoint may be accepted or redirected;
|
|
// verify the response is coherent in either case
|
|
const { body: reqBody, contentType } = buildMultipart(
|
|
[{ name: "file", filename: "a.png", contentType: "image/png", buffer: PNG_200x150 }],
|
|
[{ name: "settings", value: JSON.stringify({ quality: 50 }) }],
|
|
);
|
|
const res = await request.post("/api/v1/tools/compress/batch", {
|
|
headers: { Authorization: `Bearer ${token}`, "Content-Type": contentType },
|
|
data: reqBody,
|
|
});
|
|
// Either accepts the single file or returns an error — both valid
|
|
const resContentType = res.headers()["content-type"] ?? "";
|
|
if (res.ok()) {
|
|
if (resContentType.includes("application/json")) {
|
|
const json = await res.json();
|
|
expect(json.downloadUrl).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
} else {
|
|
const json = await res.json();
|
|
expect(json.error).toBeDefined();
|
|
}
|
|
});
|
|
});
|