Skip to content

nsc-events-fullstack_32_160_jwt-authentication-guard #164

Closed
NahomAlemu wants to merge 1 commit into
mainfrom
chore-160-jwt-auth-guard-test
Closed

nsc-events-fullstack_32_160_jwt-authentication-guard #164
NahomAlemu wants to merge 1 commit into
mainfrom
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
@gitbiruk2010 gitbiruk2010 self-requested a review April 27, 2026 18:32
Copy link
Copy Markdown
Contributor

@gitbiruk2010 gitbiruk2010 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image

@NahomAlemu
Copy link
Copy Markdown
Contributor Author

Since my practicum work has ended, I'm closing this PR to keep the repository tidy. I won't be able to address future feedback, but feel free to use this branch as a reference if the feature is needed later!

@NahomAlemu NahomAlemu closed this May 7, 2026
@NahomAlemu NahomAlemu deleted the chore-160-jwt-auth-guard-test branch May 7, 2026 20:33
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

3 participants