Skip to content

[BE-39] Write unit tests for AuthService in opsce module #764

@yusuftomilola

Description

@yusuftomilola

Problem

Authentication is the most critical path in the application and has zero test coverage. Bugs in password hashing, JWT signing, or token validation could expose user accounts.

Proposed Solution

Create backend/src/opsce/auth/auth.service.spec.ts covering all auth flows with mocked dependencies.

Acceptance Criteria

  • register() — success path creates user with hashed password, throws ConflictException on duplicate email
  • login() — success returns access and refresh tokens, throws UnauthorizedException for wrong password
  • refreshToken() — valid token returns new token pair, invalid token throws UnauthorizedException
  • forgotPassword() — creates reset token and calls MailerService.sendPasswordReset()
  • resetPassword() — updates password, throws BadRequestException for expired token
  • bcryptjs.compare and JwtService.sign are mocked — no real crypto in unit tests
  • Tests achieve at least 90% statement coverage for AuthService

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions