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
621 lines
22 KiB
TypeScript
621 lines
22 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
// ─── Pipeline Tools ─────────────────────────────────────────────────
|
|
// Tests for the pipeline/automation system:
|
|
// POST /api/v1/pipeline/execute — run a multi-step pipeline
|
|
// POST /api/v1/pipeline/save — save a pipeline definition
|
|
// GET /api/v1/pipeline/list — list saved pipelines
|
|
// DELETE /api/v1/pipeline/:id — delete a saved pipeline
|
|
//
|
|
// Pipelines chain tool steps: the output of step N feeds into step N+1.
|
|
// AI tools in a pipeline respect the same FEATURE_NOT_INSTALLED guard.
|
|
|
|
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));
|
|
}
|
|
|
|
const PNG_200x150 = fixture("test-200x150.png");
|
|
const JPG_100x100 = fixture("test-100x100.jpg");
|
|
const JPG_SAMPLE = readFileSync(join(FORMATS, "sample.jpg"));
|
|
|
|
// ─── Pipeline Execution ─────────────────────────────────────────────
|
|
|
|
test.describe("Pipeline execution", () => {
|
|
test("execute single-step pipeline (resize)", async ({ request }) => {
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.png", mimeType: "image/png", buffer: PNG_200x150 },
|
|
pipeline: JSON.stringify({
|
|
steps: [{ toolId: "resize", settings: { width: 100, fit: "contain" } }],
|
|
}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
expect(body.processedSize).toBeGreaterThan(0);
|
|
expect(body.steps).toBeTruthy();
|
|
});
|
|
|
|
test("execute two-step pipeline (resize then compress)", async ({ request }) => {
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "sample.jpg", mimeType: "image/jpeg", buffer: JPG_SAMPLE },
|
|
pipeline: JSON.stringify({
|
|
steps: [
|
|
{ toolId: "resize", settings: { width: 400, fit: "contain" } },
|
|
{ toolId: "compress", settings: { quality: 60 } },
|
|
],
|
|
}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
expect(body.processedSize).toBeGreaterThan(0);
|
|
// The pipeline output should be smaller than the original sample
|
|
expect(body.processedSize).toBeLessThan(body.originalSize);
|
|
});
|
|
|
|
test("execute three-step pipeline (resize, rotate, border)", async ({ request }) => {
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.png", mimeType: "image/png", buffer: PNG_200x150 },
|
|
pipeline: JSON.stringify({
|
|
steps: [
|
|
{ toolId: "resize", settings: { width: 100, fit: "contain" } },
|
|
{ toolId: "rotate", settings: { angle: 90 } },
|
|
{ toolId: "border", settings: { size: 10, color: "#ff0000" } },
|
|
],
|
|
}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
});
|
|
|
|
test("execute pipeline with format conversion", async ({ request }) => {
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.png", mimeType: "image/png", buffer: PNG_200x150 },
|
|
pipeline: JSON.stringify({
|
|
steps: [
|
|
{ toolId: "resize", settings: { width: 150, fit: "contain" } },
|
|
{ toolId: "convert", settings: { format: "webp" } },
|
|
],
|
|
}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
// Output should be WebP
|
|
expect(body.downloadUrl).toContain(".webp");
|
|
});
|
|
|
|
test("execute pipeline with color adjustments and sharpening", async ({ request }) => {
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.jpg", mimeType: "image/jpeg", buffer: JPG_100x100 },
|
|
pipeline: JSON.stringify({
|
|
steps: [
|
|
{ toolId: "adjust-colors", settings: { brightness: 10, contrast: 15 } },
|
|
{ toolId: "sharpening", settings: { sigma: 1.5 } },
|
|
],
|
|
}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
});
|
|
|
|
test("execute pipeline with watermark and optimize", async ({ request }) => {
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "sample.jpg", mimeType: "image/jpeg", buffer: JPG_SAMPLE },
|
|
pipeline: JSON.stringify({
|
|
steps: [
|
|
{
|
|
toolId: "watermark-text",
|
|
settings: {
|
|
text: "SAMPLE",
|
|
fontSize: 48,
|
|
color: "#ff0000",
|
|
opacity: 30,
|
|
position: "center",
|
|
},
|
|
},
|
|
{ toolId: "optimize-for-web", settings: { maxWidth: 1200, quality: 75 } },
|
|
],
|
|
}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
// ─── Pipeline with AI Tools ─────────────────────────────────────────
|
|
|
|
test.describe("Pipeline with AI tools", () => {
|
|
test("pipeline with AI tool returns 501 when feature not installed", async ({ request }) => {
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.png", mimeType: "image/png", buffer: PNG_200x150 },
|
|
pipeline: JSON.stringify({
|
|
steps: [
|
|
{ toolId: "resize", settings: { width: 100 } },
|
|
{ toolId: "remove-background", settings: {} },
|
|
],
|
|
}),
|
|
},
|
|
});
|
|
|
|
// Check whether the feature is installed
|
|
const featuresRes = await request.get("/api/v1/features", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
});
|
|
const features = await featuresRes.json();
|
|
const bgBundle = features.bundles?.find((b: { id: string }) => b.id === "background-removal");
|
|
const isInstalled = bgBundle?.status === "installed";
|
|
|
|
if (!isInstalled) {
|
|
// Pipeline should fail at the AI step with 501
|
|
expect(res.status()).toBe(501);
|
|
const body = await res.json();
|
|
expect(body.code).toBe("FEATURE_NOT_INSTALLED");
|
|
} else {
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
}
|
|
});
|
|
|
|
test("mixed pipeline: non-AI steps before AI step", async ({ request }) => {
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.jpg", mimeType: "image/jpeg", buffer: JPG_100x100 },
|
|
pipeline: JSON.stringify({
|
|
steps: [
|
|
{ toolId: "resize", settings: { width: 80, fit: "contain" } },
|
|
{ toolId: "upscale", settings: { scale: 2, model: "auto" } },
|
|
],
|
|
}),
|
|
},
|
|
});
|
|
|
|
const featuresRes = await request.get("/api/v1/features", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
});
|
|
const features = await featuresRes.json();
|
|
const upscaleBundle = features.bundles?.find((b: { id: string }) => b.id === "upscale-enhance");
|
|
const isInstalled = upscaleBundle?.status === "installed";
|
|
|
|
if (!isInstalled) {
|
|
expect(res.status()).toBe(501);
|
|
} else {
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
}
|
|
});
|
|
});
|
|
|
|
// ─── Pipeline Validation ────────────────────────────────────────────
|
|
|
|
test.describe("Pipeline validation", () => {
|
|
test("reject pipeline with no steps", async ({ request }) => {
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.png", mimeType: "image/png", buffer: PNG_200x150 },
|
|
pipeline: JSON.stringify({ steps: [] }),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(false);
|
|
const body = await res.json();
|
|
expect(body.error).toBeDefined();
|
|
});
|
|
|
|
test("reject pipeline with unknown tool", async ({ request }) => {
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.png", mimeType: "image/png", buffer: PNG_200x150 },
|
|
pipeline: JSON.stringify({
|
|
steps: [{ toolId: "nonexistent-tool", settings: {} }],
|
|
}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(false);
|
|
const body = await res.json();
|
|
expect(body.error).toBeDefined();
|
|
});
|
|
|
|
test("reject pipeline with no file", async ({ request }) => {
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
pipeline: JSON.stringify({
|
|
steps: [{ toolId: "resize", settings: { width: 100 } }],
|
|
}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(false);
|
|
});
|
|
|
|
test("reject pipeline with invalid JSON", async ({ request }) => {
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.png", mimeType: "image/png", buffer: PNG_200x150 },
|
|
pipeline: "not valid json {{{",
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(false);
|
|
});
|
|
|
|
test("reject pipeline with invalid tool settings", async ({ request }) => {
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.png", mimeType: "image/png", buffer: PNG_200x150 },
|
|
pipeline: JSON.stringify({
|
|
steps: [{ toolId: "resize", settings: { width: -100 } }],
|
|
}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(false);
|
|
const body = await res.json();
|
|
expect(body.error).toBeDefined();
|
|
});
|
|
});
|
|
|
|
// ─── Pipeline Save / List / Delete ──────────────────────────────────
|
|
|
|
test.describe("Pipeline CRUD", () => {
|
|
test("save a pipeline definition", async ({ request }) => {
|
|
const res = await request.post("/api/v1/pipeline/save", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
data: {
|
|
name: "E2E Test Pipeline",
|
|
description: "Resize then compress for web optimization",
|
|
steps: [
|
|
{ toolId: "resize", settings: { width: 800, fit: "contain" } },
|
|
{ toolId: "compress", settings: { quality: 75 } },
|
|
],
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.id).toBeTruthy();
|
|
});
|
|
|
|
test("list saved pipelines", async ({ request }) => {
|
|
const res = await request.get("/api/v1/pipeline/list", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.pipelines || body).toBeInstanceOf(Array);
|
|
});
|
|
|
|
test("delete a saved pipeline", async ({ request }) => {
|
|
// First save one to ensure we have something to delete
|
|
const saveRes = await request.post("/api/v1/pipeline/save", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
data: {
|
|
name: "Temp Pipeline for Deletion",
|
|
steps: [{ toolId: "resize", settings: { width: 100 } }],
|
|
},
|
|
});
|
|
expect(saveRes.ok()).toBe(true);
|
|
const { id } = await saveRes.json();
|
|
|
|
// Delete it
|
|
const deleteRes = await request.delete(`/api/v1/pipeline/${id}`, {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
});
|
|
expect(deleteRes.ok()).toBe(true);
|
|
|
|
// Verify it's gone from the list
|
|
const listRes = await request.get("/api/v1/pipeline/list", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
});
|
|
expect(listRes.ok()).toBe(true);
|
|
const listBody = await listRes.json();
|
|
const pipelines = listBody.pipelines ?? listBody;
|
|
const found = pipelines.find((p: { id: string }) => p.id === id);
|
|
expect(found).toBeUndefined();
|
|
});
|
|
|
|
test("save pipeline rejects empty name", async ({ request }) => {
|
|
const res = await request.post("/api/v1/pipeline/save", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
data: {
|
|
name: "",
|
|
steps: [{ toolId: "resize", settings: { width: 100 } }],
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(false);
|
|
const body = await res.json();
|
|
expect(body.error).toBeDefined();
|
|
});
|
|
|
|
test("save pipeline rejects empty steps", async ({ request }) => {
|
|
const res = await request.post("/api/v1/pipeline/save", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
data: {
|
|
name: "Empty Pipeline",
|
|
steps: [],
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(false);
|
|
const body = await res.json();
|
|
expect(body.error).toBeDefined();
|
|
});
|
|
|
|
test("delete nonexistent pipeline returns 404", async ({ request }) => {
|
|
const res = await request.delete("/api/v1/pipeline/00000000-0000-0000-0000-000000000000", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
});
|
|
expect(res.status()).toBe(404);
|
|
});
|
|
});
|
|
|
|
// ─── Pipeline Execution Edge Cases ──────────────────────────────────
|
|
|
|
test.describe("Pipeline edge cases", () => {
|
|
test("HEIC input is decoded before first step", async ({ request }) => {
|
|
const heic = fixture("test-200x150.heic");
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.heic", mimeType: "image/heic", buffer: heic },
|
|
pipeline: JSON.stringify({
|
|
steps: [{ toolId: "resize", settings: { width: 100, fit: "contain" } }],
|
|
}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
});
|
|
|
|
test("strip-metadata then convert pipeline", async ({ request }) => {
|
|
const jpgExif = fixture("test-with-exif.jpg");
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "photo.jpg", mimeType: "image/jpeg", buffer: jpgExif },
|
|
pipeline: JSON.stringify({
|
|
steps: [
|
|
{ toolId: "strip-metadata", settings: {} },
|
|
{ toolId: "convert", settings: { format: "webp" } },
|
|
],
|
|
}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
expect(body.downloadUrl).toContain(".webp");
|
|
});
|
|
|
|
test("text-overlay then border pipeline", async ({ request }) => {
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.png", mimeType: "image/png", buffer: PNG_200x150 },
|
|
pipeline: JSON.stringify({
|
|
steps: [
|
|
{
|
|
toolId: "text-overlay",
|
|
settings: {
|
|
text: "Pipeline Test",
|
|
fontSize: 24,
|
|
color: "#FFFFFF",
|
|
position: "center",
|
|
},
|
|
},
|
|
{ toolId: "border", settings: { size: 5, color: "#000000" } },
|
|
],
|
|
}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
});
|
|
|
|
test("full processing pipeline: resize, enhance, sharpen, watermark, compress", async ({
|
|
request,
|
|
}) => {
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "sample.jpg", mimeType: "image/jpeg", buffer: JPG_SAMPLE },
|
|
pipeline: JSON.stringify({
|
|
steps: [
|
|
{ toolId: "resize", settings: { width: 600, fit: "contain" } },
|
|
{ toolId: "image-enhancement", settings: { preset: "auto" } },
|
|
{ toolId: "sharpening", settings: { sigma: 1.0 } },
|
|
{
|
|
toolId: "watermark-text",
|
|
settings: {
|
|
text: "snapotter",
|
|
fontSize: 20,
|
|
color: "#808080",
|
|
opacity: 20,
|
|
position: "bottom-right",
|
|
},
|
|
},
|
|
{ toolId: "compress", settings: { quality: 80 } },
|
|
],
|
|
}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
expect(body.processedSize).toBeGreaterThan(0);
|
|
// Full pipeline should produce a smaller file than original
|
|
expect(body.processedSize).toBeLessThan(body.originalSize);
|
|
});
|
|
});
|
|
|
|
// ─── Batch Pipeline Execution ──────────────────────────────────────
|
|
|
|
test.describe("Batch pipeline execution", () => {
|
|
test("batch pipeline resize+compress on 3 images", async ({ request }) => {
|
|
const boundary = `----PlaywrightBoundary${Date.now()}`;
|
|
const files = [
|
|
{ filename: "a.png", contentType: "image/png", buffer: PNG_200x150 },
|
|
{ filename: "b.jpg", contentType: "image/jpeg", buffer: JPG_100x100 },
|
|
{ filename: "c.jpg", contentType: "image/jpeg", buffer: JPG_SAMPLE },
|
|
];
|
|
const parts: Buffer[] = [];
|
|
for (const file of files) {
|
|
parts.push(
|
|
Buffer.from(
|
|
`--${boundary}\r\nContent-Disposition: form-data; name="file"; filename="${file.filename}"\r\nContent-Type: ${file.contentType}\r\n\r\n`,
|
|
),
|
|
);
|
|
parts.push(file.buffer);
|
|
parts.push(Buffer.from("\r\n"));
|
|
}
|
|
parts.push(
|
|
Buffer.from(
|
|
`--${boundary}\r\nContent-Disposition: form-data; name="pipeline"\r\n\r\n${JSON.stringify({
|
|
steps: [
|
|
{ toolId: "resize", settings: { width: 100, fit: "contain" } },
|
|
{ toolId: "compress", settings: { quality: 60 } },
|
|
],
|
|
})}\r\n`,
|
|
),
|
|
);
|
|
parts.push(Buffer.from(`--${boundary}--\r\n`));
|
|
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: {
|
|
Authorization: `Bearer ${token}`,
|
|
"Content-Type": `multipart/form-data; boundary=${boundary}`,
|
|
},
|
|
data: Buffer.concat(parts),
|
|
});
|
|
// Batch pipeline may return ZIP or JSON depending on implementation
|
|
if (res.ok()) {
|
|
const ct = res.headers()["content-type"] ?? "";
|
|
if (ct.includes("application/json")) {
|
|
const body = await res.json();
|
|
expect(body.downloadUrl || body.results).toBeTruthy();
|
|
} else {
|
|
const buffer = Buffer.from(await res.body());
|
|
expect(buffer.length).toBeGreaterThan(0);
|
|
}
|
|
} else {
|
|
// Batch pipeline may not be supported — single-file only
|
|
// Verify the error is coherent, not a crash
|
|
const body = await res.json();
|
|
expect(body.error).toBeDefined();
|
|
}
|
|
});
|
|
});
|
|
|
|
// ─── Pipeline with Crop Dimensions ─────────────────────────────────
|
|
|
|
test.describe("Pipeline with various tools", () => {
|
|
test("crop then border then compress pipeline", async ({ request }) => {
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "sample.jpg", mimeType: "image/jpeg", buffer: JPG_SAMPLE },
|
|
pipeline: JSON.stringify({
|
|
steps: [
|
|
{ toolId: "crop", settings: { left: 0, top: 0, width: 200, height: 200 } },
|
|
{ toolId: "border", settings: { size: 10, color: "#ff0000" } },
|
|
{ toolId: "compress", settings: { quality: 70 } },
|
|
],
|
|
}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
expect(body.processedSize).toBeGreaterThan(0);
|
|
});
|
|
|
|
test("replace-color then resize pipeline", async ({ request }) => {
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.png", mimeType: "image/png", buffer: PNG_200x150 },
|
|
pipeline: JSON.stringify({
|
|
steps: [
|
|
{
|
|
toolId: "replace-color",
|
|
settings: {
|
|
targetColor: "#ffffff",
|
|
replacementColor: "#f0f0f0",
|
|
tolerance: 20,
|
|
},
|
|
},
|
|
{ toolId: "resize", settings: { width: 100, fit: "contain" } },
|
|
],
|
|
}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
});
|
|
|
|
test("edit-metadata then strip-metadata roundtrip", async ({ request }) => {
|
|
const jpgExif = fixture("test-with-exif.jpg");
|
|
const res = await request.post("/api/v1/pipeline/execute", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "photo.jpg", mimeType: "image/jpeg", buffer: jpgExif },
|
|
pipeline: JSON.stringify({
|
|
steps: [
|
|
{
|
|
toolId: "edit-metadata",
|
|
settings: { artist: "Pipeline Author", copyright: "CC0" },
|
|
},
|
|
{ toolId: "strip-metadata", settings: {} },
|
|
],
|
|
}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
});
|
|
});
|