Testing Strategy
Relevant source files
The following files were used as context for generating this wiki page:
The testing strategy for Driveway Estimator Pro is a multi-layered approach designed to ensure high reliability across the application's core functions, including AI-powered edge detection, material pricing calculations, and project sharing workflows. The project utilizes Vitest as its primary testing framework for unit and integration tests, maintaining a suite of tests that validate both business logic and API integrity.
Sources: README.md:245-255, todo.md:69-72
Core Testing Categories
The project categorizes its testing efforts into four main pillars, as outlined in the implementation roadmap and documentation.
| Category | Scope | Key Files |
|---|---|---|
| Unit Testing | Individual services and utility functions (Pricing, PDF, Calculations). | server/services/pricing.test.ts, server/services/pdfExport.test.ts |
| Integration Testing | tRPC procedures, database interactions, and authentication middleware. | server/routers/projects.test.ts |
| End-to-End (E2E) | Complete workflows from photo capture to contractor sharing. | References in todo.md (Phase 5) |
| Edge Detection | Accuracy of LLM-based boundary detection and square footage math. | server/routers/projects.ts, README.md |
Sources: README.md:245-255, todo.md:69-72
Backend Service Testing
Backend services are tested for mathematical accuracy and data integrity using unit tests. This ensures that the material estimates provided to users are reliable.
Pricing and Quantity Calculations
The Pricing Service tests focus on the logic that converts physical measurements into material weights and financial costs.
- Quantity Logic: Tests verify that
calculateMaterialQuantityhandles various depths, surface areas, and material densities (e.g., Hot Mix Asphalt vs. Gravel). - Cost Logic: Tests for
calculateTotalCostensure that price string parsing and zero/null values are handled gracefully.
Sources: server/services/pricing.test.ts:5-56, server/services/pricing.ts:100-145
PDF Export Service
The PDF service is tested to ensure that the document generator can create valid binary buffers and handle various project states.
The diagram shows the sequence of a PDF service unit test.
Sources: server/services/pdfExport.test.ts:7-65
Router and API Integration Testing
API testing is performed on tRPC procedures using mocked contexts. This allows for testing authenticated and public procedures without requiring a live session or a frontend.
tRPC Context Mocking
Integration tests use a createMockContext utility to simulate user states (Admin, User, or Unauthorized). This is used to verify that protected procedures correctly block unauthenticated requests.
Sources: server/routers/projects.test.ts:7-31
Testing Workflow for API Procedures
The following sequence diagram illustrates how a tRPC procedure like getPricing is tested:
This diagram visualizes the interaction between the router caller and internal services during an integration test.
Sources: server/routers/projects.test.ts:53-88, server/routers/projects.ts:91-125
End-to-End Workflow Testing
The project tracks "End-to-End" success through its implementation roadmap, identifying critical paths that must remain functional.
- Project Lifecycle: Tests verify the flow: Capture → Measure → Select Material → Generate Preview → Save Project.
- Sharing Lifecycle: Tests verify the flow: Share Project → Send Email → Contractor Access via Token.
- Location Accuracy: Verification of geolocation and ZIP-code based pricing accuracy.
Sources: todo.md:37-43, server/routers/projects.test.ts:105-121
Automated Test Execution
Tests are executed via the command line using the project's scripts.
- Full Suite:
pnpm testruns all backend and service tests. - Focused Tests: Specific files can be targeted, such as
pnpm test server/services/pricing.test.ts. - Watch Mode:
pnpm test --watchis used during development for immediate feedback.
Sources: README.md:120-130
Test Configuration Details
The testing environment is configured via vitest.config.ts. In Phase 2 of the development roadmap, the project achieved a milestone of 22 passing tests covering backend procedures, and reached 26 passing tests after completing Phase 5 integration.
Sources: todo.md:20, 38
Summary of Testable Logic
| Service / Router | Key Testable Function | logic Verified |
|---|---|---|
pricing.ts | calculateMaterialQuantity | Cubic yards to tons conversion per material density. |
pricing.ts | calculateTotalCost | Multiplication of tonnage and parsed price strings. |
projects.ts | list | Authentication protection and user-specific project filtering. |
projects.ts | getSharedProject | Public access via unique shareToken without login. |
pdfExport.ts | generateProjectPDF | handling of null notes and varied material types in document generation. |
Sources: server/services/pricing.test.ts:1-56, server/routers/projects.test.ts:33-121, server/services/pdfExport.test.ts:33-65