mirror of
https://github.com/supabase/supabase.git
synced 2026-10-08 02:45:07 +03:00
## Problem
We want to be able to show free-plan organizations a simplified region
selector that only lists general regions (Americas, Europe,
Asia-Pacific), controlled per organization through ConfigCat.
## Solution
- ConfigCat flags are now evaluated with `organization_slug` and
`organization_created_at` (Unix seconds) custom attributes, so flags can
target and bucket by organization.
- `organization_created_at` is read from `GET
/platform/organizations/{slug}`, fetched only for free-plan
organizations, since the organization list response doesn't include it.
- Two flags:
- `freeTierGeneralRegionEnrollment`: the organization is enrolled
(control or test).
- `freeTierGeneralRegionSelection`: the organization sees only general
regions.
- For enrolled free organizations, the region selector stays in its
loading state until flags have been evaluated with the organization's
creation time, so specific regions aren't shown and then removed.
- In the test variant, the selector hides specific regions and shows a
footer linking to the plan upgrade panel. High Availability keeps its
own region list.
- Telemetry: new `free_tier_general_region_experiment_exposed` and
`free_tier_general_region_upgrade_clicked` events, and
`freeTierGeneralRegionExperiment` / `regionSelectionType` properties on
`project_creation_simple_version_submitted`.
- `created_at` is added to `OrganizationSlugResponse` in the generated
platform types, matching the API.
## Review instructions
1. With both flags off, open `/new/[slug]` for a free organization and
confirm the region selector is unchanged.
2. Using the dev toolbar, set `freeTierGeneralRegionEnrollment` and
`freeTierGeneralRegionSelection` to `true`. Confirm only general regions
are listed and the footer links to the billing plan panel.
3. Set `freeTierGeneralRegionSelection` to `false` and confirm the full
selector is shown.
4. Repeat with a paid organization and confirm the full selector is
always shown.
201 lines
6.7 KiB
TypeScript
201 lines
6.7 KiB
TypeScript
import { AWS_REGIONS } from 'shared-data'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import {
|
|
HIGH_AVAILABILITY_INSTANCE_SIZE,
|
|
HIGH_AVAILABILITY_POSTGRES_ENGINE,
|
|
HIGH_AVAILABILITY_RELEASE_CHANNEL,
|
|
} from './ProjectCreation.constants'
|
|
import type { AvailableRegions } from './ProjectCreation.utils'
|
|
import {
|
|
filterHighAvailabilityRegions,
|
|
getAvailableRegions,
|
|
getFreeTierGeneralRegionExperimentVariant,
|
|
getHighAvailabilityRegionCode,
|
|
getRegionSelectionType,
|
|
resolveDefaultDbRegion,
|
|
} from './ProjectCreation.utils'
|
|
|
|
describe('resolveDefaultDbRegion', () => {
|
|
const base = {
|
|
cloudProvider: 'AWS_NIMBUS',
|
|
isHighAvailabilityRestricted: false,
|
|
highAvailabilityRegionName: undefined,
|
|
isSmartRegionEnabled: false,
|
|
recommendedSmartRegion: undefined,
|
|
autoDefaultRegion: undefined,
|
|
fixedDefaultRegion: AWS_REGIONS.EAST_US.displayName,
|
|
environment: 'prod',
|
|
} as const
|
|
|
|
it('prefers the high availability region when restricted, even while it is still loading', () => {
|
|
expect(
|
|
resolveDefaultDbRegion({
|
|
...base,
|
|
isHighAvailabilityRestricted: true,
|
|
highAvailabilityRegionName: AWS_REGIONS.EAST_US.displayName,
|
|
})
|
|
).toBe(AWS_REGIONS.EAST_US.displayName)
|
|
expect(resolveDefaultDbRegion({ ...base, isHighAvailabilityRestricted: true })).toBeUndefined()
|
|
})
|
|
|
|
it('uses the recommended smart region when smart regions are enabled', () => {
|
|
expect(
|
|
resolveDefaultDbRegion({
|
|
...base,
|
|
cloudProvider: 'AWS',
|
|
isSmartRegionEnabled: true,
|
|
recommendedSmartRegion: 'Americas',
|
|
autoDefaultRegion: AWS_REGIONS.SOUTHEAST_ASIA.displayName,
|
|
})
|
|
).toBe('Americas')
|
|
})
|
|
|
|
it('uses the geolocated region when the provider offers it', () => {
|
|
expect(
|
|
resolveDefaultDbRegion({
|
|
...base,
|
|
cloudProvider: 'AWS',
|
|
autoDefaultRegion: AWS_REGIONS.SOUTHEAST_ASIA.displayName,
|
|
})
|
|
).toBe(AWS_REGIONS.SOUTHEAST_ASIA.displayName)
|
|
})
|
|
|
|
it('falls back to the fixed default when the provider does not offer the geolocated region', () => {
|
|
expect(
|
|
resolveDefaultDbRegion({ ...base, autoDefaultRegion: AWS_REGIONS.SOUTHEAST_ASIA.displayName })
|
|
).toBe(AWS_REGIONS.EAST_US.displayName)
|
|
})
|
|
|
|
it('falls back to the fixed default when no geolocated region resolved', () => {
|
|
expect(resolveDefaultDbRegion(base)).toBe(AWS_REGIONS.EAST_US.displayName)
|
|
})
|
|
})
|
|
|
|
describe('getAvailableRegions', () => {
|
|
it.each(['local', 'staging', 'prod'])('returns all AWS regions for AWS on %s', (environment) => {
|
|
expect(getAvailableRegions('AWS', environment)).toEqual(AWS_REGIONS)
|
|
expect(getAvailableRegions('AWS_K8S', environment)).toEqual(AWS_REGIONS)
|
|
})
|
|
|
|
it.each([
|
|
['local', { SOUTHEAST_ASIA: AWS_REGIONS.SOUTHEAST_ASIA }],
|
|
['staging', { SOUTHEAST_ASIA: AWS_REGIONS.SOUTHEAST_ASIA }],
|
|
['prod', { EAST_US: AWS_REGIONS.EAST_US }],
|
|
])('returns the single AWS_NIMBUS region on %s', (environment, expectedRegions) => {
|
|
expect(getAvailableRegions('AWS_NIMBUS', environment)).toEqual(expectedRegions)
|
|
})
|
|
})
|
|
|
|
describe('High Availability project creation constraints', () => {
|
|
it('pins the Alpha Postgres engine, release channel, and compute size', () => {
|
|
expect(HIGH_AVAILABILITY_POSTGRES_ENGINE).toBe('17')
|
|
expect(HIGH_AVAILABILITY_RELEASE_CHANNEL).toBe('ga')
|
|
expect(HIGH_AVAILABILITY_INSTANCE_SIZE).toBe('large')
|
|
})
|
|
|
|
it.each([
|
|
['local', 'eu-central-1'],
|
|
['staging', 'us-east-1'],
|
|
['prod', 'us-east-1'],
|
|
])('resolves the %s region restriction', (environment, expectedRegion) => {
|
|
expect(getHighAvailabilityRegionCode(environment)).toBe(expectedRegion)
|
|
})
|
|
|
|
it.each([
|
|
['local', undefined],
|
|
['staging', 'us-east-1'],
|
|
['prod', 'us-east-1'],
|
|
])(
|
|
'applies the %s region restriction to high availability projects',
|
|
(environment, expectedRegion) => {
|
|
const regions = [{ code: 'us-east-1' }, { code: 'eu-central-1' }, { code: 'ap-southeast-1' }]
|
|
|
|
expect(filterHighAvailabilityRegions(regions, true, environment)).toEqual(
|
|
expectedRegion === undefined ? regions : [{ code: expectedRegion }]
|
|
)
|
|
expect(filterHighAvailabilityRegions(regions, false, environment)).toEqual(regions)
|
|
}
|
|
)
|
|
})
|
|
|
|
describe('getFreeTierGeneralRegionExperimentVariant', () => {
|
|
const base = {
|
|
isFreePlan: true,
|
|
smartRegionEnabled: true,
|
|
enrollmentFlag: true,
|
|
selectionFlag: true,
|
|
}
|
|
|
|
it('returns test when in the experiment and the selection flag is on', () => {
|
|
expect(getFreeTierGeneralRegionExperimentVariant(base)).toBe('test')
|
|
})
|
|
|
|
it('returns control when in the experiment and the selection flag is off', () => {
|
|
expect(getFreeTierGeneralRegionExperimentVariant({ ...base, selectionFlag: false })).toBe(
|
|
'control'
|
|
)
|
|
})
|
|
|
|
it('returns undefined for a paid plan', () => {
|
|
expect(
|
|
getFreeTierGeneralRegionExperimentVariant({ ...base, isFreePlan: false })
|
|
).toBeUndefined()
|
|
})
|
|
|
|
it('returns undefined when smart regions are disabled (AWS_NIMBUS)', () => {
|
|
expect(
|
|
getFreeTierGeneralRegionExperimentVariant({ ...base, smartRegionEnabled: false })
|
|
).toBeUndefined()
|
|
})
|
|
|
|
it('returns undefined when the enrollment flag is off', () => {
|
|
expect(
|
|
getFreeTierGeneralRegionExperimentVariant({ ...base, enrollmentFlag: false })
|
|
).toBeUndefined()
|
|
})
|
|
|
|
it('returns undefined when the enrollment flag is off even if the selection flag is on', () => {
|
|
expect(
|
|
getFreeTierGeneralRegionExperimentVariant({
|
|
...base,
|
|
enrollmentFlag: false,
|
|
selectionFlag: true,
|
|
})
|
|
).toBeUndefined()
|
|
})
|
|
})
|
|
|
|
describe('getRegionSelectionType', () => {
|
|
const availableRegions: AvailableRegions = {
|
|
smartGroup: [{ code: 'americas', name: 'Americas', type: 'smartGroup' }],
|
|
specific: [
|
|
{ code: 'us-east-1', name: 'East US (North Virginia)', provider: 'AWS', type: 'specific' },
|
|
],
|
|
}
|
|
|
|
it('classifies a smart group region as general', () => {
|
|
expect(getRegionSelectionType({ dbRegion: 'Americas', availableRegions })).toBe('general')
|
|
})
|
|
|
|
it('classifies a specific region as specific', () => {
|
|
expect(getRegionSelectionType({ dbRegion: 'East US (North Virginia)', availableRegions })).toBe(
|
|
'specific'
|
|
)
|
|
})
|
|
|
|
it('returns undefined when the region matches neither list', () => {
|
|
expect(getRegionSelectionType({ dbRegion: 'Nonexistent', availableRegions })).toBeUndefined()
|
|
})
|
|
|
|
it('returns undefined when dbRegion is undefined', () => {
|
|
expect(getRegionSelectionType({ dbRegion: undefined, availableRegions })).toBeUndefined()
|
|
})
|
|
|
|
it('returns undefined when availableRegions is undefined', () => {
|
|
expect(
|
|
getRegionSelectionType({ dbRegion: 'Americas', availableRegions: undefined })
|
|
).toBeUndefined()
|
|
})
|
|
})
|