mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +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>
114 lines
3.8 KiB
TypeScript
114 lines
3.8 KiB
TypeScript
import { waitFor } from '@testing-library/react'
|
|
import { HttpResponse } from 'msw'
|
|
import { beforeEach, describe, expect, test, vi } from 'vitest'
|
|
|
|
import {
|
|
useIsVectorBucketsEnabled,
|
|
type ProjectStorageConfigData,
|
|
} from './project-storage-config-query'
|
|
import type { DeploymentMode } from '@/hooks/misc/useDeploymentMode'
|
|
import { customRenderHook } from '@/tests/lib/custom-render'
|
|
import { addAPIMock } from '@/tests/lib/msw'
|
|
|
|
const { mockIsPlatform, mockUseDeploymentMode } = vi.hoisted(() => ({
|
|
mockIsPlatform: { value: false },
|
|
mockUseDeploymentMode: vi.fn<() => DeploymentMode>(),
|
|
}))
|
|
|
|
// `useProjectStorageConfigQuery` (same module as the hook under test) gates its
|
|
// fetch on the build-time `IS_PLATFORM` constant — mock it so the query fires in
|
|
// the platform cases.
|
|
vi.mock('@/lib/constants', async () => {
|
|
const actual = await vi.importActual<Record<string, unknown>>('@/lib/constants')
|
|
return {
|
|
...actual,
|
|
get IS_PLATFORM() {
|
|
return mockIsPlatform.value
|
|
},
|
|
}
|
|
})
|
|
|
|
vi.mock('@/hooks/misc/useDeploymentMode', () => ({
|
|
useDeploymentMode: mockUseDeploymentMode,
|
|
}))
|
|
|
|
const createStorageConfig = (vectorBucketsEnabled: boolean): ProjectStorageConfigData =>
|
|
({
|
|
capabilities: { iceberg_catalog: false, list_v2: false, object_versioning: false },
|
|
external: { upstreamTarget: 'main' },
|
|
features: {
|
|
icebergCatalog: { enabled: false, maxCatalogs: 0, maxNamespaces: 0, maxTables: 0 },
|
|
imageTransformation: { enabled: false },
|
|
s3Protocol: { enabled: false },
|
|
purgeCache: { enabled: false },
|
|
vectorBuckets: { enabled: vectorBucketsEnabled, maxBuckets: 0, maxIndexes: 0 },
|
|
},
|
|
fileSizeLimit: 0,
|
|
migrationVersion: 'v1',
|
|
}) as const
|
|
|
|
const deploymentMode = (overrides: Partial<DeploymentMode>): DeploymentMode => ({
|
|
isPlatform: false,
|
|
isCli: false,
|
|
isSelfHosted: false,
|
|
...overrides,
|
|
})
|
|
|
|
describe('useIsVectorBucketsEnabled', () => {
|
|
beforeEach(() => {
|
|
mockIsPlatform.value = false
|
|
mockUseDeploymentMode.mockReset()
|
|
})
|
|
|
|
test('platform + storage config flag enabled: true', async () => {
|
|
mockIsPlatform.value = true
|
|
mockUseDeploymentMode.mockReturnValue(deploymentMode({ isPlatform: true }))
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/projects/:ref/config/storage',
|
|
response: () => HttpResponse.json<ProjectStorageConfigData>(createStorageConfig(true)),
|
|
})
|
|
|
|
const { result } = customRenderHook(() => useIsVectorBucketsEnabled({ projectRef: 'default' }))
|
|
|
|
await waitFor(() => expect(result.current).toBe(true))
|
|
})
|
|
|
|
test('platform + storage config flag disabled: false', async () => {
|
|
mockIsPlatform.value = true
|
|
mockUseDeploymentMode.mockReturnValue(deploymentMode({ isPlatform: true }))
|
|
|
|
let configRequested = false
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/projects/:ref/config/storage',
|
|
response: () => {
|
|
configRequested = true
|
|
return HttpResponse.json<ProjectStorageConfigData>(createStorageConfig(false))
|
|
},
|
|
})
|
|
|
|
const { result } = customRenderHook(() => useIsVectorBucketsEnabled({ projectRef: 'default' }))
|
|
|
|
await waitFor(() => expect(configRequested).toBe(true))
|
|
expect(result.current).toBe(false)
|
|
})
|
|
|
|
test('CLI: true regardless of the storage config flag', () => {
|
|
// Query is disabled off-platform, so no storage config endpoint is needed.
|
|
mockUseDeploymentMode.mockReturnValue(deploymentMode({ isCli: true }))
|
|
|
|
const { result } = customRenderHook(() => useIsVectorBucketsEnabled({ projectRef: 'default' }))
|
|
|
|
expect(result.current).toBe(true)
|
|
})
|
|
|
|
test('self-hosted: false', () => {
|
|
mockUseDeploymentMode.mockReturnValue(deploymentMode({ isSelfHosted: true }))
|
|
|
|
const { result } = customRenderHook(() => useIsVectorBucketsEnabled({ projectRef: 'default' }))
|
|
|
|
expect(result.current).toBe(false)
|
|
})
|
|
})
|