mirror of
https://github.com/supabase/supabase.git
synced 2026-09-22 13:37:53 +08:00
737b8595f2
## 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>
104 lines
3.4 KiB
TypeScript
104 lines
3.4 KiB
TypeScript
import { screen, waitFor } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import { mockAnimationsApi } from 'jsdom-testing-mocks'
|
|
import { HttpResponse } from 'msw'
|
|
import { toast } from 'sonner'
|
|
import { describe, expect, test, vi } from 'vitest'
|
|
|
|
import { SwitchToPreviewModal } from './SwitchToPreviewModal'
|
|
import type { components } from '@/data/api'
|
|
import type { Branch } from '@/data/branches/branches-query'
|
|
import { customRender } from '@/tests/lib/custom-render'
|
|
import { addAPIMock, type APIErrorBody } from '@/tests/lib/msw'
|
|
|
|
mockAnimationsApi()
|
|
|
|
vi.mock('sonner', () => ({
|
|
toast: { success: vi.fn(), error: vi.fn() },
|
|
}))
|
|
|
|
type BranchUpdateResponse = components['schemas']['BranchUpdateResponse_Output']
|
|
|
|
const PARENT_PROJECT_REF = 'parent-project-ref'
|
|
const BRANCH_PROJECT_REF = 'branch-project-ref'
|
|
|
|
const BRANCH: Branch = {
|
|
created_at: '2026-01-01T00:00:00.000Z',
|
|
id: '00000000-0000-0000-0000-000000000001',
|
|
is_default: false,
|
|
name: 'docs-local-staging',
|
|
parent_project_ref: PARENT_PROJECT_REF,
|
|
persistent: true,
|
|
project_ref: BRANCH_PROJECT_REF,
|
|
status: 'MIGRATIONS_PASSED',
|
|
updated_at: '2026-01-01T00:00:00.000Z',
|
|
with_data: false,
|
|
}
|
|
|
|
const mockBranchUpdate = () => {
|
|
const requests: Array<{ branchRef: string | undefined; body: unknown }> = []
|
|
|
|
addAPIMock({
|
|
method: 'patch',
|
|
path: '/v1/branches/:branch_id_or_ref',
|
|
response: async ({ request, params }) => {
|
|
requests.push({
|
|
branchRef: params.branch_id_or_ref as string | undefined,
|
|
body: await request.json(),
|
|
})
|
|
return HttpResponse.json<BranchUpdateResponse>({
|
|
message: 'ok',
|
|
workflow_run_id: 'workflow-run-1',
|
|
})
|
|
},
|
|
})
|
|
|
|
return requests
|
|
}
|
|
|
|
const renderModal = (overrides: { branch?: Branch; onClose?: () => void } = {}) => {
|
|
const onClose = overrides.onClose ?? vi.fn()
|
|
customRender(<SwitchToPreviewModal open branch={overrides.branch} onClose={onClose} />)
|
|
return { onClose }
|
|
}
|
|
|
|
describe('SwitchToPreviewModal', () => {
|
|
test('switches the branch to preview using the refs on the branch', async () => {
|
|
const requests = mockBranchUpdate()
|
|
|
|
const { onClose } = renderModal({ branch: BRANCH })
|
|
|
|
await userEvent.click(await screen.findByRole('button', { name: 'Switch to preview' }))
|
|
|
|
await waitFor(() => expect(onClose).toHaveBeenCalledOnce())
|
|
expect(requests).toEqual([{ branchRef: BRANCH_PROJECT_REF, body: { persistent: false } }])
|
|
expect(toast.success).toHaveBeenCalledWith('Successfully updated branch')
|
|
})
|
|
|
|
test('surfaces the error and keeps the modal open when the update fails', async () => {
|
|
addAPIMock({
|
|
method: 'patch',
|
|
path: '/v1/branches/:branch_id_or_ref',
|
|
response: () =>
|
|
HttpResponse.json<APIErrorBody>({ message: 'Something exploded' }, { status: 500 }),
|
|
})
|
|
|
|
const { onClose } = renderModal({ branch: BRANCH })
|
|
|
|
const confirm = await screen.findByRole('button', { name: 'Switch to preview' })
|
|
await userEvent.click(confirm)
|
|
|
|
await waitFor(() =>
|
|
expect(toast.error).toHaveBeenCalledWith('Failed to update branch: Something exploded')
|
|
)
|
|
expect(onClose).not.toHaveBeenCalled()
|
|
expect(confirm).toBeEnabled()
|
|
})
|
|
|
|
test('disables the confirm button while the branch is unavailable', async () => {
|
|
renderModal()
|
|
|
|
expect(await screen.findByRole('button', { name: 'Switch to preview' })).toBeDisabled()
|
|
})
|
|
})
|