mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 09:55:06 +03:00
## Problem platform, v1 and v2 have been already completely migrated and introduced some changes. Some types have been renamed, some outputs and inputs updated. ## Solution - Update the API types - Fix the TS errors ## Update Taking this over to unblock #50134, which needs the new scoped token permission ids from the regenerated types. - Merged `master`. - Regenerated `api-v2.d.ts` from the production spec. The previous files came from a local API that exposed a webhook events endpoint production doesn't have yet. Production has since added standardized 400 error responses on the v2 organization endpoints. `api-v1.d.ts` and `platform.d.ts` already matched production. - Fixed `verify-production-types`. It formatted the regenerated files in a temp directory outside the repository, so Prettier fell back to its defaults and the comparison could never match the committed files. It now passes the repository config explicitly. `pnpm api:verify-types` passes on this branch. - Verified locally: `pnpm typecheck`, `pnpm api:verify-types`, Studio unit tests. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Preserved descriptions when saving, sharing, moving, or unsharing notebooks, reports, SQL snippets, and saved queries. * Improved handling of empty or null values across notebook descriptions, billing usage, pooler settings, and infrastructure fields. * Improved read-replica connection handling, including read-only connection strings. * Updated storage configuration and capability handling to match current settings. * **API and Compatibility** * Updated organization, project, storage, OAuth, billing, and infrastructure data handling to match current API responses. * OAuth app creation and updates now require scopes. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
98 lines
3.5 KiB
TypeScript
98 lines
3.5 KiB
TypeScript
import { screen } from '@testing-library/react'
|
|
import { HttpResponse } from 'msw'
|
|
import { beforeEach, describe, expect, test, vi } from 'vitest'
|
|
|
|
import { ReadReplicasSection } from '@/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicasSection'
|
|
import type { components } from '@/data/api'
|
|
import { customRender } from '@/tests/lib/custom-render'
|
|
import { addAPIMock } from '@/tests/lib/msw'
|
|
|
|
type DatabaseDetailResponse = components['schemas']['DatabaseDetailResponse_Output']
|
|
type DatabaseStatusResponse = components['schemas']['DatabaseStatusResponse_Output']
|
|
type LoadBalancerDetailResponse = components['schemas']['LoadBalancerDetailResponse_Output']
|
|
|
|
const { mockUseIsFeatureEnabled } = vi.hoisted(() => ({
|
|
mockUseIsFeatureEnabled: vi.fn(() => ({ infrastructureReadReplicas: true })),
|
|
}))
|
|
|
|
vi.mock('@/hooks/misc/useIsFeatureEnabled', () => ({
|
|
useIsFeatureEnabled: mockUseIsFeatureEnabled,
|
|
}))
|
|
vi.mock(
|
|
'@/components/interfaces/Settings/Infrastructure/ReadReplicas/AddReadReplicaDialog',
|
|
() => ({ AddReadReplicaDialog: () => null })
|
|
)
|
|
|
|
const addReplicaListMocks = () => {
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/projects/:ref/databases',
|
|
response: () =>
|
|
HttpResponse.json<DatabaseDetailResponse[]>([
|
|
{
|
|
cloud_provider: 'AWS',
|
|
connectionString: 'postgresql://postgres:password@db.default.supabase.co:5432/postgres',
|
|
connection_string_read_only:
|
|
'postgresql://postgres:password@db.default.supabase.co:5432/postgres',
|
|
db_host: 'db.default.supabase.co',
|
|
db_name: 'postgres',
|
|
db_port: 5432,
|
|
db_user: 'postgres',
|
|
identifier: 'default',
|
|
inserted_at: '2026-01-01T00:00:00.000Z',
|
|
region: 'us-east-1',
|
|
restUrl: 'https://default.supabase.co',
|
|
size: 't4g.small',
|
|
status: 'ACTIVE_HEALTHY',
|
|
},
|
|
]),
|
|
})
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/projects/:ref/databases-statuses',
|
|
response: () => HttpResponse.json<DatabaseStatusResponse[]>([]),
|
|
})
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/projects/:ref/load-balancers',
|
|
response: () => HttpResponse.json<LoadBalancerDetailResponse[]>([]),
|
|
})
|
|
}
|
|
|
|
describe('ReadReplicasSection', () => {
|
|
beforeEach(() => {
|
|
mockUseIsFeatureEnabled.mockReturnValue({ infrastructureReadReplicas: true })
|
|
})
|
|
|
|
test('renders the read replicas section with add CTA and empty state', async () => {
|
|
mockUseIsFeatureEnabled.mockReturnValue({ infrastructureReadReplicas: true })
|
|
addReplicaListMocks()
|
|
|
|
customRender(<ReadReplicasSection onRecommendCompute={vi.fn()} />)
|
|
|
|
expect(await screen.findByText('Read replicas')).toBeInTheDocument()
|
|
expect(await screen.findByText('No read replicas')).toBeInTheDocument()
|
|
expect(screen.getAllByRole('button', { name: /Add read replica/i }).length).toBeGreaterThan(0)
|
|
})
|
|
|
|
test('does not fetch replicas when the feature is disabled', async () => {
|
|
mockUseIsFeatureEnabled.mockReturnValue({ infrastructureReadReplicas: false })
|
|
|
|
let fetchedReplicas = false
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/projects/:ref/databases',
|
|
response: () => {
|
|
fetchedReplicas = true
|
|
return HttpResponse.json<DatabaseDetailResponse[]>([])
|
|
},
|
|
})
|
|
|
|
customRender(<ReadReplicasSection onRecommendCompute={vi.fn()} />)
|
|
|
|
expect(screen.queryByText('Read replicas')).not.toBeInTheDocument()
|
|
await new Promise((resolve) => setTimeout(resolve, 50))
|
|
expect(fetchedReplicas).toBe(false)
|
|
})
|
|
})
|