PolyWood Price Builder

Testing

Current Test Stack

  • Runner: Vitest (npm test)
  • Config: vitest.config.ts
    • Node test environment
    • @ alias resolves to src

Current Coverage (High-Value Tests)

Unit tests (src/lib/*)

  1. src/lib/rules.test.ts
    • Verifies pipeline execution order and rounding behavior (multiply -> percentAdjust -> roundNearest9).
  2. src/lib/tier-pricing-policy.test.ts
    • Verifies circular dependency handling in tier computation while independent tiers still compute.
  3. src/lib/products-csv.test.ts
    • Verifies CSV header alias handling (cost accepted as cogs) and product field mapping.

API route tests (src/app/api/*)

  1. src/app/api/rulesets/route.test.ts
    • POST /api/rulesets returns 400 when ruleset id is missing.
  2. src/app/api/rule-assignments/route.test.ts
    • PUT /api/rule-assignments returns 400 when an assignment references an unknown ruleset.
  3. src/app/api/products/upload/route.test.ts
    • Returns 400 for multipart uploads missing the file field.
    • Verifies raw CSV uploads call storage and return Cache-Control: no-store.

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.