Skip to content

Conversation

@panteliselef
Copy link
Contributor

@panteliselef panteliselef commented Nov 14, 2025

Description

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • Tests
    • Strengthened test coverage for pagination and API parameter validation across organization management, invitations, domains, memberships, billing/plans, and shared pagination hooks—adding exact call-count and exact-parameter assertions to verify paginated request sequences.
  • Chores
    • Added a placeholder changeset file.

@panteliselef panteliselef self-assigned this Nov 14, 2025
@changeset-bot
Copy link

changeset-bot bot commented Nov 14, 2025

🦋 Changeset detected

Latest commit: 4d93083

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Nov 14, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Ready Ready Preview Comment Nov 14, 2025 4:44pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 14, 2025

Walkthrough

Added a placeholder changeset and strengthened unit tests across multiple packages to assert exact pagination and related fetch parameters (e.g., initialPage, pageSize, status, scope) for various organization- and pagination-related hooks and components; no production code changes.

Changes

Cohort / File(s) Summary
Changeset
\.changeset/many-pants-pump.md
New placeholder changeset file containing minimal metadata lines (---)
OrganizationSwitcher Tests
packages/clerk-js/src/ui/components/OrganizationSwitcher/__tests__/OrganizationSwitcher.test.tsx
Added assertions that fixtures.clerk.user?.getOrganizationMemberships is called once with { initialPage: 1, pageSize: 10 } when opening the switcher in multiple scenarios
Core Organization Hooks Tests
packages/clerk-js/src/ui/hooks/__tests__/useCoreOrganization.test.tsx
Added strict assertions validating pagination parameters for getMemberships, getDomains, getMembershipRequests, and getInvitations across fetch cycles (checks for initialPage, pageSize, and status/enrollmentMode where applicable)
Core Organization List Hooks Tests
packages/clerk-js/src/ui/hooks/__tests__/useCoreOrganizationList.test.tsx
Added strict parameter checks for getOrganizationMemberships, getOrganizationInvitations, and getOrganizationSuggestions, verifying initialPage progression and consistent pageSize across fetchNext operations and aggregated-call assertions
Shared Pagination Hooks Tests
packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts
Replaced partial/objectContaining assertions with exact equality checks on fetcher parameters (e.g., { initialPage, pageSize, filter }) for pagination and transition tests
Shared Plans Hooks Tests
packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx
Added assertions that the fetcher is called with explicit pagination and scope, e.g., { for: 'user', initialPage: 1, pageSize: 5 }
Billing Paginated Hook Tests
packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx
Inserted assertions ensuring the fetcher is invoked with exact pagination params (initialPage: 1, pageSize: 2 or 5) across authenticated/unauthenticated and pagination/infinite scenarios

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Rationale: changes are test-focused and repetitive but touch multiple packages and test suites.
  • Pay special attention to:
    • Exact parameter object literals used in assertions (ensure no accidental extra/omitted keys or ordering assumptions).
    • Tests that collect or aggregate multiple mock calls (verify call ordering and collection logic).
    • Mock/fixture behavior that must match the stricter assertions (pagination defaults, statuses, enrollmentMode).

Poem

🐇 I hopped through mocks with tiny feet,
I counted pages, never beat,
initialPage and pageSize too,
I cheered when every call rang true. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: improving test coverage for fetcher parameters across shared and clerk-js packages.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch elef/improve-fetcher-param-tests

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 58560c6 and 4d93083.

📒 Files selected for processing (7)
  • .changeset/many-pants-pump.md (1 hunks)
  • packages/clerk-js/src/ui/components/OrganizationSwitcher/__tests__/OrganizationSwitcher.test.tsx (3 hunks)
  • packages/clerk-js/src/ui/hooks/__tests__/useCoreOrganization.test.tsx (10 hunks)
  • packages/clerk-js/src/ui/hooks/__tests__/useCoreOrganizationList.test.tsx (11 hunks)
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx (6 hunks)
  • packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts (2 hunks)
  • packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/shared/src/react/hooks/tests/createBillingPaginatedHook.spec.tsx
  • packages/clerk-js/src/ui/components/OrganizationSwitcher/tests/OrganizationSwitcher.test.tsx
  • packages/clerk-js/src/ui/hooks/tests/useCoreOrganizationList.test.tsx
  • .changeset/many-pants-pump.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (9)
packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx (1)

191-191: Strict fetcher param assertion for sign-out scenario looks correct

Asserting the first call’s args as { for: 'user', initialPage: 1, pageSize: 5 } is consistent with earlier tests and accurately captures the expected contract before sign-out. No issues spotted.

packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts (2)

55-55: Fetcher arg equality in basic pagination test is accurate

Checking that the first fetcher call receives exactly { initialPage: 2, pageSize: 5 } tightly verifies that only pagination params flow through and cache keys are stripped. This matches the params definition and looks good.


753-755: Transition test now precisely validates per-call params

Capturing both calls and asserting:

  • first: { initialPage: 1, pageSize: 2, filter: 'A' }
  • second: { initialPage: 1, pageSize: 2, filter: 'B' }

gives clear coverage that filter changes propagate correctly while pagination settings stay stable. Looks correct and aligned with the test’s intent.

packages/clerk-js/src/ui/hooks/__tests__/useCoreOrganization.test.tsx (6)

149-155: Membership pagination param assertions are consistent and precise

The new checks on getMemberships:

  • First call: { initialPage: 1, pageSize: 2, role: undefined, query: undefined }
  • Second call: { initialPage: 2, pageSize: 2, role: undefined, query: undefined }

accurately reflect the default useOrganization config and ensure no extra filters are sneaking into the request. Looks solid.

Also applies to: 208-214


274-280: Domain pagination tests correctly enforce request shape

Verifying getDomains is called with:

  • Page 1: { initialPage: 1, pageSize: 2, enrollmentMode: undefined }
  • Page 2: { initialPage: 2, pageSize: 2, enrollmentMode: undefined }

nicely captures the intended behavior and ensures no extra params (like orgId or others) are forwarded. No issues here.

Also applies to: 321-327


392-398: Membership request pagination/status expectations look right

The stricter assertions that getMembershipRequests receives:

  • First page: { initialPage: 1, pageSize: 2, status: 'pending' }
  • Second page: { initialPage: 2, pageSize: 2, status: 'pending' }

match the default “pending-only” behavior and correct paging. This is a good, targeted tightening of the contract.

Also applies to: 433-438


508-513: Paginated invitations now fully assert pending-status pagination

Checking getInvitations calls for:

  • Page 1: { initialPage: 1, pageSize: 2, status: ['pending'] }
  • Page 2: { initialPage: 2, pageSize: 2, status: ['pending'] }

accurately encodes the expected pending-only filter and page advancement. This should catch regressions in invitation query parameters.

Also applies to: 545-550


619-624: Infinite invitations: initial fetch params are clearly specified

The infinite-mode test’s first-call expectation:

{ initialPage: 1, pageSize: 2, status: ['pending'] }

correctly mirrors the paginated test and confirms that infinite mode doesn’t alter the outbound param shape. Looks good.


653-661: Per-call invitation param inspection in infinite mode is thorough

Iterating over organizationInvitationParams to assert:

  • Keys are exactly ['initialPage', 'pageSize', 'status']
  • pageSize === 2
  • status === ['pending']
  • At least one call has initialPage === 2

is a strong guard against both param leaks and pagination regressions in infinite mode. This is a nice, robust addition.


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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9f48f13 and b9e27e3.

📒 Files selected for processing (6)
  • .changeset/many-pants-pump.md (1 hunks)
  • packages/clerk-js/src/ui/components/OrganizationSwitcher/__tests__/OrganizationSwitcher.test.tsx (3 hunks)
  • packages/clerk-js/src/ui/hooks/__tests__/useCoreOrganization.test.tsx (10 hunks)
  • packages/clerk-js/src/ui/hooks/__tests__/useCoreOrganizationList.test.tsx (11 hunks)
  • packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts (2 hunks)
  • packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Build Packages
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (9)
.changeset/many-pants-pump.md (1)

1-2: Verify PR checklist completion.

Per the PR objectives, the following checklist items remain unchecked:

  • pnpm test runs as expected
  • pnpm build runs as expected
  • JSDoc comments added/updated (if applicable)
  • Documentation updated in clerk-docs (if applicable)

Since this PR focuses on test coverage improvements, please confirm that pnpm test and pnpm build both execute successfully before merging.

packages/clerk-js/src/ui/components/OrganizationSwitcher/__tests__/OrganizationSwitcher.test.tsx (1)

244-248: LGTM! Good parameter validation.

The strict equality checks ensure getOrganizationMemberships is called with exact pagination parameters after opening the OrganizationSwitcher. This prevents regression where parameters might be accidentally omitted or modified.

Also applies to: 479-483, 510-514

packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx (1)

69-69: LGTM! Comprehensive parameter validation.

The strict equality checks ensure the fetcher receives the complete parameter object including both pagination (initialPage, pageSize) and scope (for) parameters. This guards against parameter omission or incorrect merging.

Also applies to: 191-191

packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts (2)

55-55: LGTM! Stricter parameter validation.

Upgrading from partial object matching to strict equality ensures the fetcher receives exactly the expected parameters without any extra or missing fields. This improves test precision.


753-755: LGTM! Thorough multi-call parameter validation.

Collecting and verifying all fetcher calls ensures parameter consistency across state transitions. The strict equality checks confirm both calls receive complete parameter objects with correct filter values.

packages/clerk-js/src/ui/hooks/__tests__/useCoreOrganization.test.tsx (2)

149-155: LGTM! Precise pagination parameter validation.

The assertions verify exact parameter shapes for both initial and subsequent fetch calls, including undefined values for optional filters. This ensures the hook correctly propagates pagination state without accidentally modifying or omitting parameters.

Also applies to: 208-214


653-661: LGTM! Excellent multi-call validation pattern.

Aggregating all fetcher calls and validating each parameter object ensures consistency across the infinite fetch cycle. Checking for specific keys, values, and the presence of initialPage: 2 confirms proper pagination progression.

packages/clerk-js/src/ui/hooks/__tests__/useCoreOrganizationList.test.tsx (2)

111-115: LGTM! Comprehensive pagination validation.

The assertions verify exact parameter shapes for user membership fetches, ensuring both initial page and subsequent pagination calls pass correct parameters. This prevents regressions in pagination behavior.

Also applies to: 158-162


468-474: LGTM! Robust multi-call parameter verification.

The aggregation pattern validates all fetcher calls maintain consistent parameter structure throughout the infinite fetch cycle. Checking sorted keys, fixed values, and initialPage: 2 presence ensures proper pagination state management.

Also applies to: 656-662

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 14, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@7218

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@7218

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@7218

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@7218

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@7218

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@7218

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@7218

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@7218

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@7218

@clerk/express

npm i https://pkg.pr.new/@clerk/express@7218

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@7218

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@7218

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@7218

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@7218

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@7218

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@7218

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@7218

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@7218

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@7218

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@7218

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@7218

@clerk/types

npm i https://pkg.pr.new/@clerk/types@7218

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@7218

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@7218

commit: 4d93083

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx (1)

253-257: Consider extracting the repeated assertion pattern into a helper function.

The same 5-line assertion pattern appears in six different tests, which introduces maintenance overhead. While the assertions are correct and effectively verify fetcher parameters, extracting this into a reusable helper would improve maintainability.

Consider adding a helper function at the top of the test suite:

function expectAllFetcherCallsToMatch(mock: any, expectedParams: object) {
  expect(mock).toHaveBeenCalled();
  const paramsCalls = mock.mock.calls.map(([params]) => params);
  paramsCalls.forEach(params => {
    expect(params).toStrictEqual(expectedParams);
  });
}

Then replace each occurrence with:

-expect(fetcherMock).toHaveBeenCalled();
-const paramsCalls = fetcherMock.mock.calls.map(([params]) => params);
-paramsCalls.forEach(params => {
-  expect(params).toStrictEqual({ initialPage: 1, pageSize: 2 });
-});
+expectAllFetcherCallsToMatch(fetcherMock, { initialPage: 1, pageSize: 2 });

Also applies to: 303-307, 351-355, 386-390, 438-442, 476-480

packages/clerk-js/src/ui/components/OrganizationSwitcher/__tests__/OrganizationSwitcher.test.tsx (1)

244-248: Consider extracting repeated assertions into a helper function.

The same assertion pattern appears in three test cases (lines 244-248, 479-483, 510-514). While the current implementation is clear and readable, you could optionally reduce duplication with a helper function:

const expectOrganizationMembershipsCalledWithDefaults = (fixtures: any) => {
  expect(fixtures.clerk.user?.getOrganizationMemberships).toHaveBeenCalledTimes(1);
  expect(fixtures.clerk.user?.getOrganizationMemberships.mock.calls[0][0]).toStrictEqual({
    initialPage: 1,
    pageSize: 10,
  });
};

Then replace each occurrence with:

expectOrganizationMembershipsCalledWithDefaults(fixtures);

This would improve maintainability if pagination defaults ever change, but the current approach is also perfectly acceptable for test clarity.

Also applies to: 479-483, 510-514

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between b9e27e3 and 58560c6.

📒 Files selected for processing (7)
  • .changeset/many-pants-pump.md (1 hunks)
  • packages/clerk-js/src/ui/components/OrganizationSwitcher/__tests__/OrganizationSwitcher.test.tsx (3 hunks)
  • packages/clerk-js/src/ui/hooks/__tests__/useCoreOrganization.test.tsx (10 hunks)
  • packages/clerk-js/src/ui/hooks/__tests__/useCoreOrganizationList.test.tsx (11 hunks)
  • packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx (6 hunks)
  • packages/shared/src/react/hooks/__tests__/usePagesOrInfinite.spec.ts (2 hunks)
  • packages/shared/src/react/hooks/__tests__/usePlans.spec.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changeset/many-pants-pump.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/clerk-js/src/ui/hooks/tests/useCoreOrganizationList.test.tsx
  • packages/shared/src/react/hooks/tests/usePlans.spec.tsx
  • packages/shared/src/react/hooks/tests/usePagesOrInfinite.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Build Packages
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (8)
packages/clerk-js/src/ui/hooks/__tests__/useCoreOrganization.test.tsx (5)

149-155: LGTM! Excellent parameter validation for memberships pagination.

The assertions correctly verify that getMemberships is called with the expected pagination parameters, including proper handling of initialPage incrementing on fetchNext and appropriate undefined values for optional role and query parameters.

Also applies to: 208-214


274-279: LGTM! Domains pagination parameters validated correctly.

The assertions properly verify pagination behavior for getDomains, ensuring correct parameter passing across page transitions.

Also applies to: 321-326


392-397: LGTM! Membership requests pagination validated correctly.

The assertions properly validate getMembershipRequests parameters, including the default status: 'pending' value.

Also applies to: 433-438


508-513: LGTM! Invitations pagination parameters validated correctly.

The assertions correctly verify getInvitations parameters, properly using array type for status: ['pending'].

Also applies to: 545-550


619-624: Excellent comprehensive validation for infinite fetch!

The enhanced assertions provide thorough coverage by:

  • Validating exact parameter keys using Object.keys(params).sort()
  • Checking each parameter value across all calls
  • Confirming pagination occurred by verifying initialPage === 2 exists

This approach catches both missing/extra parameters and incorrect values.

Also applies to: 653-661

packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx (1)

253-257: Excellent test coverage improvements!

The added assertions effectively verify that the fetcher is invoked with the exact expected parameter objects across various scenarios (authenticated/unauthenticated, pagination/infinite modes, with/without keepPreviousData). This aligns perfectly with the PR's objective to improve coverage around fetcher parameters.

Also applies to: 303-307, 351-355, 386-390, 438-442, 476-480

packages/clerk-js/src/ui/components/OrganizationSwitcher/__tests__/OrganizationSwitcher.test.tsx (2)

244-248: LGTM! Good test coverage for pagination parameters.

The assertions correctly verify that getOrganizationMemberships is called with the expected pagination defaults when opening the switcher.


479-483: LGTM! Consistent parameter verification.

The assertions correctly verify the pagination parameters when switching organizations.

@panteliselef panteliselef merged commit 6da8819 into main Nov 14, 2025
45 checks passed
@panteliselef panteliselef deleted the elef/improve-fetcher-param-tests branch November 14, 2025 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants