This directory contains unit tests for all backend controllers.
tests/unit/controllers/
├── driver/
│ └── userController.test.js # Tests for driver user management
├── rider/
│ └── rideController.test.js # Tests for ride management
└── shared/
├── authController.test.js # Tests for authentication and profile
├── chatController.test.js # Tests for chat and messaging
├── emergencyController.test.js # Tests for emergency incidents
├── notificationController.test.js # Tests for notifications
├── settingsController.test.js # Tests for application settings
├── reportsController.test.js # Tests for reporting and analytics
└── monitoringController.test.js # Tests for real-time monitoring
npm test -- tests/unit/controllersnpm test -- tests/unit/controllers/shared# Auth controller tests (14 tests)
npm test -- tests/unit/controllers/shared/authController.test.js
# Chat controller tests (26 tests)
npm test -- tests/unit/controllers/shared/chatController.test.js
# Emergency controller tests (22 tests)
npm test -- tests/unit/controllers/shared/emergencyController.test.js
# Notification controller tests (30 tests)
npm test -- tests/unit/controllers/shared/notificationController.test.js
# Settings controller tests (28 tests)
npm test -- tests/unit/controllers/shared/settingsController.test.js
# Reports controller tests (28 tests)
npm test -- tests/unit/controllers/shared/reportsController.test.js
# Monitoring controller tests (30 tests)
npm test -- tests/unit/controllers/shared/monitoringController.test.js# Driver user controller tests (17 tests)
npm test -- tests/unit/controllers/driver/userController.test.js# Rider ride controller tests (17 tests)
npm test -- tests/unit/controllers/rider/rideController.test.jsnpm run test:watch -- tests/unit/controllersnpm run test:coverage -- tests/unit/controllersCurrent controller tests cover:
- ✅ Function exports and signatures
- ✅ Required field validation
- ✅ User role validation
- ✅ 2FA support verification
- ✅ Function exports and signatures
- ✅ Conversation management (listing, creation)
- ✅ Message management (retrieval, sending)
- ✅ Message status (read/unread)
- ✅ Query parameter handling
- ✅ Function exports and signatures
- ✅ Incident retrieval and filtering
- ✅ Incident creation and updates
- ✅ Status and priority validation
- ✅ Incident type validation
- ✅ Function exports and signatures
- ✅ Notification retrieval and filtering
- ✅ Notification creation
- ✅ Broadcasting functionality
- ✅ Status management
- ✅ Notification statistics
- ✅ Type and priority validation
- ✅ Function exports and signatures
- ✅ Settings retrieval (all, by key)
- ✅ Setting creation and updates
- ✅ Bulk operations
- ✅ Setting categories and data types
- ✅ Key naming conventions
- ✅ Function exports and signatures
- ✅ Report retrieval (recent, scheduled)
- ✅ Report generation
- ✅ Report statistics
- ✅ Scheduled report management
- ✅ Report type and format validation
- ✅ Schedule frequency validation
- ✅ Function exports and signatures
- ✅ Live ride monitoring
- ✅ Safety monitoring
- ✅ System monitoring
- ✅ GPS logs
- ✅ Alert types and severity levels
- ✅ Location data handling
- ✅ Function exports and signatures
- ✅ Query parameter handling
- ✅ User filtering (role, status, search)
- ✅ CRUD operations structure
- ✅ User statistics
- ✅ Function exports and signatures
- ✅ Query parameter handling
- ✅ Ride filtering (status, type, dates)
- ✅ CRUD operations structure
- ✅ Ride status and type validation
- ✅ Ride statistics
Total: 212 tests passing
When adding new controller tests:
-
Create a new test file in the appropriate directory:
driver/for driver-specific controllersrider/for rider-specific controllersshared/for shared controllers
-
Follow the existing test structure:
import { functionName } from '../../../../src/controllers/path/to/controller.js';
describe('Controller Name', () => {
describe('Function exports', () => {
test('functionName should be defined', () => {
expect(functionName).toBeDefined();
expect(typeof functionName).toBe('function');
});
});
describe('Specific functionality', () => {
test('should test specific behavior', () => {
// Test code here
});
});
});- Run the tests to ensure they pass:
npm test -- path/to/your/test.jsThese tests focus on:
- Structure validation: Ensuring functions are properly exported
- Interface validation: Verifying function signatures match Express patterns
- Data structure validation: Testing query parameters, request bodies, and response formats
- Business logic validation: Checking valid values for statuses, roles, types, etc.
For full integration testing with database mocking, see the integration tests directory.
- Tests use ES modules (
import/export) - Tests are compatible with Jest's experimental VM modules support
- Database connections are not mocked in these structural tests
- For full end-to-end testing, use the integration test suite