Skip to content

Latest commit

 

History

History
71 lines (57 loc) · 2.3 KB

File metadata and controls

71 lines (57 loc) · 2.3 KB

Test Suite Fix Summary

Issue

The full test suite was failing with 20 failed tests in auth.service.spec.ts due to a missing dependency mock.

Root Cause

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.

Error Message

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.

Solution

Added the missing AuthRateLimitService mock to the test providers in auth.service.spec.ts:

Changes Made

  1. Added import statement:
import { AuthRateLimitService } from './services/auth-rate-limit.service';
  1. 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),
};
  1. Added provider to test module:
{
  provide: AuthRateLimitService,
  useValue: mockAuthRateLimitService,
}

Test Results

Before Fix

  • Test Suites: 1 failed, 54 passed, 55 total
  • Tests: 20 failed, 408 passed, 428 total
  • Status: ❌ FAILED

After Fix

  • Test Suites: 55 passed, 55 total
  • Tests: 428 passed, 428 total
  • Status: ✅ PASSED

Files Modified

  • Nestera/backend/src/auth/auth.service.spec.ts

Verification

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

Notes

  • 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