32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
|
|
import { describe, it, expect } from "vitest";
|
||
|
|
import { parseCsv } from "./loader";
|
||
|
|
import * as path from "path";
|
||
|
|
import * as fs from "fs";
|
||
|
|
|
||
|
|
const fixturesDir = path.join(__dirname, "fixtures");
|
||
|
|
|
||
|
|
describe("parseCsv - integration: loading two CSV tables from fixtures", () => {
|
||
|
|
it("should load user_rev and order_rev tables and resolve orders array with correct length", () => {
|
||
|
|
const userCsv = fs.readFileSync(
|
||
|
|
path.join(fixturesDir, "user_rev.csv"),
|
||
|
|
"utf-8",
|
||
|
|
);
|
||
|
|
|
||
|
|
const result = parseCsv(userCsv, {
|
||
|
|
emitTypes: false,
|
||
|
|
currentFilePath: path.join(fixturesDir, "user_rev.csv"),
|
||
|
|
});
|
||
|
|
|
||
|
|
expect(result.data).toHaveLength(2);
|
||
|
|
|
||
|
|
// Alice (u01) should have 1 order
|
||
|
|
const aliceOrders = result.data[0].orders as Record<string, unknown>[];
|
||
|
|
expect(aliceOrders).toHaveLength(1);
|
||
|
|
expect(aliceOrders[0].id).toBe("o01");
|
||
|
|
|
||
|
|
// Bob (u02) should have 0 orders
|
||
|
|
const bobOrders = result.data[1].orders as Record<string, unknown>[];
|
||
|
|
expect(bobOrders).toHaveLength(0);
|
||
|
|
});
|
||
|
|
});
|