Testing
Current Test Stack
- Runner: Vitest (
npm test) - Config:
vitest.config.ts- Node test environment
@alias resolves tosrc
Current Coverage (High-Value Tests)
Unit tests (src/lib/*)
src/lib/rules.test.ts- Verifies pipeline execution order and rounding behavior (
multiply -> percentAdjust -> roundNearest9).
- Verifies pipeline execution order and rounding behavior (
src/lib/tier-pricing-policy.test.ts- Verifies circular dependency handling in tier computation while independent tiers still compute.
src/lib/products-csv.test.ts- Verifies CSV header alias handling (
costaccepted ascogs) and product field mapping.
- Verifies CSV header alias handling (
API route tests (src/app/api/*)
src/app/api/rulesets/route.test.tsPOST /api/rulesetsreturns400when rulesetidis missing.
src/app/api/rule-assignments/route.test.tsPUT /api/rule-assignmentsreturns400when an assignment references an unknown ruleset.
src/app/api/products/upload/route.test.ts- Returns
400for multipart uploads missing thefilefield. - Verifies raw CSV uploads call storage and return
Cache-Control: no-store.
- Returns
How to Run Tests
npm test
For local quality checks:
npm test
npm run lint
npx tsc --noEmit
Testing Approach
- Prioritize logic-heavy pure modules and API validation boundaries first.
- Keep tests deterministic by mocking S3/storage adapters in route tests.
- Add E2E later for critical user flows (ruleset save/assign/export) once unit+route coverage is stable.