Skip to content

nsc-events-fullstack_32_161_role_guard#165

Open
NahomAlemu wants to merge 1 commit intomainfrom
chore-161-role-auth-guard-test
Open

nsc-events-fullstack_32_161_role_guard#165
NahomAlemu wants to merge 1 commit intomainfrom
chore-161-role-auth-guard-test

Conversation

@NahomAlemu
Copy link
Copy Markdown
Contributor

Summary & Changes 📃

  • Resolves: Issue: Add Unit Tests for Role-Based Authorization Guard #161

  • Summary: Adds unit tests for the RoleGuard class to ensure proper role-based access control.

    • 🔨 Adds missing test coverage for the role-based authorization guard
    • 👀 Tests verify that routes enforce correct role restrictions (admin, creator, user)
    • 🗨️ Achieves 100% code coverage across statements, branches, functions, and lines
  • Changes:

    • ✅ Added role.guard.spec.ts with 26 test cases covering:
    • Guard instantiation and dependency injection
    • matchRoles method logic
    • Routes without @roles decorator (allow all)
    • Routes with @roles decorator (enforce restrictions)
    • RBAC scenarios (admin-only, admin-or-creator, etc.)
    • 🛠️ No breaking changes
    • 📝 Follows existing codebase testing patterns

Screenshots / Visual Aids 🔎

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

Expand ⬇️ Screenshot 2026-02-26 at 12 36 26 PM Screenshot 2026-02-26 at 12 36 22 PM

How to Test 🧪

  1. Steps to Reproduce:
    - Step 1: Navigate to the nsc-events-nestjs directory
    - Step 2: Run with coverage: npm run test -- --coverage role.guard.spec.ts
  2. Expected Behavior: All 26 tests pass with 100% coverage

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 47
❌ Failed 0
📊 Total 47

View detailed report

@NahomAlemu NahomAlemu changed the title nsc-events-fullstack_32_160_role_guard nsc-events-fullstack_32_161_role_guard Feb 27, 2026
@NahomAlemu NahomAlemu linked an issue Mar 7, 2026 that may be closed by this pull request
4 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 Role-Based Authorization Guard

1 participant