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:
hypercross 2026-04-20 00:21:41 +08:00
parent c3572a5b56
commit eeaac92e39
3 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,3 @@
id,user,total
string,string,int
o01,u01,100
1 id user total
2 string string int
3 o01 u01 100

View File

@ -0,0 +1,5 @@
# orders := ~order_rev(user)
id,name
string,string
u01,Alice
u02,Bob
1 # orders := ~order_rev(user)
2 id,name
3 string,string
4 u01,Alice
5 u02,Bob

View File

@ -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);
});
});