The full test suite was failing with 20 failed tests in auth.service.spec.ts due to a missing dependency mock.
When AuthRateLimitService was integrated into AuthService (as part of Task 2: Authentication Rate Limiting), the test file auth.service.spec.ts was not updated to include a mock for this new dependency.
Nest can't resolve dependencies of the AuthService (UserService, JwtService, EventEmitter, CACHE_MANAGER, ?).
Please make sure that the argument AuthRateLimitService at index [4] is available in the RootTestModule module.
Added the missing AuthRateLimitService mock to the test providers in auth.service.spec.ts:
- Added import statement:
import { AuthRateLimitService } from './services/auth-rate-limit.service';- Created mock object:
const mockAuthRateLimitService = {
recordFailedAttempt: jest.fn(),
clearFailedAttempts: jest.fn(),
applyProgressiveDelay: jest.fn(),
shouldBlockRequest: jest.fn().mockResolvedValue({ blocked: false }),
getProgressiveDelay: jest.fn().mockResolvedValue(0),
getFailedAttemptCount: jest.fn().mockResolvedValue(0),
isIpBanned: jest.fn().mockResolvedValue(false),
isAccountLocked: jest.fn().mockResolvedValue(false),
};- Added provider to test module:
{
provide: AuthRateLimitService,
useValue: mockAuthRateLimitService,
}- Test Suites: 1 failed, 54 passed, 55 total
- Tests: 20 failed, 408 passed, 428 total
- Status: ❌ FAILED
- Test Suites: 55 passed, 55 total
- Tests: 428 passed, 428 total
- Status: ✅ PASSED
Nestera/backend/src/auth/auth.service.spec.ts
All 428 tests now pass successfully, including:
- 22 tests in
auth.service.spec.ts(nonce security tests) - 22 tests in
auth-rate-limit.service.spec.ts(rate limiting tests) - 384 other tests across the application
- The individual test files passed when run in isolation because they had proper mocks
- The failure only occurred when running the full test suite due to NestJS dependency injection
- This is a common pattern when adding new service dependencies - test mocks must be updated accordingly