Skip to content

[Test Improver] Add unit tests for shell/utils/auth.js utility functions - #132

Draft
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/auth-utils-tests-aab9befd994adac7
Draft

[Test Improver] Add unit tests for shell/utils/auth.js utility functions#132
github-actions[bot] wants to merge 1 commit into
masterfrom
test-assist/auth-utils-tests-aab9befd994adac7

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

🤖 This PR was created by Test Improver, an automated AI assistant focused on improving test coverage.

Goal and Rationale

shell/utils/auth.js is a critical utility module used in authentication flows across Rancher Dashboard. It had zero test coverage. This module contains several functions with genuine branching logic that benefit from tests:

  • parseAuthProvidersInfo — filters and categorises auth providers; determines the "enabled location" for the single active provider. Multiple filter branches and a null-vs-object decision for enabledLocation.
  • canViewResource — guards resource views based on store schemas and virtual-resource checks. 5 distinct return paths.
  • notLoggedIn — commits auth state and conditionally commits a redirect target, then picks between two redirect destinations.
  • checkPermissions — async function that builds a permissions hash by walking types and checking schemas against schemaValidator, resourceMethods, or collectionMethods matchers.

Approach

  • Focused on functions with real branching logic (not trivial one-liners).
  • parseAuthProvidersInfo tested with pure data fixtures — no store required.
  • canViewResource and notLoggedIn tested with minimal jest.fn() mocks.
  • checkPermissions tested end-to-end (awaiting the resolved Promise) covering all 5 execution paths.
  • Used it.each with named-object entries for table-driven variants.
  • Followed project conventions: lowercase describe/it names, toStrictEqual, toHaveBeenCalledWith.

Coverage Impact

Metric Before After
Tests added 0 24
Test suites 0 1

Test Status

PASS shell/utils/__tests__/auth.test.ts
Tests: 24 passed, 24 total

Lint: ✅ No warnings (eslint --max-warnings 0)

Reproducibility

yarn install --frozen-lockfile
yarn test:ci --testPathPattern=shell/utils/__tests__/auth.test.ts

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • download.cypress.io

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "download.cypress.io"

See Network Configuration for more information.

Generated by Daily Test Improver · ● 2.2M ·

Test parseAuthProvidersInfo, canViewResource, notLoggedIn, and
checkPermissions with 24 test cases covering all logical branches:
- parseAuthProvidersInfo: empty rows, local filtering, single enabled
  provider, oidc exclusion from supportedNonLocal, multiple enabled
  providers (null enabledLocation), disabled providers
- canViewResource: falsy inStore, missing schemaFor, schema found,
  virtual resource fallback, no schema and not virtual
- notLoggedIn: auth/hasAuth commit, setAuthRedirect conditional,
  index vs non-index redirect targets
- checkPermissions: empty types, missing schema, schemaValidator,
  resourceMethods all-present/one-missing, collectionMethods,
  schema-only default

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants