mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 00:19:08 +00:00
fix(studio): give downloadable backups their own query key (FE-5243)
useDownloadableBackupQuery and useBackupsQuery shared one query key for two different endpoints. The failed restore screen mounts both, so one could read the other's data: Download backup used the wrong list. Split the key, restore the original support copy so it stays accurate when no retry is offered, and drop the local `common` mock from the new test in favor of the harness auth context. Add a test for the screen that fails when the key is shared again.
This commit is contained in:
1 parent
1e40636464
commit
83263dc580
4 files changed
+65
-10
No files matched your search
@@ -84,7 +84,7 @@ export const RestoreFailedState = () => {
|
||||
<InlineLink href={`/project/${ref}/database/backups/scheduled`}>here</InlineLink>.
|
||||
</p>
|
||||
<p className="text-sm text-foreground-light">
|
||||
Retry the restore, or contact support for assistance.
|
||||
Please contact support for assistance.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -3,9 +3,11 @@ import userEvent from '@testing-library/user-event'
|
||||
import { platformComponents as components } from 'api-types'
|
||||
import { mockAnimationsApi } from 'jsdom-testing-mocks'
|
||||
import { HttpResponse } from 'msw'
|
||||
import { describe, expect, test, vi } from 'vitest'
|
||||
import { describe, expect, test } from 'vitest'
|
||||
|
||||
import { RestoreFailedState } from './RestoreFailedState'
|
||||
import { RetryFailedRestore } from './RetryFailedRestore'
|
||||
import { createMockAuthContext } from '@/tests/lib/auth-helpers'
|
||||
import { customRender } from '@/tests/lib/custom-render'
|
||||
import { addAPIMock } from '@/tests/lib/msw'
|
||||
import { NO_PERMISSIONS } from '@/tests/lib/permissions-fixtures'
|
||||
@@ -14,11 +16,7 @@ import { mockProjectGrantContext } from '@/tests/lib/project-grant-mocks'
|
||||
|
||||
type BackupsResponse = components['schemas']['BackupsResponse_Output']
|
||||
type Backup = BackupsResponse['backups'][number]
|
||||
|
||||
vi.mock('common', async () => {
|
||||
const actual = await vi.importActual<Record<string, unknown>>('common')
|
||||
return { ...actual, useIsLoggedIn: () => true, useParams: () => ({ ref: 'default' }) }
|
||||
})
|
||||
type DownloadableBackupsResponse = components['schemas']['DownloadableBackupsResponse_Output']
|
||||
|
||||
mockAnimationsApi()
|
||||
|
||||
@@ -65,8 +63,12 @@ const clickRetryRestore = async () => {
|
||||
fireEvent.click(button)
|
||||
}
|
||||
|
||||
const renderComponent = () =>
|
||||
customRender(<RetryFailedRestore />, { profileContext: createMockProfileContext() })
|
||||
const renderOptions = {
|
||||
authContext: createMockAuthContext(),
|
||||
profileContext: createMockProfileContext(),
|
||||
}
|
||||
|
||||
const renderComponent = () => customRender(<RetryFailedRestore />, renderOptions)
|
||||
|
||||
describe('RetryFailedRestore', () => {
|
||||
test('retries the restore from the latest completed physical backup by default', async () => {
|
||||
@@ -135,4 +137,55 @@ describe('RetryFailedRestore', () => {
|
||||
|
||||
expect(await screen.findByRole('button', { name: 'Retry restore' })).toBeAriaDisabled()
|
||||
})
|
||||
|
||||
// The screen also loads the downloadable backups: a different list, from a different endpoint
|
||||
test('keeps both backup lists separate on the failed restore screen', async () => {
|
||||
mockProjectGrantContext({ ref: 'default' })
|
||||
addAPIMock({
|
||||
method: 'get',
|
||||
path: '/platform/organizations/:slug/billing/subscription',
|
||||
response: {
|
||||
addons: [],
|
||||
billing_via_partner: false,
|
||||
current_period_end: 1700000000,
|
||||
current_period_start: 1700000000,
|
||||
next_invoice_at: 1700000000,
|
||||
payment_method_type: 'card',
|
||||
plan: { id: 'pro', name: 'Pro' },
|
||||
project_addons: [],
|
||||
usage_billing_enabled: false,
|
||||
},
|
||||
})
|
||||
mockBackups([createBackup({ id: 1, inserted_at: '2026-11-20T03:00:00.000Z' })])
|
||||
addAPIMock({
|
||||
method: 'get',
|
||||
path: '/platform/database/:ref/backups/downloadable-backups',
|
||||
response: () =>
|
||||
HttpResponse.json<DownloadableBackupsResponse>({
|
||||
status: 'ok',
|
||||
backups: [createBackup({ id: 99, isPhysicalBackup: false })],
|
||||
}),
|
||||
})
|
||||
const downloads: unknown[] = []
|
||||
addAPIMock({
|
||||
method: 'post',
|
||||
path: '/platform/database/:ref/backups/download',
|
||||
response: async ({ request }) => {
|
||||
downloads.push(await request.json())
|
||||
return HttpResponse.json<{ fileUrl: string }>({ fileUrl: '#backup' })
|
||||
},
|
||||
})
|
||||
|
||||
customRender(<RestoreFailedState />, renderOptions)
|
||||
|
||||
expect(await screen.findByRole('combobox', { name: 'Backup' })).toHaveTextContent(
|
||||
'20 Nov 2026 03:00:00 (UTC)'
|
||||
)
|
||||
|
||||
const downloadButton = screen.getByRole('button', { name: 'Download backup' })
|
||||
await waitFor(() => expect(downloadButton).not.toBeAriaDisabled())
|
||||
fireEvent.click(downloadButton)
|
||||
|
||||
await waitFor(() => expect(downloads).toEqual([{ id: 99 }]))
|
||||
})
|
||||
})
|
||||
@@ -36,7 +36,7 @@ export const useDownloadableBackupQuery = <TData = DownloadableBackupData>(
|
||||
}: UseCustomQueryOptions<DownloadableBackupData, DownloadableBackupError, TData> = {}
|
||||
) =>
|
||||
useQuery<DownloadableBackupData, DownloadableBackupError, TData>({
|
||||
queryKey: databaseKeys.backups(projectRef),
|
||||
queryKey: databaseKeys.downloadableBackups(projectRef),
|
||||
queryFn: ({ signal }) => getDownloadableBackup({ projectRef }, signal),
|
||||
enabled: enabled && typeof projectRef !== 'undefined',
|
||||
...options,
|
||||
|
||||
@@ -35,6 +35,8 @@ export const databaseKeys = {
|
||||
['projects', projectRef, 'view-definition', id, includeCreateStatement ?? false] as const,
|
||||
backups: (projectRef: string | undefined) =>
|
||||
['projects', projectRef, 'database', 'backups'] as const,
|
||||
downloadableBackups: (projectRef: string | undefined) =>
|
||||
['projects', projectRef, 'database', 'downloadable-backups'] as const,
|
||||
poolingConfiguration: (projectRef: string | undefined) =>
|
||||
['projects', projectRef, 'database', 'pooling-configuration'] as const,
|
||||
indexesFromQuery: (projectRef: string | undefined, query: string) =>
|
||||
|
||||
Reference in new issue
Block a user