mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
test: expand API and GUI test coverage across all tools
Add ~500 new E2E tests and ~300 new integration tests covering: - 24 new GUI E2E specs: navigation, responsive layout, keyboard shortcuts, tool UI for all 35 non-AI tools, batch/pipeline workflows, settings/RBAC, visual regression, accessibility, and performance budgets - 3 new E2E-Docker specs: batch workflows, advanced pipelines, cross-format - 1 new adversarial integration test: memory pressure, corrupted files, unicode filenames, extreme dimensions, pipeline/batch edge cases - 29 expanded integration test files: HEIC/HEIF input, large files, parameter boundaries, batch processing, format edge cases across all tools - Cross-format matrix expanded: 641 tests covering every tool x 18 formats - AI bridge unit tests expanded: lifecycle, tool modules, error propagation - Unit test gaps filled: analytics, tool-registry, web stores Also fixes: - vitest.config.ts: exclude e2e-docs and e2e-landing from Vitest runner - AI E2E specs: add sidecar health check to skip gracefully when Python AI backend is not running instead of timing out
This commit is contained in:
@@ -879,4 +879,209 @@ describe("svg-to-raster", () => {
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.headers["content-type"]).toBe("application/zip");
|
||||
});
|
||||
|
||||
// ── Branch coverage: invalid SVG content triggers conversion error ─
|
||||
|
||||
it("returns 422 for malformed SVG that passes isSvgBuffer but fails Sharp", async () => {
|
||||
// An SVG with broken XML structure that passes initial check but may fail conversion
|
||||
const brokenSvg = Buffer.from(
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><invalid-element/></svg>',
|
||||
);
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "broken.svg", contentType: "image/svg+xml", content: brokenSvg },
|
||||
{ name: "settings", content: JSON.stringify({ outputFormat: "png" }) },
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/svg-to-raster",
|
||||
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
|
||||
body,
|
||||
});
|
||||
|
||||
// Either succeeds (Sharp handles unknown elements gracefully) or returns 422
|
||||
expect([200, 422]).toContain(res.statusCode);
|
||||
});
|
||||
|
||||
// ── Branch coverage: width exceeding max rejects ───────────────────
|
||||
|
||||
it("rejects width exceeding maximum (65536)", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "test.svg", contentType: "image/svg+xml", content: SVG },
|
||||
{ name: "settings", content: JSON.stringify({ width: 70000 }) },
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/svg-to-raster",
|
||||
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
|
||||
body,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
|
||||
// ── Branch coverage: height exceeding max rejects ──────────────────
|
||||
|
||||
it("rejects height exceeding maximum (65536)", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "test.svg", contentType: "image/svg+xml", content: SVG },
|
||||
{ name: "settings", content: JSON.stringify({ height: 70000 }) },
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/svg-to-raster",
|
||||
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
|
||||
body,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
|
||||
// ── Branch coverage: quality at boundary values ────────────────────
|
||||
|
||||
it("accepts quality at minimum (1)", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "test.svg", contentType: "image/svg+xml", content: SVG },
|
||||
{ name: "settings", content: JSON.stringify({ outputFormat: "jpg", quality: 1 }) },
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/svg-to-raster",
|
||||
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
|
||||
body,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
const json = JSON.parse(res.body);
|
||||
expect(json.processedSize).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
// ── Branch coverage: quality above max rejects ─────────────────────
|
||||
|
||||
it("rejects quality above maximum (100)", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "test.svg", contentType: "image/svg+xml", content: SVG },
|
||||
{ name: "settings", content: JSON.stringify({ quality: 101 }) },
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/svg-to-raster",
|
||||
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
|
||||
body,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
|
||||
// ── Branch coverage: invalid outputFormat rejects ──────────────────
|
||||
|
||||
it("rejects invalid output format", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "test.svg", contentType: "image/svg+xml", content: SVG },
|
||||
{ name: "settings", content: JSON.stringify({ outputFormat: "bmp" }) },
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/svg-to-raster",
|
||||
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
|
||||
body,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
|
||||
// ── Branch coverage: batch with heif output ────────────────────────
|
||||
|
||||
it("batch converts SVGs to heif format", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "a.svg", contentType: "image/svg+xml", content: SVG },
|
||||
{ name: "file", filename: "b.svg", contentType: "image/svg+xml", content: SVG },
|
||||
{ name: "settings", content: JSON.stringify({ outputFormat: "heif" }) },
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/svg-to-raster/batch",
|
||||
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
|
||||
body,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.headers["content-type"]).toBe("application/zip");
|
||||
});
|
||||
|
||||
// ── Branch coverage: batch with 5+ SVG files ──────────────────────
|
||||
|
||||
it("batch converts 5+ SVG files", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "a.svg", contentType: "image/svg+xml", content: SVG },
|
||||
{ name: "file", filename: "b.svg", contentType: "image/svg+xml", content: SVG },
|
||||
{ name: "file", filename: "c.svg", contentType: "image/svg+xml", content: SVG },
|
||||
{ name: "file", filename: "d.svg", contentType: "image/svg+xml", content: SVG },
|
||||
{ name: "file", filename: "e.svg", contentType: "image/svg+xml", content: SVG },
|
||||
{ name: "settings", content: JSON.stringify({ outputFormat: "png" }) },
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/svg-to-raster/batch",
|
||||
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
|
||||
body,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.headers["content-type"]).toBe("application/zip");
|
||||
const fileResults = JSON.parse(res.headers["x-file-results"] as string);
|
||||
expect(Object.keys(fileResults).length).toBe(5);
|
||||
});
|
||||
|
||||
// ── Branch coverage: SVG without .svg extension ────────────────────
|
||||
|
||||
it("handles SVG file without .svg extension in filename", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "icon", contentType: "image/svg+xml", content: SVG },
|
||||
{ name: "settings", content: JSON.stringify({ outputFormat: "png" }) },
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/svg-to-raster",
|
||||
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.processedSize).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
// ── Branch coverage: heif + background color combination ───────────
|
||||
|
||||
it("converts to heif format with background color applied", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "test.svg", contentType: "image/svg+xml", content: SVG },
|
||||
{
|
||||
name: "settings",
|
||||
content: JSON.stringify({ outputFormat: "heif", backgroundColor: "#FF0000" }),
|
||||
},
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/svg-to-raster",
|
||||
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.previewUrl).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user