mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
Group 245 flat integration tests and 25 loose unit tests into
discoverable subdirectories per spec section 6:
integration/tools/{image,video,audio,document,data}/ (156 files)
integration/platform/ (64 files)
integration/generated/ (14 files)
integration/security/ (10 files)
unit/security/ (8 files, new subdir)
unit/api/ (7 files moved in)
unit/web/ (3 files moved in)
unit/shared/ (6 files moved in)
unit/image-engine/ (1 file moved in)
All moves via git mv (history preserved). Relative imports repaired
for both depth levels (platform/generated/security = +1, tools/ = +2):
static from-imports, dynamic import() calls, vi.mock() paths,
import.meta.dirname joins, and __dirname joins.
Vitest discovery unchanged (no test.include in config, recursive glob
matches subdirs, shard-by-hash unaffected). test-server.ts and
tool-route-drift.test.ts stay at integration root. fixtures/ untouched.
Parity gate: 13189 passing test names before = 13189 after (0 dropped).
125 lines
3.9 KiB
TypeScript
125 lines
3.9 KiB
TypeScript
import AdmZip from "adm-zip";
|
|
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 CSV = readFixture(fixtures.data.csv);
|
|
const TSV = readFixture(fixtures.data.tsv);
|
|
|
|
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);
|
|
|
|
async function runTool(settings: Record<string, unknown>) {
|
|
const { body, contentType } = createMultipartPayload([
|
|
{ name: "file", filename: "tiny.csv", contentType: "text/csv", content: CSV },
|
|
{ name: "settings", content: JSON.stringify(settings) },
|
|
]);
|
|
return testApp.app.inject({
|
|
method: "POST",
|
|
url: "/api/v1/tools/split-csv",
|
|
headers: { authorization: `Bearer ${adminToken}`, "content-type": contentType },
|
|
body,
|
|
});
|
|
}
|
|
|
|
describe("split-csv (pure JS, no skipIf)", () => {
|
|
it("splits with rowsPerFile 1 into a zip with 3 entries each containing the header", async () => {
|
|
const res = await runTool({ rowsPerFile: 1, keepHeader: true });
|
|
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);
|
|
|
|
// Verify zip magic (PK header: 0x50 0x4B)
|
|
expect(dl.rawPayload[0]).toBe(0x50);
|
|
expect(dl.rawPayload[1]).toBe(0x4b);
|
|
|
|
// Verify 3 entries via adm-zip (3 data rows = 3 parts)
|
|
const zip = new AdmZip(Buffer.from(dl.rawPayload));
|
|
const entries = zip.getEntries();
|
|
expect(entries.length).toBe(3);
|
|
|
|
// Each part should contain the header row "name,age"
|
|
for (const entry of entries) {
|
|
const text = entry.getData().toString("utf8");
|
|
expect(text).toContain("name,age");
|
|
}
|
|
}, 30_000);
|
|
|
|
it("splits a TSV file correctly with rowsPerFile 1", async () => {
|
|
const { body: tsvBody, contentType: tsvCt } = createMultipartPayload([
|
|
{
|
|
name: "file",
|
|
filename: "tiny.tsv",
|
|
contentType: "text/tab-separated-values",
|
|
content: TSV,
|
|
},
|
|
{ name: "settings", content: JSON.stringify({ rowsPerFile: 1, keepHeader: true }) },
|
|
]);
|
|
const res = await testApp.app.inject({
|
|
method: "POST",
|
|
url: "/api/v1/tools/split-csv",
|
|
headers: { authorization: `Bearer ${adminToken}`, "content-type": tsvCt },
|
|
body: tsvBody,
|
|
});
|
|
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);
|
|
|
|
const zip = new AdmZip(Buffer.from(dl.rawPayload));
|
|
const entries = zip.getEntries();
|
|
// TSV has 2 data rows -> 2 parts
|
|
expect(entries.length).toBe(2);
|
|
|
|
// Each part should contain the header
|
|
for (const entry of entries) {
|
|
const text = entry.getData().toString("utf8");
|
|
expect(text).toContain("id");
|
|
expect(text).toContain("name");
|
|
}
|
|
}, 30_000);
|
|
|
|
it("splits with keepHeader false omits the header from parts", async () => {
|
|
const res = await runTool({ rowsPerFile: 2, keepHeader: false });
|
|
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);
|
|
|
|
const zip = new AdmZip(Buffer.from(dl.rawPayload));
|
|
const entries = zip.getEntries();
|
|
// 4 rows (including header treated as data) / 2 = 2 parts
|
|
expect(entries.length).toBe(2);
|
|
}, 30_000);
|
|
});
|