Skip to content

test(cli): add unit tests for dashboard auth commands (login, logout, whoami)#938

Merged
aaight merged 1 commit intodevfrom
feature/dashboard-auth-cli-tests
Mar 17, 2026
Merged

test(cli): add unit tests for dashboard auth commands (login, logout, whoami)#938
aaight merged 1 commit intodevfrom
feature/dashboard-auth-cli-tests

Conversation

@aaight
Copy link
Copy Markdown
Collaborator

@aaight aaight commented Mar 17, 2026

Summary

  • Adds tests/unit/cli/dashboard/auth.test.ts with 14 tests covering login, logout, and whoami dashboard CLI commands
  • Mocks fetch(), saveConfig/clearConfig/loadConfig, createDashboardClient, and chalk following the pattern from integration-credentials.test.ts
  • Uses oclifConfig = { runHook: vi.fn() } for oclif command instantiation

What was implemented

Login tests (6):

  • Success path saves serverUrl, sessionToken, cookieName, and orgId extracted from Set-Cookie header
  • Failure path throws with error message from server response body
  • --org flag is passed through to saveConfig
  • Trailing slash is stripped from --server URL
  • Generic error message when server response has no error field
  • Errors when no session cookie is returned on a success response

Logout tests (4):

  • Calls clearConfig and logs success message
  • Makes best-effort server-side logout fetch and ignores network errors
  • Skips the fetch entirely when no active session config is present
  • Sends the logout request using the cookie name from config (supports cascade_session_development etc.)

Whoami tests (4):

  • Queries client.auth.me and displays table output
  • Outputs JSON when --json flag is set
  • Shows effectiveOrgId row when it differs from orgId
  • Does NOT show effectiveOrgId row when it equals orgId

Test plan

  • npx vitest run --project unit-core tests/unit/cli/dashboard/auth.test.ts → 14/14 pass
  • npm run lint:fix → clean
  • npm run typecheck → zero errors

Card

https://trello.com/c/69b9918fc9f6194971250484

🤖 Generated with Claude Code

🕵️ claude-code · claude-sonnet-4-6 · run details

Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

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

LGTM — Well-structured unit tests that follow the established patterns (mock hoisting, oclifConfig stub, chalk identity mock) from integration-credentials.test.ts. All 14 tests cover meaningful behavior paths for login, logout, and whoami commands. CI is green.

Verified against source:

  • Login success/failure paths, cookie parsing, trailing-slash stripping, and org passthrough all match login.ts implementation
  • Logout best-effort fetch, error swallowing, null-config skip, and dynamic cookie name all match logout.ts
  • Whoami table/JSON output and effectiveOrgId conditional display match whoami.ts + DashboardCommand.outputDetail/outputJson

No issues found.

🕵️ claude-code · claude-opus-4-6 · run details

@aaight aaight merged commit 4ad680d into dev Mar 17, 2026
5 checks passed
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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