Files
supabase/apps/studio/components/interfaces/ProjectCreation/ProjectCreation.schema.test.ts
T
Jordi Enric 6f36fe879b fix(studio): require an available project region FE-3884 (#51582)
## Problem

Project creation can send a request without a region, which the API
rejects. Empty region values pass frontend validation, and a failed
available-regions request fills in a static region name that cannot
resolve to a region selection.

## Fix

Keep the region selector controlled from mount and require a nonempty
value. Disable creation when available regions fail to load, guard
submission against unresolved region selections, and preserve the static
fallback for providers that use it.

Fixes
[FE-3884](https://linear.app/supabase/issue/FE-3884/project-creation-wizard-can-submit-with-an-empty-region).

## How to test

- Open the new-project form and verify the recommended region submits
without manually selecting a region.
- Submit with an empty region. Expected result: an inline validation
error appears and no project creation request is sent.
- Fail the available-regions endpoint, including after changing compute
size with a region already selected. Expected result: the region-loading
error appears, creation is disabled, and direct form submission sends no
project creation request.
- Run `pnpm --filter studio exec vitest --run
'tests/pages/new/[slug].test.tsx'
tests/pages/vercel-deploy-button-new-project.test.tsx
components/interfaces/ProjectCreation/ProjectCreation.schema.test.ts`.

Local validation: all 54 focused tests and formatting pass. Focused
ESLint has no errors. Local typecheck reports the existing image type
mismatch in InstructionBlocks.tsx; CI typecheck passed for the previous
commit.
2026-10-13 12:20:43 +02:00

44 lines
1.3 KiB
TypeScript

import { describe, expect, test } from 'vitest'
import { FormSchema, type CreateProjectForm } from './ProjectCreation.schema'
const validProject: CreateProjectForm = {
organization: 'default-org',
projectName: 'Region Project',
highAvailability: false,
postgresVersion: '',
dbRegion: 'Americas',
cloudProvider: 'AWS',
dbPass: 'strong-database-password',
dbPassStrength: 4,
dbPassStrengthMessage: '',
dbPassStrengthWarning: '',
githubRepositoryId: '',
githubRepositoryName: '',
dataApi: true,
dataApiDefaultPrivileges: true,
enableRlsEventTrigger: false,
postgresVersionSelection: '',
useOrioleDb: false,
shouldRunMigrations: true,
}
describe('project creation region validation', () => {
test.each([undefined, '', ' '])('rejects a missing region (%j)', (dbRegion) => {
const result = FormSchema.safeParse({ ...validProject, dbRegion })
expect(result.success).toBe(false)
if (result.success) throw new Error('Expected region validation to fail')
expect(result.error.issues).toEqual([
expect.objectContaining({ path: ['dbRegion'], message: 'Please select a region.' }),
])
})
test.each(['Americas', 'East US (North Virginia)'])(
'accepts a selected region (%s)',
(dbRegion) => {
expect(FormSchema.safeParse({ ...validProject, dbRegion }).success).toBe(true)
}
)
})