mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
Regenerates the API types with `pnpm api:codegen:prod` and fixes the
Studio type errors the new types caused.
## Changes from the API
- **Branch merge now requires production write permission.** `POST
/v1/branches/{branch_id_or_ref}/merge` changed from accepting either
`branching_development_write` or `branching_production_write` to
requiring `branching_production_write`. Studio's FGA refinement for
merge no longer matched and failed typecheck.
- Removed the merge entry from `lib/fga-refinements.ts`.
- `merge.tsx` checks merge permission with `useGrant` instead of
`useBranchGrant`.
- `BranchMergeGrant` uses `GrantFor` instead of `GrantForVariants`.
- Removed merge from the "requires a variant" test in
`guarded-fetch.test.ts`.
- Users with only development branching permissions can no longer merge
in Studio. This matches what the API now enforces.
- **Replication pipelines have a required `cluster_id`.** Added it to
the pipeline fixtures in six test files.
- **`MemberWithFreeProjectLimit` has a required
`free_plan_organizations`.** Added it to the mock in
`tests/pages/new/[slug].test.tsx`. No app code reads it yet.
## Testing
- `pnpm typecheck` passes.
- Vitest passes for the affected Studio tests.
105 lines
3.7 KiB
TypeScript
105 lines
3.7 KiB
TypeScript
import { QueryClient } from '@tanstack/react-query'
|
|
import { waitFor } from '@testing-library/react'
|
|
import type { components } from 'api-types'
|
|
import { HttpResponse } from 'msw'
|
|
import { expect, test } from 'vitest'
|
|
|
|
import { useCreateDestinationPipelineMutation } from './create-destination-pipeline-mutation'
|
|
import { useReplicationDestinationsQuery } from './destinations-query'
|
|
import { useReplicationPipelinesQuery } from './pipelines-query'
|
|
import { customRenderHook } from '@/tests/lib/custom-render'
|
|
import { addAPIMock } from '@/tests/lib/msw'
|
|
|
|
type Destination = components['schemas']['DestinationsResponse_Output']['destinations'][number]
|
|
type Pipeline = components['schemas']['PipelinesResponse_Output']['pipelines'][number]
|
|
|
|
const destination: Destination = {
|
|
id: 7,
|
|
name: 'Warehouse',
|
|
tenant_id: 'tenant',
|
|
config: { big_query: { project_id: 'warehouse', dataset_id: 'analytics' } },
|
|
}
|
|
const pipeline: Pipeline = {
|
|
id: '8',
|
|
cluster_id: 'cluster',
|
|
destination_id: 7,
|
|
destination_name: 'Warehouse',
|
|
source_id: 1,
|
|
source_name: 'default',
|
|
tenant_id: 'tenant',
|
|
replicator_id: 9,
|
|
config: { publication_name: 'analytics' },
|
|
}
|
|
|
|
// Regression: lists were mounted with `refetchOnMount: false`, so after creating a pipeline
|
|
// elsewhere, returning to the (unmounted) list page kept showing the stale cache.
|
|
test('shows a newly created pipeline when returning to the list page', async () => {
|
|
const queryClient = new QueryClient({
|
|
defaultOptions: { queries: { retry: false, staleTime: Infinity } },
|
|
})
|
|
|
|
let hasCreated = false
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/destinations',
|
|
response: () =>
|
|
HttpResponse.json<components['schemas']['DestinationsResponse_Output']>({
|
|
destinations: hasCreated ? [destination] : [],
|
|
}),
|
|
})
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/replication/:ref/pipelines',
|
|
response: () =>
|
|
HttpResponse.json<components['schemas']['PipelinesResponse_Output']>({
|
|
pipelines: hasCreated ? [pipeline] : [],
|
|
}),
|
|
})
|
|
addAPIMock({
|
|
method: 'post',
|
|
path: '/platform/replication/:ref/destinations-pipelines',
|
|
response: () => {
|
|
hasCreated = true
|
|
return HttpResponse.json<components['schemas']['CreateDestinationPipelineResponse_Output']>({
|
|
destination_id: 7,
|
|
pipeline_id: '8',
|
|
})
|
|
},
|
|
})
|
|
|
|
const useLists = () => ({
|
|
destinations: useReplicationDestinationsQuery({ projectRef: 'default' }),
|
|
pipelines: useReplicationPipelinesQuery({ projectRef: 'default' }),
|
|
})
|
|
|
|
// Visit the list page while it's empty, then navigate away
|
|
const listPage = customRenderHook(useLists, { queryClient })
|
|
await waitFor(() => {
|
|
expect(listPage.result.current.destinations.data?.destinations).toEqual([])
|
|
expect(listPage.result.current.pipelines.data?.pipelines).toEqual([])
|
|
})
|
|
listPage.unmount()
|
|
|
|
// Create a pipeline from another page
|
|
const createPage = customRenderHook(() => useCreateDestinationPipelineMutation(), {
|
|
queryClient,
|
|
})
|
|
await createPage.result.current.mutateAsync({
|
|
projectRef: 'default',
|
|
destinationName: 'Warehouse',
|
|
destinationConfig: {
|
|
bigQuery: { projectId: 'warehouse', datasetId: 'analytics', serviceAccountKey: '{}' },
|
|
},
|
|
sourceId: 1,
|
|
pipelineConfig: { publicationName: 'analytics', tableSyncCopy: { type: 'include_all_tables' } },
|
|
})
|
|
createPage.unmount()
|
|
|
|
// Return to the list page
|
|
const returnedPage = customRenderHook(useLists, { queryClient })
|
|
await waitFor(() => {
|
|
expect(returnedPage.result.current.destinations.data?.destinations).toEqual([destination])
|
|
expect(returnedPage.result.current.pipelines.data?.pipelines).toEqual([pipeline])
|
|
})
|
|
})
|