fix(js): Render standalone APIKeys in org context when user API keys are disabled#9247
Conversation
🦋 Changeset detectedLatest commit: 2496aa0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/electron
@clerk/electron-passkeys
@clerk/eslint-plugin
@clerk/expo
@clerk/expo-google-signin
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
API Changes Report
Summary
No API Changes DetectedAll packages have stable APIs with no detected changes. Report generated by Break Check Last ran on |
📝 WalkthroughWalkthrough
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
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 `@integration/tests/api-keys-component.test.ts`:
- Around line 391-428: Add focused unit tests for the changed logic in Clerk’s
organization API-key handling, covering both organization-active and
no-organization contexts. Verify the disabled-feature behavior for each branch,
including the expected error or no-op outcome, while retaining this Playwright
test for validating the request subject contract.
🪄 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: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro Plus
Run ID: d39e0a58-275a-42e6-bacc-019f192d8cc9
📒 Files selected for processing (3)
.changeset/api-keys-org-context-user-disabled.mdintegration/tests/api-keys-component.test.tspackages/clerk-js/src/core/clerk.ts
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
clerk/clerk_go(manual)clerk/dashboard(manual)clerk/accounts(manual)clerk/backoffice(manual)clerk/clerk(manual)clerk/clerk-docs(manual)clerk/cloudflare-workers(manual)clerk/clerk-ios(auto-detected)clerk/cli(auto-detected)clerk/clerk-android(auto-detected)
| test('standalone API keys component renders in org context when user API keys are disabled', async ({ | ||
| page, | ||
| context, | ||
| }) => { | ||
| const u = createTestUtils({ app, page, context }); | ||
|
|
||
| await u.po.signIn.goTo(); | ||
| await u.po.signIn.waitForMounted(); | ||
| await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeAdmin.email, password: fakeAdmin.password }); | ||
| await u.po.expect.toBeSignedIn(); | ||
|
|
||
| await u.po.organizationSwitcher.goTo(); | ||
| await u.po.organizationSwitcher.waitForMounted(); | ||
| await u.po.organizationSwitcher.waitForAnOrganizationToSelected(); | ||
|
|
||
| await mockAPIKeysEnvironmentSettings(u.page, { user_api_keys_enabled: false }); | ||
|
|
||
| let capturedSubject: string | null = null; | ||
| const apiKeyRequestPromise = u.page.waitForRequest(request => { | ||
| if (request.url().includes('api_keys')) { | ||
| const url = new URL(request.url()); | ||
| capturedSubject = url.searchParams.get('subject'); | ||
| return true; | ||
| } | ||
| return false; | ||
| }); | ||
|
|
||
| await u.po.page.goToRelative('/api-keys'); | ||
| await u.po.apiKeys.waitForMounted(); | ||
| await expect(u.page.locator('.cl-apiKeys-root')).toBeVisible(); | ||
|
|
||
| // Org API keys are listed, so the subject must be the organization | ||
| await apiKeyRequestPromise; | ||
| expect(capturedSubject).toBe(fakeOrganization.organization.id); | ||
|
|
||
| await u.page.unrouteAll(); | ||
| }); | ||
|
|
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Add focused unit coverage for both guard branches.
This Playwright test covers the happy path, but the changed logic in packages/clerk-js/src/core/clerk.ts also needs unit coverage for organization-active versus no-organization contexts, including the disabled-feature error/no-op behavior. Retain this integration test for the request-subject contract.
As per coding guidelines, unit tests are required for all new functionality and must cover error handling and edge cases.
🤖 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 `@integration/tests/api-keys-component.test.ts` around lines 391 - 428, Add
focused unit tests for the changed logic in Clerk’s organization API-key
handling, covering both organization-active and no-organization contexts. Verify
the disabled-feature behavior for each branch, including the expected error or
no-op outcome, while retaining this Playwright test for validating the request
subject contract.
Source: Coding guidelines
Description
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change