test: add integration test for CSV reference resolution
Add integration tests for `parseCsv` using fixture CSV files to verify that table references are correctly resolved across multiple files.
This commit is contained in:
parent
c3572a5b56
commit
eeaac92e39
|
|
@ -0,0 +1,3 @@
|
|||
id,user,total
|
||||
string,string,int
|
||||
o01,u01,100
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
# orders := ~order_rev(user)
|
||||
id,name
|
||||
string,string
|
||||
u01,Alice
|
||||
u02,Bob
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
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);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue