mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
feat(tools): 2.0 phase 5 wave 4 - office, ebooks, data, archives (14 tools) (#224)
This commit is contained in:
@@ -5,6 +5,7 @@ import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
||||
import { buildTestApp, createMultipartPayload, loginAsAdmin, type TestApp } from "./test-server.js";
|
||||
|
||||
const CSV = readFileSync(join(__dirname, "..", "fixtures", "data", "tiny.csv"));
|
||||
const TSV = readFileSync(join(__dirname, "..", "fixtures", "data", "tiny.tsv"));
|
||||
|
||||
let testApp: TestApp;
|
||||
let adminToken: string;
|
||||
@@ -60,6 +61,45 @@ describe("split-csv (pure JS, no skipIf)", () => {
|
||||
}
|
||||
}, 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);
|
||||
|
||||
Reference in New Issue
Block a user