Skip to content

test(vue): add unit tests for getDisplayName utility#530

Open
salabili212 wants to merge 4 commits into
asgardeo:mainfrom
salabili212:test-coverage-vue-sdk
Open

test(vue): add unit tests for getDisplayName utility#530
salabili212 wants to merge 4 commits into
asgardeo:mainfrom
salabili212:test-coverage-vue-sdk

Conversation

@salabili212

@salabili212 salabili212 commented Jun 9, 2026

Copy link
Copy Markdown

Purpose

I noticed that the getDisplayName utility function in the @asgardeo/vue package had no unit tests at all. This PR adds 6 tests covering all the main code paths — including fallback behavior when user attributes are missing, and when displayAttributes are provided.

Related Issues

Related PRs

  • N/A

Checklist

  • Followed the CONTRIBUTING guidelines.
  • Manual test round performed and verified.
  • Documentation provided. (Add links if there are any)
  • Unit tests provided.

Security checks

Summary by CodeRabbit

  • Tests
    • Added/expanded coverage for display name resolution, including default naming, first/last name combinations, username/email fallbacks, configurable display attributes, and correct handling when attribute configurations are empty.
  • Chores
    • Pinned the project’s package manager version in the package manifest.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5b622331-c5ca-4afa-b052-2329ff26be97

📥 Commits

Reviewing files that changed from the base of the PR and between 6b663e9 and 26cfe1e.

📒 Files selected for processing (1)
  • packages/vue/src/__tests__/utils/getDisplayName.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/vue/src/tests/utils/getDisplayName.test.ts

📝 Walkthrough

Walkthrough

This pull request adds unit tests for getDisplayName fallback behavior in the Vue SDK and pins the pnpm version in package.json.

Changes

Test Coverage and Package Configuration

Layer / File(s) Summary
getDisplayName test suite with mocks and fallback validation
packages/vue/src/__tests__/utils/getDisplayName.test.ts
Vitest tests mock getMappedUserProfileValue and cover default, fallback, displayAttributes, and empty-attribute display-name resolution paths.
Package manager version pinning
package.json
Adds a top-level packageManager field specifying pnpm 11.5.2 with a SHA-512 integrity hash.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped through tests, both neat and bright,
For names that fall back just right.
pnpm stays pinned, no drift in sight,
And coverage blooms with extra light ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The packageManager pin in package.json is unrelated to the test-coverage issue and appears out of scope. Remove the packageManager change unless it is required for this test work, or document it as part of the linked issue scope.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: adding unit tests for the Vue getDisplayName utility.
Description check ✅ Passed The description follows the template and includes purpose, related issues, checklist, and security checks.
Linked Issues check ✅ Passed The new tests cover the Vue getDisplayName edge cases and fallbacks requested by #170.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/vue/src/__tests__/utils/getDisplayName.test.ts (1)

26-59: ⚡ Quick win

The tests validate return order but not lookup keys.

Using only mockReturnValueOnce can still pass if getDisplayName calls getMappedUserProfileValue with wrong attribute names but the same call count/order. Add argument assertions (e.g., toHaveBeenNthCalledWith) or switch to a key-based mock implementation map.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/vue/src/__tests__/utils/getDisplayName.test.ts` around lines 26 -
59, The tests for getDisplayName currently only assert call order via
mockReturnValueOnce, which can hide wrong lookup keys; update the tests in
getDisplayName.test.ts to assert the actual lookup keys passed to
getMappedUserProfileValue (or mockGet) — either replace the sequenced
mockReturnValueOnce approach with a key-based mock implementation (e.g.,
mockGet.mockImplementation(key => ({ firstName: 'Jane', lastName: 'Doe',
username: 'janedoe', email: 'jane@example.com' }[key]))) or add explicit
argument assertions using toHaveBeenNthCalledWith against mockGet for each case;
target the tests that call getDisplayName(mergedMappings, user, ...) and verify
mockGet/getMappedUserProfileValue was called with the expected attribute names.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/vue/src/__tests__/utils/getDisplayName.test.ts`:
- Around line 33-47: Add a new unit test to cover the `name` fallback in
getDisplayName: in the test file using the same helpers (`mockGet`,
`mergedMappings`, `user`), set mockGet to return undefined for firstName,
lastName, username, and email (four consecutive mockReturnValueOnce(undefined)
calls) and then return a non-empty string for `name` (e.g., 'Jane Doe'); call
getDisplayName(mergedMappings, user) and assert the result equals that `name`
value so the explicit `name` branch in getDisplayName is exercised.

---

Nitpick comments:
In `@packages/vue/src/__tests__/utils/getDisplayName.test.ts`:
- Around line 26-59: The tests for getDisplayName currently only assert call
order via mockReturnValueOnce, which can hide wrong lookup keys; update the
tests in getDisplayName.test.ts to assert the actual lookup keys passed to
getMappedUserProfileValue (or mockGet) — either replace the sequenced
mockReturnValueOnce approach with a key-based mock implementation (e.g.,
mockGet.mockImplementation(key => ({ firstName: 'Jane', lastName: 'Doe',
username: 'janedoe', email: 'jane@example.com' }[key]))) or add explicit
argument assertions using toHaveBeenNthCalledWith against mockGet for each case;
target the tests that call getDisplayName(mergedMappings, user, ...) and verify
mockGet/getMappedUserProfileValue was called with the expected attribute names.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bf893e0e-aae8-48fc-a88f-6e6eb13031b1

📥 Commits

Reviewing files that changed from the base of the PR and between 66838b8 and 2d9ecad.

📒 Files selected for processing (1)
  • packages/vue/src/__tests__/utils/getDisplayName.test.ts

Comment thread packages/vue/src/__tests__/utils/getDisplayName.test.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@package.json`:
- Line 56: The CI workflows are using floating "latest" pnpm versions instead of
respecting the pinned version in package.json. Update all four CI workflow files
(e2e-tests.yml, npm-audit.yml, pr-builder.yml, and release.yml) to use the
pinned pnpm version 11.5.2 from package.json. Replace the matrix.pnpm-version:
[latest] configuration in e2e-tests, npm-audit, and pr-builder workflows with
the pinned version, and update the version field in the pnpm/action-setup
configuration in all workflows to use 11.5.2 instead of "latest" to ensure
consistency across all environments.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dd5b73c2-60da-4815-8131-e3417ae366d7

📥 Commits

Reviewing files that changed from the base of the PR and between 2d9ecad and 6b663e9.

📒 Files selected for processing (2)
  • package.json
  • packages/vue/src/__tests__/utils/getDisplayName.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/vue/src/tests/utils/getDisplayName.test.ts

Comment thread package.json
"access": "restricted"
}
},
"packageManager": "pnpm@11.5.2+sha512.71c631e382066efc25625d5cf029075de07b61b37f6e27350fbd84b1bda5864c8c1967adc280776b45c30a715c0359a3be08fef42d5bb09e2b99029979692916"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

python - <<'PY'
import json, glob, re

with open("package.json", "r", encoding="utf-8") as f:
    pkg = json.load(f)

pm = pkg.get("packageManager", "")
print("package.json packageManager:", pm)

pinned = None
if pm.startswith("pnpm@"):
    pinned = pm.split("@", 1)[1].split("+", 1)[0]
print("Pinned pnpm version:", pinned)

for wf in sorted(glob.glob(".github/workflows/*.yml") + glob.glob(".github/workflows/*.yaml")):
    text = open(wf, "r", encoding="utf-8").read()
    if "pnpm/action-setup" not in text:
        continue
    m = re.search(r"pnpm-version:\s*\[([^\]]+)\]", text)
    if m:
        print(f"{wf}: matrix pnpm-version=[{m.group(1).strip()}]")
    else:
        print(f"{wf}: pnpm/action-setup found (no matrix pnpm-version pattern matched)")
PY

Repository: asgardeo/javascript

Length of output: 645


🏁 Script executed:

#!/bin/bash
# Check release.yml for pnpm version handling
rg -A 5 "pnpm/action-setup" .github/workflows/release.yml

Repository: asgardeo/javascript

Length of output: 308


Align all CI workflows to use the pinned pnpm version from package.json.

Package.json pins pnpm@11.5.2, but all four CI workflows (e2e-tests.yml, npm-audit.yml, pr-builder.yml, release.yml) install from floating latest: e2e-tests, npm-audit, and pr-builder use matrix.pnpm-version: [latest], while release.yml uses version: latest in the pnpm/action-setup config. This allows pnpm to drift across environments, compromising reproducibility in testing and production builds. Update CI to respect the pinned version.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@package.json` at line 56, The CI workflows are using floating "latest" pnpm
versions instead of respecting the pinned version in package.json. Update all
four CI workflow files (e2e-tests.yml, npm-audit.yml, pr-builder.yml, and
release.yml) to use the pinned pnpm version 11.5.2 from package.json. Replace
the matrix.pnpm-version: [latest] configuration in e2e-tests, npm-audit, and
pr-builder workflows with the pinned version, and update the version field in
the pnpm/action-setup configuration in all workflows to use 11.5.2 instead of
"latest" to ensure consistency across all environments.

@salabili212

Copy link
Copy Markdown
Author

Added the missing test for the name fallback branch as suggested. Pushed in the latest commit.

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.

chore: add unit test coverage for untested code paths in @asgardeo/vue SDK

1 participant