Testing Strategy
Relevant source files
The following files were used as context for generating this wiki page:
The AtlasCleanAI Enterprise testing strategy ensures the reliability of AI-powered cleaning management services through a multi-layered verification approach. It covers individual logic in use cases, end-to-end integration of API routes, and the validation of AI-driven scheduling and pricing components.
The strategy employs Jest for backend TypeScript testing and the Node.js native test runner for core server validations. It prioritizes decoupled unit tests using in-memory repository implementations and integrated tests that simulate HTTP lifecycles.
Sources: backend/package.json:11-13, README.md:144-147
Test Hierarchy and Organization
The project categorizes tests into unit, integration, and service-level validations. The backend configuration uses ts-jest to handle TypeScript files and separates tests into distinct directories under backend/tests.
Sources: backend/package.json:71-77
Execution Commands
| Test Type | Command | Scope |
|---|---|---|
| All Tests | npm test | Runs all Jest tests with coverage reporting |
| Unit Tests | npm run test:unit | Executes tests in tests/unit |
| Integration Tests | npm run test:integration | Executes tests in tests/integration |
| Core Server Tests | node --test test/app.test.js | Runs native Node.js tests for the main entry point |
| Sources: backend/package.json:11-14, package.json:7 |
Unit Testing Strategy
Unit tests focus on the business logic within Use Cases and Domain Services. To isolate logic, these tests use "In-Memory" stubs for repositories, which simulate database behavior without requiring a live connection.
Sources: backend/tests/unit/use-cases/booking.test.ts:13-33
Dependency Injection and Mocking
The CreateBookingUseCase is tested by injecting in-memory versions of IBookingRepository, IUserRepository, and ICleanerRepository. This allows the test to verify that the AI pricing and cleaner recommendation logic correctly influences the resulting Booking entity status and amount.
Sources: backend/tests/unit/use-cases/booking.test.ts:98-103
This diagram illustrates the isolation of business logic using in-memory implementations during unit tests.
Integration Testing Strategy
Integration tests verify the interaction between the HTTP interface and the application layer. These tests use supertest to simulate real API calls and ensure that authentication, validation middleware, and use case orchestration function correctly together.
Sources: backend/tests/integration/booking.integration.test.ts:1, test/app.test.js:45-52
API Workflow Validation
Integration tests for the booking system follow these steps:
- Initialize the application with a
createAppfactory function. - Generate valid JWT tokens using
JwtService. - Dispatch a
POSTrequest to/api/v1/bookingswith a JSON payload. - Validate the HTTP status code and the structure of the returned data.
Sources: backend/tests/integration/booking.integration.test.ts:79-114
The sequence above shows the flow of an integration test verifying the booking API endpoint.
AI and Chat Validation
A specific testing suite exists for the Atlas AI chat integration to ensure safety and performance limits. These tests verify the configuration of the OPENAI_API_KEY and the enforcement of message size constraints.
Sources: test/app.test.js:31-39, src/validation/chat.js:5-10
Security and Health Checks
The system includes tests to confirm:
- Degraded Mode: The health endpoint returns
503if AI services are unconfigured. - Authentication: The chat API requires an
x-api-keyheader whenATLAS_API_KEYis set. - Payload Validation: The
validateMessagesfunction restricts the number of messages and total content length.
Sources: test/app.test.js:31-39, test/app.test.js:58-69, src/validation/chat.js:12-32
Coverage and Quality Standards
The testing infrastructure is configured to collect code coverage for all files in the src directory, excluding the main entry point server.ts. This ensures that new features in the domain and infrastructure layers are verified.
Sources: backend/package.json:74-77
Summary of test coverage focus:
- Domain Entities: Logic such as
assignCleaner,confirm, andcancelwithinBooking.ts. - Infrastructure Services: Fallback heuristics in
AtlasAIServicewhen the remote AI API is unreachable. - Use Cases: Orchestration of multiple services (e.g., combining pricing and scheduling).
Sources: backend/src/domain/entities/Booking.ts:60-77, backend/tests/unit/services/atlasai.test.ts:7-34
The project uses a testing strategy that balances fast-running unit tests with comprehensive integration tests to maintain high software quality across the AI cleaning platform.