Files
supabase/apps/studio/components/layouts/APIKeys/APIKeysLayout.test.tsx
Ali Waseem e8f9359a98 fix(studio): hide legacy API keys on High Availability projects (#49552)
Multigres (High Availability) projects ship with legacy API keys
disabled and the management API rejects re-enabling them, so the
Dashboard should not surface them at all.

Hides the "Legacy anon, service_role API keys" tab, renders an empty
state on the legacy page for direct URL access, and drops the "Copy
anonymous API key" / "Copy service API key" commands from the command
menu. Non-HA projects are unchanged.

Fixes FE-4276

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* High Availability projects now hide legacy API key navigation and
commands.
* Legacy API key settings display an unavailable message for High
Availability projects.
  * Publishable and secret key options remain available where supported.
* Other projects continue to provide access to supported legacy API key
options.

* **Bug Fixes**
* Prevented unsupported legacy API key controls from appearing on High
Availability projects.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2026-08-26 10:17:28 +00:00

52 lines
1.4 KiB
TypeScript

import { screen } from '@testing-library/react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import ApiKeysLayout from './APIKeysLayout'
import { customRender } from '@/tests/lib/custom-render'
const { mockUseHighAvailability } = vi.hoisted(() => ({
mockUseHighAvailability: vi.fn(),
}))
vi.mock('@/hooks/misc/useHighAvailability', () => ({
useHighAvailability: mockUseHighAvailability,
}))
const LEGACY_TAB = 'Legacy anon, service_role API keys'
const NEW_TAB = 'Publishable and secret API keys'
describe('ApiKeysLayout', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('hides the legacy keys tab on High Availability projects', () => {
mockUseHighAvailability.mockReturnValue({ isHighAvailability: true, isPending: false })
customRender(
<ApiKeysLayout>
<div>content</div>
</ApiKeysLayout>
)
expect(screen.getByText(NEW_TAB)).toBeInTheDocument()
expect(screen.queryByText(LEGACY_TAB)).not.toBeInTheDocument()
})
it('shows the legacy keys tab on other projects', () => {
mockUseHighAvailability.mockReturnValue({ isHighAvailability: false, isPending: false })
customRender(
<ApiKeysLayout>
<div>content</div>
</ApiKeysLayout>
)
expect(screen.getByText(NEW_TAB)).toBeInTheDocument()
expect(screen.getByRole('link', { name: LEGACY_TAB })).toHaveAttribute(
'href',
'/project/default/settings/api-keys/legacy'
)
})
})