Skip to content

nsc-events-fullstack_32_160_jwt-authentication-guard #164

Open
NahomAlemu wants to merge 1 commit intomainfrom
chore-160-jwt-auth-guard-test
Open

nsc-events-fullstack_32_160_jwt-authentication-guard #164
NahomAlemu wants to merge 1 commit intomainfrom
chore-160-jwt-auth-guard-test

Conversation

@NahomAlemu
Copy link
Copy Markdown
Contributor

Summary & Changes 📃

  • Resolves: Issue: Add Unit Tests for JWT Authentication Guard #160

  • Summary: Adds comprehensive unit tests for the JwtAuthGuard class to ensure proper JWT
    authentication behavior.

    • Adds missing test coverage for the JWT authentication guard
    • Tests verify that public routes bypass authentication while protected routes require valid
      JWT tokens
    • Tests cover the canActivate method, @public() decorator integration, and proper delegation to
      the parent AuthGuard
  • Changes:

    • Added jwt-auth.guard.spec.ts with 15 test cases covering:
    • Guard instantiation and dependency injection
    • Public route handling (routes marked with @public() decorator)
    • Protected route authentication flow
    • Edge cases (explicit false, null, undefined decorator values)
    • IS_PUBLIC_KEY metadata lookup verification
    • No breaking changes
    • Related to JWT authentication guard implementation
    • Uses mock ExecutionContext and Reflector for isolated unit testing

Screenshots / Visual Aids 🔎

📌 Required for: UI changes, layout updates, or bug fixes.

Expand ⬇️ 1 2

How to Test 🧪

  1. Steps to Reproduce:
    • Step 1: Navigate to the nsc-events-nestjs directory
    • Step 2: Run npm run test -- --coverage jwt-auth.guard.spec.ts
  2. Expected Behavior: All 15 tests should pass, verifying that the JwtAuthGuard correctly handles
    public vs protected routes

Checklist ✅

  • I have tested this PR locally and it works as expected.
  • This PR resolves an issue (Resolves #issue-number).
  • Reviewers, assignees(self), tags, and labels are correctly assigned.
  • Squash commits and enable auto-merge if approved.

@github-actions
Copy link
Copy Markdown

✅ Full E2E Test Results

Running full test suite (critical files changed)

Status Count
✅ Passed 53
❌ Failed 0
📊 Total 53

View detailed report

@NahomAlemu NahomAlemu linked an issue Mar 7, 2026 that may be closed by this pull request
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

unit-test Small-scope logic validation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue: Add Unit Tests for JWT Authentication Guard

1 participant