Skip to content

[12] Add unit tests for AuthService #4

Description

@EmeditWeb

Problem

src/modules/auth/auth.service.ts has zero unit tests. All authentication paths (nonce generation, signature verification, token rotation) are untested. Any regression here logs every user out and is undetectable until production.

Context

Auth is the most security-sensitive module. A silent bug in token rotation could leak session lifetimes or allow refresh-token replay attacks. Unit tests are the cheapest line of defense.

Before Starting

Read these context files first:

  • context/architecture-context.md
  • context/code-standards.md
  • context/progress-tracker.md
  • src/modules/auth/auth.service.ts

What To Build

  1. Create test/unit/auth.service.spec.ts with a Test.createTestingModule setup mocking SupabaseService, JwtService, and ConfigService.
  2. Test getNonce(wallet): returns a 32-char nonce, inserts a row in nonces with wallet, nonce, expires_at.
  3. Test verify(wallet, signature): valid signature path returns { accessToken, refreshToken }; invalid signature throws UnauthorizedException.
  4. Test refresh(refreshToken): valid token returns new pair; refresh token is rotated (old one marked revoked).
  5. Test nonce dedup: two getNonce(wallet) calls within expiry window return the same nonce.
  6. Achieve ≥ 90% branch coverage on auth.service.ts.

Files To Touch

  • test/unit/auth.service.spec.ts

Acceptance Criteria

  • At least 5 distinct describe blocks covering each method
  • All Supabase calls are mocked — no real DB hit
  • Test runs in under 2 seconds
  • npm test -- auth.service passes
  • Branch coverage ≥ 90% on the service
  • No any types in the test file

Mandatory Checks Before PR

  • npm run build passes with zero TypeScript errors
  • No new any types introduced anywhere
  • Full Swagger @apioperation + @apiresponse decorators on any new endpoints
  • New migration file created for any schema changes
  • context/progress-tracker.md updated

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions