test: add unit and integration test suites

- Extract evaluateCondition + rule types into src/lib/rules.ts for testability
- 48 unit tests for evaluateCondition (all fields/operators) and formatCategory
- 21 integration tests for getTransactions filters and getParticipantBalances
- Vitest configs for unit (vitest.config.ts) and integration (vitest.integration.config.ts)
- setup-test-db.sh creates personal_test DB from production schema via pg_dump
- Use vi.doMock + dynamic import pattern to isolate test DB from Prisma singleton
This commit is contained in:
2026-04-01 19:59:29 +11:00
parent 7491e70a15
commit 1296555f17
12 changed files with 2036 additions and 74 deletions
+24
View File
@@ -0,0 +1,24 @@
import { defineConfig } from "vitest/config";
import tsconfigPaths from "vite-tsconfig-paths";
import { readFileSync, existsSync } from "fs";
import { resolve } from "path";
// Load .env.test into process.env HERE, at config-load time.
// Forked workers inherit the parent process env, so Prisma's singleton
// will see the test DATABASE_URL when db.ts is first imported.
const envTestPath = resolve(__dirname, ".env.test");
if (existsSync(envTestPath)) {
for (const line of readFileSync(envTestPath, "utf-8").split("\n")) {
const m = line.match(/^([^#=]+)=(.*)/);
if (m) process.env[m[1].trim()] = m[2].trim();
}
}
export default defineConfig({
plugins: [tsconfigPaths()],
test: {
environment: "node",
include: ["src/__tests__/integration/**/*.test.ts"],
pool: "forks",
},
});