mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
- Unit: 1,353 tests (42 files) — +256 new tests covering AI bridge modules, image-engine sharpen/optimize-for-web, Zustand stores, and icon-map validation - Integration: 1,640 tests (57 files) — +826 new tests across all tool routes, pipeline/progress/batch infrastructure, user-files, edit-metadata, and a 321-test cross-format matrix - E2E-Docker: 389 passing (20 spec files) — 6 new spec files for batch processing, format conversion, layout, optimization, watermark/overlay, and pipeline chains. Tests verified against fresh Docker container with all 6 AI bundles installed. Bug fixes discovered during testing: - fix(compress): SVG/BMP/exotic formats crashed Sharp encoder — added format-safety fallback to PNG - fix(rate-limit): increase default login attempt limit from 10 to 500 per minute — previous value caused false test failures and is too restrictive for a self-hosted app - fix(auth.setup): wait for consent button visibility before clicking to prevent flaky E2E-Docker auth setup
504 lines
19 KiB
TypeScript
504 lines
19 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { expect, test } from "@playwright/test";
|
|
|
|
// ─── Format Conversion Tools ───────────────────────────────────────
|
|
// Comprehensive format conversion coverage: SVG-to-raster with all
|
|
// output formats, vectorize from all raster formats, GIF tools with
|
|
// various operations, PDF-to-image with all DPI and format options.
|
|
// Complements conversion-tools.spec.ts with deeper fixture coverage.
|
|
|
|
const FIXTURES = join(process.cwd(), "tests", "fixtures");
|
|
const FORMATS = join(FIXTURES, "formats");
|
|
const CONTENT = join(FIXTURES, "content");
|
|
|
|
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));
|
|
}
|
|
|
|
function contentFixture(name: string): Buffer {
|
|
return readFileSync(join(CONTENT, name));
|
|
}
|
|
|
|
const PNG_200x150 = fixture("test-200x150.png");
|
|
const SVG_100x100 = fixture("test-100x100.svg");
|
|
const HEIC_200x150 = fixture("test-200x150.heic");
|
|
const WEBP_50x50 = fixture("test-50x50.webp");
|
|
const ANIMATED_GIF = fixture("animated.gif");
|
|
const PDF_3PAGE = fixture("test-3page.pdf");
|
|
|
|
// ─── SVG to Raster — Extended Formats ──────────────────────────────
|
|
|
|
test.describe("SVG to Raster — extended", () => {
|
|
test("convert SVG to AVIF", async ({ request }) => {
|
|
const res = await request.post("/api/v1/tools/svg-to-raster", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.svg", mimeType: "image/svg+xml", buffer: SVG_100x100 },
|
|
settings: JSON.stringify({ format: "avif", width: 256 }),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
expect(body.processedSize).toBeGreaterThan(0);
|
|
});
|
|
|
|
test("convert SVG to TIFF", async ({ request }) => {
|
|
const res = await request.post("/api/v1/tools/svg-to-raster", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.svg", mimeType: "image/svg+xml", buffer: SVG_100x100 },
|
|
settings: JSON.stringify({ format: "tiff", width: 400 }),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
});
|
|
|
|
test("convert SVG with large render width (1024px)", async ({ request }) => {
|
|
const res = await request.post("/api/v1/tools/svg-to-raster", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.svg", mimeType: "image/svg+xml", buffer: SVG_100x100 },
|
|
settings: JSON.stringify({ format: "png", width: 1024 }),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
expect(body.processedSize).toBeGreaterThan(0);
|
|
});
|
|
|
|
test("convert QR code SVG to raster", async ({ request }) => {
|
|
const qrSvg = contentFixture("qr-code.svg");
|
|
const res = await request.post("/api/v1/tools/svg-to-raster", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "qr.svg", mimeType: "image/svg+xml", buffer: qrSvg },
|
|
settings: JSON.stringify({ format: "png", width: 400 }),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
// ─── Vectorize — Extended Formats ──────────────────────────────────
|
|
|
|
test.describe("Vectorize — extended", () => {
|
|
test("vectorize WebP to SVG", async ({ request }) => {
|
|
const res = await request.post("/api/v1/tools/vectorize", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.webp", mimeType: "image/webp", buffer: WEBP_50x50 },
|
|
settings: JSON.stringify({}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
expect(body.downloadUrl).toContain(".svg");
|
|
});
|
|
|
|
test("vectorize HEIC to SVG", async ({ request }) => {
|
|
const res = await request.post("/api/v1/tools/vectorize", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.heic", mimeType: "image/heic", buffer: HEIC_200x150 },
|
|
settings: JSON.stringify({}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
});
|
|
|
|
test("vectorize AVIF sample to SVG", async ({ request }) => {
|
|
const avif = formatFixture("sample.avif");
|
|
const res = await request.post("/api/v1/tools/vectorize", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "sample.avif", mimeType: "image/avif", buffer: avif },
|
|
settings: JSON.stringify({}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
});
|
|
|
|
test("vectorize TIFF sample to SVG", async ({ request }) => {
|
|
const tiff = formatFixture("sample.tiff");
|
|
const res = await request.post("/api/v1/tools/vectorize", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "sample.tiff", mimeType: "image/tiff", buffer: tiff },
|
|
settings: JSON.stringify({}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
// ─── GIF Tools — Extended ──────────────────────────────────────────
|
|
|
|
test.describe("GIF Tools — extended", () => {
|
|
test("GIF tool with resize settings", async ({ request }) => {
|
|
const res = await request.post("/api/v1/tools/gif-tools", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "animated.gif", mimeType: "image/gif", buffer: ANIMATED_GIF },
|
|
settings: JSON.stringify({ action: "resize", width: 100 }),
|
|
},
|
|
});
|
|
if (res.ok()) {
|
|
const body = await res.json();
|
|
expect(body.downloadUrl || body.frames).toBeTruthy();
|
|
} else {
|
|
const body = await res.json();
|
|
expect(body.error).toBeDefined();
|
|
}
|
|
});
|
|
|
|
test("GIF tool with extract-frames action", async ({ request }) => {
|
|
const res = await request.post("/api/v1/tools/gif-tools", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "animated.gif", mimeType: "image/gif", buffer: ANIMATED_GIF },
|
|
settings: JSON.stringify({ action: "extract-frames" }),
|
|
},
|
|
});
|
|
if (res.ok()) {
|
|
const body = await res.json();
|
|
expect(body.downloadUrl || body.frames).toBeTruthy();
|
|
} else {
|
|
const body = await res.json();
|
|
expect(body.error).toBeDefined();
|
|
}
|
|
});
|
|
|
|
test("GIF tool with speed adjustment", async ({ request }) => {
|
|
const simpsons = contentFixture("animated-simpsons.gif");
|
|
const res = await request.post("/api/v1/tools/gif-tools", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "simpsons.gif", mimeType: "image/gif", buffer: simpsons },
|
|
settings: JSON.stringify({ action: "speed", speedFactor: 2 }),
|
|
},
|
|
});
|
|
if (res.ok()) {
|
|
const body = await res.json();
|
|
expect(body.downloadUrl || body.frames).toBeTruthy();
|
|
} else {
|
|
const body = await res.json();
|
|
expect(body.error).toBeDefined();
|
|
}
|
|
});
|
|
|
|
test("GIF tool with reverse action", async ({ request }) => {
|
|
const res = await request.post("/api/v1/tools/gif-tools", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "animated.gif", mimeType: "image/gif", buffer: ANIMATED_GIF },
|
|
settings: JSON.stringify({ action: "reverse" }),
|
|
},
|
|
});
|
|
if (res.ok()) {
|
|
const body = await res.json();
|
|
expect(body.downloadUrl || body.frames).toBeTruthy();
|
|
} else {
|
|
const body = await res.json();
|
|
expect(body.error).toBeDefined();
|
|
}
|
|
});
|
|
|
|
test("reject non-GIF file", async ({ request }) => {
|
|
const res = await request.post("/api/v1/tools/gif-tools", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.png", mimeType: "image/png", buffer: PNG_200x150 },
|
|
settings: JSON.stringify({}),
|
|
},
|
|
});
|
|
// May accept and convert, or reject with error
|
|
if (!res.ok()) {
|
|
const body = await res.json();
|
|
expect(body.error).toBeDefined();
|
|
}
|
|
});
|
|
});
|
|
|
|
// ─── PDF to Image — Extended ───────────────────────────────────────
|
|
|
|
test.describe("PDF to Image — extended", () => {
|
|
test("convert PDF to AVIF format", async ({ request }) => {
|
|
const res = await request.post("/api/v1/tools/pdf-to-image", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.pdf", mimeType: "application/pdf", buffer: PDF_3PAGE },
|
|
settings: JSON.stringify({ format: "avif", dpi: 150, pages: "1" }),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl || body.pages || body.jobId).toBeTruthy();
|
|
});
|
|
|
|
test("convert PDF at high DPI (300)", async ({ request }) => {
|
|
const res = await request.post("/api/v1/tools/pdf-to-image", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.pdf", mimeType: "application/pdf", buffer: PDF_3PAGE },
|
|
settings: JSON.stringify({ format: "png", dpi: 300, pages: "1" }),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl || body.pages || body.jobId).toBeTruthy();
|
|
});
|
|
|
|
test("convert PDF at low DPI (72)", async ({ request }) => {
|
|
const res = await request.post("/api/v1/tools/pdf-to-image", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.pdf", mimeType: "application/pdf", buffer: PDF_3PAGE },
|
|
settings: JSON.stringify({ format: "jpg", dpi: 72, pages: "all" }),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl || body.pages || body.jobId).toBeTruthy();
|
|
});
|
|
|
|
test("convert specific middle page", async ({ request }) => {
|
|
const res = await request.post("/api/v1/tools/pdf-to-image", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.pdf", mimeType: "application/pdf", buffer: PDF_3PAGE },
|
|
settings: JSON.stringify({ format: "png", dpi: 150, pages: "2" }),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl || body.pages || body.jobId).toBeTruthy();
|
|
});
|
|
|
|
test("convert last page only", async ({ request }) => {
|
|
const res = await request.post("/api/v1/tools/pdf-to-image", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.pdf", mimeType: "application/pdf", buffer: PDF_3PAGE },
|
|
settings: JSON.stringify({ format: "png", dpi: 150, pages: "3" }),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl || body.pages || body.jobId).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
// ─── Convert from Exotic Formats ───────────────────────────────────
|
|
|
|
test.describe("Convert from exotic formats", () => {
|
|
test("TIFF to PNG", async ({ request }) => {
|
|
const tiff = formatFixture("sample.tiff");
|
|
const res = await request.post("/api/v1/tools/convert", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "sample.tiff", mimeType: "image/tiff", buffer: tiff },
|
|
settings: JSON.stringify({ format: "png" }),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toContain(".png");
|
|
expect(body.processedSize).toBeGreaterThan(0);
|
|
});
|
|
|
|
test("TIFF to JPEG", async ({ request }) => {
|
|
const tiff = formatFixture("sample.tiff");
|
|
const res = await request.post("/api/v1/tools/convert", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "sample.tiff", mimeType: "image/tiff", buffer: tiff },
|
|
settings: JSON.stringify({ format: "jpg", quality: 85 }),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toContain(".jpg");
|
|
});
|
|
|
|
test("AVIF to PNG", async ({ request }) => {
|
|
const avif = formatFixture("sample.avif");
|
|
const res = await request.post("/api/v1/tools/convert", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "sample.avif", mimeType: "image/avif", buffer: avif },
|
|
settings: JSON.stringify({ format: "png" }),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toContain(".png");
|
|
});
|
|
|
|
test("AVIF to WebP", async ({ request }) => {
|
|
const avif = formatFixture("sample.avif");
|
|
const res = await request.post("/api/v1/tools/convert", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "sample.avif", mimeType: "image/avif", buffer: avif },
|
|
settings: JSON.stringify({ format: "webp" }),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toContain(".webp");
|
|
});
|
|
|
|
test("GIF to PNG (single frame)", async ({ request }) => {
|
|
const gif = formatFixture("sample.gif");
|
|
const res = await request.post("/api/v1/tools/convert", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "sample.gif", mimeType: "image/gif", buffer: gif },
|
|
settings: JSON.stringify({ format: "png" }),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toContain(".png");
|
|
});
|
|
|
|
test("HEIF to WebP", async ({ request }) => {
|
|
const heif = formatFixture("sample.heif");
|
|
const res = await request.post("/api/v1/tools/convert", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "sample.heif", mimeType: "image/heif", buffer: heif },
|
|
settings: JSON.stringify({ format: "webp" }),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toContain(".webp");
|
|
});
|
|
|
|
test("HEIF to JPEG", async ({ request }) => {
|
|
const heif = formatFixture("sample.heif");
|
|
const res = await request.post("/api/v1/tools/convert", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "sample.heif", mimeType: "image/heif", buffer: heif },
|
|
settings: JSON.stringify({ format: "jpg" }),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl).toContain(".jpg");
|
|
});
|
|
});
|
|
|
|
// ─── Image to Base64 — Extended Formats ────────────────────────────
|
|
|
|
test.describe("Image to Base64 — extended", () => {
|
|
test("encode WebP to base64", async ({ request }) => {
|
|
const res = await request.post("/api/v1/tools/image-to-base64", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.webp", mimeType: "image/webp", buffer: WEBP_50x50 },
|
|
settings: JSON.stringify({}),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.results).toBeInstanceOf(Array);
|
|
expect(body.results[0].base64).toBeTruthy();
|
|
expect(body.results[0].width).toBe(50);
|
|
expect(body.results[0].height).toBe(50);
|
|
});
|
|
|
|
test("encode HEIC to base64 with format conversion", async ({ request }) => {
|
|
const res = await request.post("/api/v1/tools/image-to-base64", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "test.heic", mimeType: "image/heic", buffer: HEIC_200x150 },
|
|
settings: JSON.stringify({ outputFormat: "png" }),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.results[0].base64).toBeTruthy();
|
|
expect(body.results[0].mimeType).toBe("image/png");
|
|
});
|
|
|
|
test("encode with both maxWidth and format conversion", async ({ request }) => {
|
|
const sample = formatFixture("sample.jpg");
|
|
const res = await request.post("/api/v1/tools/image-to-base64", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "sample.jpg", mimeType: "image/jpeg", buffer: sample },
|
|
settings: JSON.stringify({ outputFormat: "webp", maxWidth: 100, quality: 60 }),
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.results[0].mimeType).toBe("image/webp");
|
|
expect(body.results[0].width).toBeLessThanOrEqual(100);
|
|
});
|
|
});
|
|
|
|
// ─── Multipage TIFF ────────────────────────────────────────────────
|
|
|
|
test.describe("Multipage TIFF handling", () => {
|
|
test("convert multipage TIFF to PNG", async ({ request }) => {
|
|
const multiTiff = formatFixture("multipage.tiff");
|
|
const res = await request.post("/api/v1/tools/convert", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "multipage.tiff", mimeType: "image/tiff", buffer: multiTiff },
|
|
settings: JSON.stringify({ format: "png" }),
|
|
},
|
|
});
|
|
// May return first page or all pages — verify no crash
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.downloadUrl || body.pages).toBeTruthy();
|
|
});
|
|
|
|
test("get info from multipage TIFF", async ({ request }) => {
|
|
const multiTiff = formatFixture("multipage.tiff");
|
|
const res = await request.post("/api/v1/tools/info", {
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
multipart: {
|
|
file: { name: "multipage.tiff", mimeType: "image/tiff", buffer: multiTiff },
|
|
},
|
|
});
|
|
expect(res.ok()).toBe(true);
|
|
const body = await res.json();
|
|
expect(body.width).toBeGreaterThan(0);
|
|
expect(body.height).toBeGreaterThan(0);
|
|
expect(body.format).toBeTruthy();
|
|
});
|
|
});
|