Files
SnapOtter/tests/integration/text-overlay.test.ts
T
SnapOtter a0556772e8 test: expand coverage across all layers -- 1,268 new tests, fix replace-color div-by-zero
14-agent parallel test expansion covering integration, unit, E2E, E2E-Docker,
cross-format matrix, adversarial, GUI navigation/tools/settings/visual/a11y/perf.

- Integration: expand 23 tool test files with HEIC, stress, batch, edge cases
- Unit: close coverage gaps in image-engine, stores, lib (metadata, auto-enhance,
  connection-store, lazy-with-retry, collage/file-store HEIC preview)
- AI bridge: 141 new tests for dispatcher buffering, crash recovery, OOM/segfault
- Cross-format: 794 parameterized tests (16 formats x 12 tools + no-crash matrix)
- Adversarial: memory stress (50x large file), zero-byte, corrupted headers, unicode
- E2E-Docker: expand 8 spec files with dimension verification, pipeline chains
- GUI E2E: tool UI settings/interactions for all 47 tools, remove all test.skip,
  RBAC per-role verification, visual screenshot naming, cross-browser smoke tests,
  a11y ARIA/focus/contrast, performance budgets, 15-tool stability test
- Fix: replace-color.ts tolerance=0 caused division-by-zero producing NaN pixels

Total: 8,958 tests passing across 202 files. Zero failures, zero skips.
2026-05-09 18:02:58 +08:00

909 lines
31 KiB
TypeScript

/**
* Integration tests for the text-overlay tool.
*
* Adds styled text onto an image with position, color, background box,
* and shadow options.
*/
import { readFileSync } from "node:fs";
import { join } from "node:path";
import sharp from "sharp";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { buildTestApp, createMultipartPayload, loginAsAdmin, type TestApp } from "./test-server.js";
const FIXTURES = join(__dirname, "..", "fixtures");
const PNG = readFileSync(join(FIXTURES, "test-200x150.png"));
let testApp: TestApp;
let app: TestApp["app"];
let adminToken: string;
beforeAll(async () => {
testApp = await buildTestApp();
app = testApp.app;
adminToken = await loginAsAdmin(app);
}, 30_000);
afterAll(async () => {
await testApp.cleanup();
}, 10_000);
describe("text-overlay", () => {
it("adds text overlay with default settings", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{ name: "settings", content: JSON.stringify({ text: "Hello World" }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.downloadUrl).toBeDefined();
expect(json.jobId).toBeDefined();
expect(json.processedSize).toBeGreaterThan(0);
});
it("output differs from input", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{ name: "settings", content: JSON.stringify({ text: "Overlay" }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
const dlRes = await app.inject({
method: "GET",
url: json.downloadUrl,
headers: { authorization: `Bearer ${adminToken}` },
});
expect(dlRes.statusCode).toBe(200);
expect(Buffer.from(dlRes.rawPayload).equals(PNG)).toBe(false);
});
it.each(["top", "center", "bottom"] as const)("supports position: %s", async (position) => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{ name: "settings", content: JSON.stringify({ text: "Pos", position }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
});
it("applies custom color and font size", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{
name: "settings",
content: JSON.stringify({ text: "Styled", color: "#FF0000", fontSize: 24 }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
});
it("enables background box", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{
name: "settings",
content: JSON.stringify({
text: "With BG",
backgroundBox: true,
backgroundColor: "#333333",
}),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
});
it("disables shadow", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{
name: "settings",
content: JSON.stringify({ text: "No Shadow", shadow: false }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
});
it("rejects request without a file", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "settings", content: JSON.stringify({ text: "NoFile" }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(400);
});
it("rejects request without text", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{ name: "settings", content: JSON.stringify({}) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(400);
const json = JSON.parse(res.body);
expect(json.error).toContain("Invalid settings");
});
it("rejects invalid color format", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{ name: "settings", content: JSON.stringify({ text: "Bad", color: "blue" }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(400);
});
it("rejects fontSize out of range", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{ name: "settings", content: JSON.stringify({ text: "Big", fontSize: 999 }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(400);
});
// ── Branch coverage: lines 40-41 (metadata fallback for width/height) ──
it("handles tiny 1x1 image input", async () => {
const TINY = readFileSync(join(FIXTURES, "test-1x1.png"));
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "tiny.png", contentType: "image/png", content: TINY },
{ name: "settings", content: JSON.stringify({ text: "Tiny", position: "center" }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.downloadUrl).toBeDefined();
});
// ── HEIC input handling ───────────────────────────────────────────
it("handles HEIC input", { timeout: 120_000 }, async () => {
const HEIC = readFileSync(join(FIXTURES, "test-200x150.heic"));
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "photo.heic", contentType: "image/heic", content: HEIC },
{ name: "settings", content: JSON.stringify({ text: "HEIC overlay" }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.downloadUrl).toBeDefined();
});
// ── Background box + shadow combined ──────────────────────────────
it("combines background box and shadow with position top", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{
name: "settings",
content: JSON.stringify({
text: "Combined",
position: "top",
backgroundBox: true,
backgroundColor: "#FF0000",
shadow: true,
}),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.downloadUrl).toBeDefined();
});
// ── XML escaping in text ──────────────────────────────────────────
it("handles special XML characters in overlay text", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{
name: "settings",
content: JSON.stringify({ text: '<Test & "Quotes">' }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
});
// ── JPEG format preserves correctly ───────────────────────────────
it("preserves JPEG format", async () => {
const JPG = readFileSync(join(FIXTURES, "test-100x100.jpg"));
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.jpg", contentType: "image/jpeg", content: JPG },
{ name: "settings", content: JSON.stringify({ text: "JPEG" }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
const dlRes = await app.inject({
method: "GET",
url: json.downloadUrl,
headers: { authorization: `Bearer ${adminToken}` },
});
const meta = await sharp(dlRes.rawPayload).metadata();
expect(meta.format).toBe("jpeg");
});
// ── Large file (stress test) ──────────────────────────────────────
it("handles stress-large.jpg", async () => {
const LARGE = readFileSync(join(FIXTURES, "content", "stress-large.jpg"));
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "large.jpg", contentType: "image/jpeg", content: LARGE },
{ name: "settings", content: JSON.stringify({ text: "Stress test", fontSize: 100 }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.processedSize).toBeGreaterThan(0);
});
// ── No shadow, no background box ──────────────────────────────────
it("renders text with no shadow and no background box", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{
name: "settings",
content: JSON.stringify({ text: "Minimal", shadow: false, backgroundBox: false }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
});
// ── Rejects text exceeding max length ────────────────────────────
it("rejects text exceeding max length (>500 chars)", async () => {
const longText = "B".repeat(501);
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{ name: "settings", content: JSON.stringify({ text: longText }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(400);
});
// ── WebP input ───────────────────────────────────────────────────
it("processes WebP input", async () => {
const WEBP = readFileSync(join(FIXTURES, "test-50x50.webp"));
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.webp", contentType: "image/webp", content: WEBP },
{ name: "settings", content: JSON.stringify({ text: "WebP overlay" }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.downloadUrl).toBeDefined();
});
// ── Rejects unauthenticated request ──────────────────────────────
it("rejects unauthenticated request", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{ name: "settings", content: JSON.stringify({ text: "Unauth" }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { "content-type": contentType },
body,
});
expect(res.statusCode).toBe(401);
});
// ── Background box with bottom position ──────────────────────────
it("applies background box at bottom position", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{
name: "settings",
content: JSON.stringify({
text: "Bottom box",
position: "bottom",
backgroundBox: true,
backgroundColor: "#0000FF",
shadow: true,
}),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.downloadUrl).toBeDefined();
});
// ── Max font size ────────────────────────────────────────────────
it("applies maximum font size (200)", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{
name: "settings",
content: JSON.stringify({ text: "Max", fontSize: 200 }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
});
// ── Min font size ────────────────────────────────────────────────
it("applies minimum font size (8)", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{
name: "settings",
content: JSON.stringify({ text: "Tiny text", fontSize: 8 }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
});
// ── Invalid backgroundColor format ───────────────────────────────
it("rejects invalid backgroundColor format", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{
name: "settings",
content: JSON.stringify({
text: "Bad BG",
backgroundBox: true,
backgroundColor: "green",
}),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(400);
});
// ── HEIF input ───────────────────────────────────────────────────
it(
"handles HEIF input (motorcycle.heif)",
{ timeout: 120_000 },
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({ text: "HEIF overlay" }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.downloadUrl).toBeDefined();
},
60_000,
);
// ── Animated GIF input ──────────────────────────────────────────
it("handles animated GIF input", 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({ text: "GIF overlay" }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.downloadUrl).toBeDefined();
});
// ── SVG input ───────────────────────────────────────────────────
it("handles SVG input", 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({ text: "SVG overlay" }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.downloadUrl).toBeDefined();
});
// ── Preserves image dimensions ───────────────────────────────────
it("preserves image dimensions after text overlay", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{ name: "settings", content: JSON.stringify({ text: "Dim test" }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
const dlRes = await app.inject({
method: "GET",
url: json.downloadUrl,
headers: { authorization: `Bearer ${adminToken}` },
});
const meta = await sharp(dlRes.rawPayload).metadata();
expect(meta.width).toBe(200);
expect(meta.height).toBe(150);
});
// ── Multiline text support ───────────────────────────────────────
it("handles multiline text with newlines", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{
name: "settings",
content: JSON.stringify({ text: "Line 1\nLine 2\nLine 3" }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.downloadUrl).toBeDefined();
});
// ── TIFF input format ───────────────────────────────────────────
it("processes TIFF input format", async () => {
const TIFF = readFileSync(join(FIXTURES, "formats", "sample.tiff"));
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.tiff", contentType: "image/tiff", content: TIFF },
{ name: "settings", content: JSON.stringify({ text: "TIFF overlay" }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.downloadUrl).toBeDefined();
});
// ── Rejects fontSize below minimum ──────────────────────────────
it("rejects fontSize below minimum (<8)", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{ name: "settings", content: JSON.stringify({ text: "Bad", fontSize: 7 }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(400);
});
// ── Rejects fontSize above maximum ──────────────────────────────
it("rejects fontSize above maximum (>200)", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{ name: "settings", content: JSON.stringify({ text: "Bad", fontSize: 201 }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(400);
});
// ── Background box with different positions ─────────────────────
it("applies background box at center position", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{
name: "settings",
content: JSON.stringify({
text: "Center box",
position: "center",
backgroundBox: true,
backgroundColor: "#990000",
}),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.downloadUrl).toBeDefined();
});
// ── Invalid position value ──────────────────────────────────────
it("rejects invalid position value", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{
name: "settings",
content: JSON.stringify({ text: "Bad", position: "left" }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(400);
});
// ── Unicode text support ────────────────────────────────────────
it("handles unicode text characters", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{
name: "settings",
content: JSON.stringify({ text: "Hello World 123" }),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.downloadUrl).toBeDefined();
});
// ── All parameters combined ──────────────────────────────────────
it("applies all parameters at once", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{
name: "settings",
content: JSON.stringify({
text: "Full",
fontSize: 24,
color: "#00FF00",
position: "center",
backgroundBox: true,
backgroundColor: "#333333",
shadow: true,
}),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.downloadUrl).toBeDefined();
});
// ── Rejects invalid settings JSON ───────────────────────────────
it("rejects invalid settings JSON", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{ name: "settings", content: "not-valid-json" },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(400);
});
// ── Empty text rejected ─────────────────────────────────────────
it("rejects empty text string", async () => {
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
{ name: "settings", content: JSON.stringify({ text: "" }) },
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(400);
});
// ── TIFF input with all options ─────────────────────────────────
it("processes TIFF input with background box and shadow at top position", async () => {
const TIFF = readFileSync(join(FIXTURES, "formats", "sample.tiff"));
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "test.tiff", contentType: "image/tiff", content: TIFF },
{
name: "settings",
content: JSON.stringify({
text: "TIFF Full",
position: "top",
fontSize: 24,
color: "#FFFF00",
backgroundBox: true,
backgroundColor: "#000000",
shadow: true,
}),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.downloadUrl).toBeDefined();
});
// ── Stress large file with background box ───────────────────────
it("handles stress-large.jpg with background box at bottom", async () => {
const LARGE = readFileSync(join(FIXTURES, "content", "stress-large.jpg"));
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "large.jpg", contentType: "image/jpeg", content: LARGE },
{
name: "settings",
content: JSON.stringify({
text: "Large Image Caption",
position: "bottom",
backgroundBox: true,
backgroundColor: "#222222",
fontSize: 48,
}),
},
]);
const res = await app.inject({
method: "POST",
url: "/api/v1/tools/text-overlay",
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
body,
});
expect(res.statusCode).toBe(200);
const json = JSON.parse(res.body);
expect(json.processedSize).toBeGreaterThan(0);
});
});