mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
Codemod rewrites all five ad-hoc fixture-path styles to import from the typed registry (tests/fixtures/index.ts): - join(__dirname, "..", "fixtures", ...) inline patterns (100 files) - const FIXTURES = join(__dirname, ...) + join(FIXTURES, ...) (92 files) - process.cwd()-based paths (10 files) - path.resolve(__dirname, ...) patterns (5 files) Registry extended with 8 new keys (portraitJpg, portraitHeic, motorcycle, svgLogo, barcodeAvif, qrAvif, crossFormatChat, multipageTiff) and directory accessors (fixtureDir, fixtureRoot). Dynamic directory scanners (format-matrix-generated, format-matrix-multimodal, hostile-inputs) preserved via fixtureDir imports. No fixtures swapped, bytes identical. Parity gate: dropped 0, net-new 388.
72 lines
2.7 KiB
TypeScript
72 lines
2.7 KiB
TypeScript
import { mkdtempSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { ffmpegAvailable, probeMedia } from "@snapotter/media-engine";
|
|
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
import { fixtures, readFixture } from "../fixtures/index.js";
|
|
import { buildTestApp, createMultipartPayload, loginAsAdmin, type TestApp } from "./test-server.js";
|
|
|
|
const MP3 = readFixture(fixtures.audio.tiny("mp3"));
|
|
const WAV = readFixture(fixtures.audio.tiny("wav"));
|
|
|
|
let testApp: TestApp;
|
|
let adminToken: string;
|
|
|
|
beforeAll(async () => {
|
|
testApp = await buildTestApp();
|
|
adminToken = await loginAsAdmin(testApp.app);
|
|
}, 30_000);
|
|
|
|
afterAll(async () => {
|
|
await testApp.cleanup();
|
|
}, 10_000);
|
|
|
|
describe.skipIf(!ffmpegAvailable())("merge-audio (requires ffmpeg)", () => {
|
|
it("merges two audio files with different sample rates", async () => {
|
|
const { body, contentType } = createMultipartPayload([
|
|
{ name: "file", filename: "tiny.mp3", contentType: "audio/mpeg", content: MP3 },
|
|
{ name: "file", filename: "tiny.wav", contentType: "audio/wav", content: WAV },
|
|
{ name: "settings", content: JSON.stringify({ format: "mp3" }) },
|
|
]);
|
|
const res = await testApp.app.inject({
|
|
method: "POST",
|
|
url: "/api/v1/tools/merge-audio",
|
|
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
|
|
body,
|
|
});
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
const envelope = JSON.parse(res.body);
|
|
expect(envelope.downloadUrl).toBeDefined();
|
|
|
|
const dl = await testApp.app.inject({ method: "GET", url: envelope.downloadUrl });
|
|
expect(dl.statusCode).toBe(200);
|
|
|
|
// Probe: duration should be close to 1.044 + 1.0 = 2.044s
|
|
const tmpDir = mkdtempSync(join(tmpdir(), "merge-audio-test-"));
|
|
const probeFile = join(tmpDir, "merged.mp3");
|
|
writeFileSync(probeFile, dl.rawPayload);
|
|
const info = await probeMedia(probeFile);
|
|
const expected = 2.04;
|
|
expect(info.durationS).toBeDefined();
|
|
expect(Math.abs((info.durationS ?? 0) - expected)).toBeLessThan(expected * 0.3);
|
|
}, 60_000);
|
|
|
|
it("rejects when only one file is provided", async () => {
|
|
const { body, contentType } = createMultipartPayload([
|
|
{ name: "file", filename: "tiny.mp3", contentType: "audio/mpeg", content: MP3 },
|
|
{ name: "settings", content: JSON.stringify({}) },
|
|
]);
|
|
const res = await testApp.app.inject({
|
|
method: "POST",
|
|
url: "/api/v1/tools/merge-audio",
|
|
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
|
|
body,
|
|
});
|
|
|
|
expect(res.statusCode).toBe(422);
|
|
const parsed = JSON.parse(res.body);
|
|
expect(parsed.details).toMatch(/at least two/i);
|
|
}, 60_000);
|
|
});
|