mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
test: comprehensive test coverage expansion (+965 tests)
Add 42 new test files covering all untested tool routes, image engine internals, AI sidecar bridge, Zustand stores, and cross-format compatibility. Expand e2e-docker suite with 7 spec files covering all 48 tools against a real Docker container. Unit tests: - Image engine: format detection, MIME mapping, metadata parsing, pipeline - AI bridge: sidecar lifecycle, all 11 tool functions (mocked) - Web stores: 14 Zustand stores (collage, settings, features, analytics, etc.) - API helpers: format decoders, page range, file validation Integration tests: - 25 tool routes that had zero dedicated tests - Cross-format matrix: 17 input formats x 3 tools - Edge cases: zero-byte files, corrupted headers, path traversal, XSS, SQL injection - Concurrent request handling and pipeline edge cases E2E-Docker (Playwright against real container): - 7 spec files: essential, adjustment, conversion, creative, utility, AI, pipeline - Custom buildMultipart helper for multi-file tool uploads - AI tools gracefully skip when sidecar not installed Fixtures: - Organized test media: formats/ (18 formats) + content/ (17 content types) - Reduced from 3.1 GB unorganized samples to 33 MB structured fixtures Bug fix: - color-adjustments: gamma exposure used invalid single-param gamma() for positive values; fixed to use two-param gamma(gammaIn, gammaOut) form
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { decodeToSharpCompat, needsCliDecode } from "../../../apps/api/src/lib/format-decoders.js";
|
||||
|
||||
// ==========================================================================
|
||||
// needsCliDecode
|
||||
// ==========================================================================
|
||||
|
||||
describe("needsCliDecode", () => {
|
||||
it("returns true for raw format", () => {
|
||||
expect(needsCliDecode("raw")).toBe(true);
|
||||
});
|
||||
|
||||
it("returns true for ico format", () => {
|
||||
expect(needsCliDecode("ico")).toBe(true);
|
||||
});
|
||||
|
||||
it("returns true for tga format", () => {
|
||||
expect(needsCliDecode("tga")).toBe(true);
|
||||
});
|
||||
|
||||
it("returns true for psd format", () => {
|
||||
expect(needsCliDecode("psd")).toBe(true);
|
||||
});
|
||||
|
||||
it("returns true for exr format", () => {
|
||||
expect(needsCliDecode("exr")).toBe(true);
|
||||
});
|
||||
|
||||
it("returns true for hdr format", () => {
|
||||
expect(needsCliDecode("hdr")).toBe(true);
|
||||
});
|
||||
|
||||
it("returns false for jpeg format", () => {
|
||||
expect(needsCliDecode("jpeg")).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false for png format", () => {
|
||||
expect(needsCliDecode("png")).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false for webp format", () => {
|
||||
expect(needsCliDecode("webp")).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false for gif format", () => {
|
||||
expect(needsCliDecode("gif")).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false for avif format", () => {
|
||||
expect(needsCliDecode("avif")).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false for svg format", () => {
|
||||
expect(needsCliDecode("svg")).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false for empty string", () => {
|
||||
expect(needsCliDecode("")).toBe(false);
|
||||
});
|
||||
|
||||
it("returns false for unknown format", () => {
|
||||
expect(needsCliDecode("bmp")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
// ==========================================================================
|
||||
// decodeToSharpCompat — routing logic (default passthrough)
|
||||
// ==========================================================================
|
||||
|
||||
describe("decodeToSharpCompat", () => {
|
||||
it("returns buffer unchanged for unknown/native formats", async () => {
|
||||
const buf = Buffer.from("test data");
|
||||
const result = await decodeToSharpCompat(buf, "jpeg");
|
||||
expect(result).toBe(buf);
|
||||
});
|
||||
|
||||
it("returns buffer unchanged for png format", async () => {
|
||||
const buf = Buffer.from("png data");
|
||||
const result = await decodeToSharpCompat(buf, "png");
|
||||
expect(result).toBe(buf);
|
||||
});
|
||||
|
||||
it("returns buffer unchanged for empty format string", async () => {
|
||||
const buf = Buffer.from("some bytes");
|
||||
const result = await decodeToSharpCompat(buf, "");
|
||||
expect(result).toBe(buf);
|
||||
});
|
||||
|
||||
it("returns buffer unchanged for webp format", async () => {
|
||||
const buf = Buffer.from("webp");
|
||||
const result = await decodeToSharpCompat(buf, "webp");
|
||||
expect(result).toBe(buf);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user