This document provides comprehensive information about the integration testing suite for the Servizo platform. These tests are designed to validate the complete flow of features across multiple components of the application.
__tests__/
├── services.test.js # Unit tests for models
├── integration/
│ ├── auth.integration.test.js # Authentication flow tests
│ ├── booking.integration.test.js # Booking system tests
│ ├── service.integration.test.js # Service management tests
│ └── review.integration.test.js # Review system tests
└── setup.js # Test configuration
npm testnpm run test:unitnpm run test:integration# Authentication tests
npm run test:integration:auth
# Booking tests
npm run test:integration:booking
# Service tests
npm run test:integration:service
# Review tests
npm run test:integration:reviewnpm run test:watchnpm run test:coverageCovers:
- ✅ User registration (customers and providers)
- ✅ Email verification with OTP
- ✅ User login with credentials
- ✅ Password hashing validation
- ✅ Duplicate email prevention
- ✅ Input validation
- ✅ Session management
- ✅ Logout functionality
Test Cases: 11 tests
- User registration with valid data
- Provider account creation
- Duplicate email handling
- Invalid email format validation
- OTP verification (valid/invalid/expired)
- Login with correct/incorrect credentials
- Unverified email login prevention
Covers:
- ✅ Booking creation workflow
- ✅ Authentication requirements
- ✅ Price calculation
- ✅ Booking status management
- ✅ Customer and provider booking lists
- ✅ Status transitions (pending → confirmed → in-progress → completed)
- ✅ Booking cancellation
- ✅ Payment status tracking
- ✅ Query performance with indexes
Test Cases: 15+ tests
- Create booking with all fields
- Authentication-protected routes
- Total amount calculation
- List customer/provider bookings
- Status updates (confirmed, in-progress, completed, cancelled)
- Field validation
- Payment status enum validation
- Efficient database queries
Covers:
- ✅ Service creation with all fields
- ✅ Multiple service categories
- ✅ Price and duration validation
- ✅ Service filtering (category, city, price range)
- ✅ Service search functionality
- ✅ Service updates (price, rating, status)
- ✅ Provider-service relationship
- ✅ Rating and review aggregation
- ✅ Query performance optimization
Test Cases: 20+ tests
- Create service with required fields
- Create services in 10+ categories
- Price validation (non-negative)
- Duration validation (minimum 15 minutes)
- Filter by category, city, price range
- Sort by rating
- Search by title
- Update price, rating, booking count
- Toggle active status
- Provider relationship and population
- Performance testing with 50+ services
Covers:
- ✅ Review creation for completed bookings
- ✅ Rating validation (1-5 scale)
- ✅ Service rating calculation
- ✅ Provider rating updates
- ✅ Review queries and filters
- ✅ Review statistics and aggregation
- ✅ Rating distribution analysis
- ✅ Recommendation tracking
- ✅ Comment validation
Test Cases: 17+ tests
- Create review with all fields
- Multiple rating levels (1-5)
- Rating range validation
- Mandatory field validation
- Service average rating calculation
- Provider rating updates
- Query reviews by service/provider
- Filter by rating and recommendation
- Sort reviews
- Populate related data
- Calculate rating distribution
- Average rating aggregation
- Recommendation percentage
- Comment trimming and length validation
- Registration → OTP Verification → Login → Browse Services → Book Service → Complete Service → Leave Review
- ✅ Password hashing
- ✅ Email uniqueness
- ✅ Foreign key relationships
- ✅ Enum validation
- ✅ Data type validation
- ✅ Booking workflow states
- ✅ Rating calculations
- ✅ Price calculations
- ✅ Service availability
- ✅ Provider verification
- ✅ Database indexing effectiveness
- ✅ Query optimization
- ✅ Batch operations
- ✅ Population efficiency
| Test Suite | Test Count | Coverage Area |
|---|---|---|
| Authentication | 11 | User management, sessions |
| Booking System | 15+ | Booking lifecycle, payments |
| Service Management | 20+ | CRUD, filtering, relationships |
| Review System | 17+ | Ratings, aggregations, stats |
| Total | 63+ | Full application flow |
Before running tests, ensure:
-
MongoDB is running on
localhost:27017mongod
-
Test database (
servizo_test) will be created automatically -
Dependencies installed
npm install
- Database Name:
servizo_test - Auto-cleanup: Tests clean up their own data using
beforeEachandafterAllhooks - Isolation: Each test suite uses unique email patterns to prevent conflicts
-
Show Test Structure
ls -la __tests__/integration/
-
Run All Integration Tests
npm run test:integration
-
Show Coverage Report
npm run test:coverage
-
Demonstrate Specific Feature
# Show authentication flow npm run test:integration:auth # Show booking workflow npm run test:integration:booking
✨ Comprehensive Coverage:
- 63+ integration tests covering end-to-end workflows
- Tests validate real user scenarios
- Database operations tested with actual MongoDB
✨ Real-World Scenarios:
- Complete user journey from registration to review
- Multi-role testing (customer, provider, admin)
- Error handling and validation
✨ Best Practices:
- Test isolation with cleanup hooks
- Separate test database
- Performance benchmarking
- Mock data generation
✨ Business Logic Validation:
- Booking status transitions
- Rating calculations
- Payment tracking
- Service availability
PASS __tests__/integration/auth.integration.test.js
Authentication Integration Tests
POST /auth/register - User Registration
✓ Should successfully register a new customer (234ms)
✓ Should successfully register a new provider (187ms)
✓ Should fail registration with duplicate email (156ms)
POST /auth/verify-otp - OTP Verification
✓ Should verify valid OTP successfully (89ms)
✓ Should fail with incorrect OTP (67ms)
POST /auth/login - User Login
✓ Should login successfully with correct credentials (123ms)
✓ Should fail login with incorrect password (98ms)
Test Suites: 4 passed, 4 total
Tests: 63 passed, 63 total
Time: 12.456s# Check if MongoDB is running
ps aux | grep mongod
# Start MongoDB
mongod
# Or use Docker
docker run -d -p 27017:27017 mongoIf tests fail due to port conflicts, ensure no development server is running:
killall node# Connect to MongoDB
mongosh
# Switch to test database
use servizo_test
# Drop database
db.dropDatabase()To extend testing:
- Add API endpoint tests with full request/response validation
- Add Socket.IO tests for real-time chat
- Add Redis caching tests for performance validation
- Add email service tests with mock SMTP
- Add file upload tests for service images
Last Updated: December 22, 2025
Version: 1.0.0
Author: Spydiecy