Skip to content

nvidia-swqa-test(ui): add unit tests for extractRolesFromClaims for mock ui#798

Open
jxiongtest314 wants to merge 1 commit intoNVIDIA:mainfrom
jxiongtest314:jxiong/add-mock-ui-tests
Open

nvidia-swqa-test(ui): add unit tests for extractRolesFromClaims for mock ui#798
jxiongtest314 wants to merge 1 commit intoNVIDIA:mainfrom
jxiongtest314:jxiong/add-mock-ui-tests

Conversation

@jxiongtest314
Copy link
Copy Markdown

@jxiongtest314 jxiongtest314 commented Apr 3, 2026

Description

Added 6 UT cases of extractRolesFromClaims for mock UI, Add coverage for extractRolesFromClaims in src/ui/src/lib/auth/roles.test.ts.

And test results are as:
$ pnpm exec vitest run src/lib/auth/roles.test.ts

RUN v4.0.18 /localhome/local-dyue/OSMO_UI/OSMO/src/ui

✓ src/lib/auth/roles.test.ts (21 tests) 7ms
✓ hasAdminRole (12)
✓ returns true for admin roles (4)
✓ returns true for osmo-admin role 1ms
✓ returns true for dashboard-admin role 0ms
✓ returns true when admin is among other roles 0ms
✓ returns true when both admin roles are present 0ms
✓ returns false for non-admin roles (5)
✓ returns false for osmo-user role 0ms
✓ returns false for dashboard-user role 0ms
✓ returns false for osmo-sre role 0ms
✓ returns false for grafana roles 0ms
✓ returns false for multiple non-admin roles 0ms
✓ edge cases (3)
✓ returns false for empty roles array 0ms
✓ returns false for unknown roles 0ms
✓ is case-sensitive (security: exact match required) 0ms
✓ extractRolesFromClaims (6)
✓ returns empty array when no role sources are present 1ms
✓ collects top-level claims.roles 0ms
✓ collects roles from claims.realm_access.roles 0ms
✓ collects roles from claims.resource_access.osmo.roles 0ms
✓ merges all sources and deduplicates 0ms
✓ ignores non-array role fields and other resource_access clients 0ms

✓ Roles constants (3)
✓ has expected OSMO role values 0ms
✓ has expected dashboard role values 0ms
✓ has expected grafana role values 0ms

Test Files 1 passed (1)
Tests 21 passed (21)
Start at 09:28:52
Duration 665ms (transform 40ms, setup 0ms, import 52ms, tests 7ms, environment 478ms)

Issue - None

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

Summary by CodeRabbit

  • Tests
    • Enhanced test coverage for role extraction functionality, verifying extraction from multiple JWT claim sources, deduplication of duplicate roles, edge case handling, and validation of role field formats.

@jxiongtest314 jxiongtest314 requested a review from a team as a code owner April 3, 2026 09:28
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 3, 2026

📝 Walkthrough

Walkthrough

Test suite for role authentication functions expanded with new test cases for extractRolesFromClaims helper. Tests verify role extraction from multiple JWT claim locations, merging with deduplication, empty array handling, and filtering of invalid role sources.

Changes

Cohort / File(s) Summary
Role Extraction Tests
src/ui/src/lib/auth/roles.test.ts
Added test cases for extractRolesFromClaims function covering extraction from roles, realm_access.roles, and resource_access.osmo.roles claim locations with merging, deduplication, empty source handling, and invalid field filtering.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Tests for roles, so thorough and bright,
Claims merged and deduplicated just right,
From realms to resources, we verify each claim,
The extractRolesFromClaims function—now truly tame!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title mentions adding unit tests for extractRolesFromClaims, which is directly supported by the changeset that adds 60 lines of test code for this function.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 42.79%. Comparing base (762ea59) to head (ddf24d7).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #798      +/-   ##
==========================================
- Coverage   42.90%   42.79%   -0.12%     
==========================================
  Files         203      203              
  Lines       26803    26803              
  Branches     7573     7573              
==========================================
- Hits        11500    11470      -30     
- Misses      15197    15226      +29     
- Partials      106      107       +1     
Flag Coverage Δ
backend 45.02% <ø> (-0.16%) ⬇️
ui 19.68% <ø> (+0.38%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 14 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jxiongtest314 jxiongtest314 changed the title nv-swqa-test(ui): add unit tests for extractRolesFromClaims nvidia-swqa-test(ui): add unit tests for extractRolesFromClaims Apr 3, 2026
@jxiongtest314 jxiongtest314 changed the title nvidia-swqa-test(ui): add unit tests for extractRolesFromClaims nvidia-swqa-test(ui): add unit tests for extractRolesFromClaims for mock ui Apr 3, 2026
@jxiongtest314
Copy link
Copy Markdown
Author

jxiongtest314 commented Apr 3, 2026

Hi @fernandol-nvidia ,
Pls help to review this MR, thanks.

BRs,
Jaze

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants