mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
Removes the remaining Next.js dependencies, compatibility shims, test
mocks, ESLint/TypeScript presets, and webpack/Next workarounds from
Studio following the TanStack Start migration.
Addresses FE-3107.
**Removed:**
- `next` and `next-router-mock` from `apps/studio/package.json` (and
updated `pnpm-lock.yaml`)
- Orphaned `apps/studio/compat/next/script.tsx` shim, `script.test.tsx`,
`compat/**` knip entry, and `nextCompat()` / `ssr.noExternal` `/^next/`
plumbing from `apps/studio/vite.config.ts`
- `apps/studio/tests/lib/route-mock.ts` and all `next-router-mock`
setup/imports across `tests/vitestSetup.ts`,
`tests/lib/custom-render.tsx`, and 12 test files
- `apps/studio/tests/pages/` directory (moved the 3 remaining tests to
`components/interfaces/Organization/Organization.utils.test.ts` and
`apps/studio/tests/routes/`)
- Unused `'use client'` directives across 23 Studio files
- Next.js/webpack workarounds: `graphiqlViteWorkers()` in
`vite.config.ts`, webpack `import.meta.glob` `try/catch` fallback in
`ConnectStepsSection.tsx`, shell `NODE_ENV=test` override in
`vite.config.ts` / root `package.json` / `studio-e2e-test.yml`, Next
`getPathMatch` and `_next` passthrough in `redirects.shared.*`,
`window.next?.router` check in `monaco-graphiql-coexistence.spec.ts`,
and unused `ANALYZE` env var in `apps/studio/turbo.jsonc`
- Next-only Sentry/chunk-load filters (`NEXT_NOT_FOUND`,
`NEXT_REDIRECT`, Next `/org/[slug]/` regex, `/app:\/\//`, dead
`includeThirdPartyErrorFilter` plumbing, webpack chunk error regex) and
stale Next/Pages Router comments, docs, and `#__next` CSS selector
**Changed:**
- `apps/studio/eslint.config.cjs`: switched from
`eslint-config-supabase/next` to the new `eslint-config-supabase/react`
preset (dropping `@next/next/no-img-element: off`, keeping `.next` /
`next-env.d.ts` ignored for local checkouts with stale pre-migration
build artifacts)
- `apps/studio/tsconfig.json`: extends `tsconfig/base.json` directly
instead of `tsconfig/nextjs.json` (identical resolved compiler options)
- `apps/studio/.github/eslint-rule-baselines.json`: pruned 33 stale
`pages/...` and `types/next.ts` entries without changing any rule
thresholds
- `apps/studio/tests/lib/custom-render.tsx`: backed
`TestFrameworkProvider` with TanStack Router instead of
`next-router-mock`
-
`apps/studio/components/interfaces/Integrations/GraphQL/GraphiQLTab.tsx`:
imports `graphiql/setup-workers/vite` directly
- `apps/studio/styles/globals.css`: replaced `@source
'../pages/**/*.{js,ts,jsx,tsx}'` with `@source
'../routes/**/*.{js,ts,jsx,tsx}'`
- `apps/studio/turbo.jsonc`: declared `"NEXT_PUBLIC_*"` in
`tasks.build.env` now that Turborepo infers `nitro` instead of `nextjs`
-
`apps/studio/components/interfaces/Organization/Organization.utils.ts`:
narrowed `buildOrgUrl`'s `slug` parameter to `string[] | undefined`
**Added:**
- `packages/eslint-config-supabase/shared.js` and
`packages/eslint-config-supabase/react.js` (plus `presets.test.ts`),
decoupling non-Next React apps from `eslint-config-next` with verified
zero non-`@next/*` rule drift while keeping
`eslint-config-supabase/next` unchanged for the Next.js apps
## To test
- Run `pnpm --filter eslint-config-supabase run test` and confirm preset
parity tests pass
- Run `pnpm --filter studio run lint`, `pnpm --filter studio run
lint:ratchet`, `pnpm --filter studio run typecheck`, `pnpm knip
--workspace apps/studio`, and `pnpm --filter studio run test`
- Run `pnpm --filter studio run build` and verify the production build,
prerendered routes, chunk-cycle check, and GraphiQL web workers succeed
- Smoke-test Studio locally (`pnpm dev:studio`): verify GraphiQL loads
cleanly, ConnectSheet framework steps render, and Tailwind styles on
route pages are intact
---------
Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
379 lines
13 KiB
TypeScript
379 lines
13 KiB
TypeScript
import { fireEvent, screen, waitFor, within } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import { platformComponents as components } from 'api-types'
|
|
import { LOCAL_STORAGE_KEYS } from 'common'
|
|
import { http, HttpResponse } from 'msw'
|
|
import { toast } from 'sonner'
|
|
import { beforeEach, describe, expect, test, vi } from 'vitest'
|
|
|
|
import { AwsMarketplaceOnboardingScreen } from '@/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceOnboarding'
|
|
import type {
|
|
CloudMarketplaceContractLinkingEligibility,
|
|
CloudMarketplaceOnboardingInfo,
|
|
} from '@/components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query'
|
|
import { CREATE_AWS_MANAGED_ORG_FORM_ID } from '@/components/interfaces/Organization/CloudMarketplace/NewAwsMarketplaceOrgForm'
|
|
import { API_URL } from '@/lib/constants'
|
|
import type { ProfileContextType } from '@/lib/profile'
|
|
import { createMockOrganizationResponse } from '@/tests/helpers'
|
|
import { customRender } from '@/tests/lib/custom-render'
|
|
import { addAPIMock, mswServer } from '@/tests/lib/msw'
|
|
|
|
vi.mock('sonner', () => ({
|
|
toast: { error: vi.fn() },
|
|
}))
|
|
|
|
type OrganizationResponse = components['schemas']['OrganizationResponse_Output']
|
|
|
|
const DEFAULT_PROFILE_CONTEXT: ProfileContextType = {
|
|
profile: {
|
|
id: 1,
|
|
auth0_id: 'auth0|test',
|
|
gotrue_id: 'gotrue-test',
|
|
username: 'testuser',
|
|
primary_email: 'test@example.com',
|
|
first_name: null,
|
|
last_name: null,
|
|
mobile: null,
|
|
is_alpha_user: false,
|
|
is_sso_user: false,
|
|
disabled_features: [],
|
|
free_project_limit: null,
|
|
},
|
|
error: null,
|
|
isLoading: false,
|
|
isError: false,
|
|
isSuccess: true,
|
|
}
|
|
|
|
const LINKABLE_ORG = createMockOrganizationResponse({
|
|
id: 1,
|
|
name: 'Acme Production',
|
|
slug: 'acme-production',
|
|
plan: { id: 'pro', name: 'Pro' },
|
|
})
|
|
const UNAVAILABLE_ORG = createMockOrganizationResponse({
|
|
id: 2,
|
|
name: 'Legacy Billing',
|
|
slug: 'legacy-billing',
|
|
plan: { id: 'team', name: 'Team' },
|
|
})
|
|
|
|
const ELIGIBLE_CONTRACT: CloudMarketplaceContractLinkingEligibility = {
|
|
eligibility: {
|
|
is_eligible: true,
|
|
reasons: [],
|
|
aws_agreement_id: 'agreement-test',
|
|
},
|
|
}
|
|
|
|
function createOnboardingInfo({
|
|
organizations = [LINKABLE_ORG, UNAVAILABLE_ORG],
|
|
eligibleSlugs = [LINKABLE_ORG.slug],
|
|
}: {
|
|
organizations?: OrganizationResponse[]
|
|
eligibleSlugs?: string[]
|
|
} = {}): CloudMarketplaceOnboardingInfo {
|
|
return {
|
|
aws_contract_auto_renewal: true,
|
|
aws_contract_end_date: '2026-12-31T00:00:00.000Z',
|
|
aws_contract_is_private_offer: false,
|
|
aws_contract_settings_url: 'https://aws.amazon.com/marketplace',
|
|
aws_contract_start_date: '2026-01-01T00:00:00.000Z',
|
|
organization_linking_eligibility: organizations.map((organization) => ({
|
|
slug: organization.slug,
|
|
is_eligible: eligibleSlugs.includes(organization.slug),
|
|
reasons: eligibleSlugs.includes(organization.slug) ? [] : ['ALREADY_MANAGED_BY_PARTNER_AWS'],
|
|
})),
|
|
plan_name_selected_on_marketplace: 'Team',
|
|
}
|
|
}
|
|
|
|
function mockAwsEndpoints({
|
|
organizations = [LINKABLE_ORG, UNAVAILABLE_ORG],
|
|
eligibility = ELIGIBLE_CONTRACT,
|
|
onboardingInfo = createOnboardingInfo({ organizations }),
|
|
}: {
|
|
organizations?: OrganizationResponse[]
|
|
eligibility?: CloudMarketplaceContractLinkingEligibility
|
|
onboardingInfo?: CloudMarketplaceOnboardingInfo
|
|
} = {}) {
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/organizations',
|
|
response: () => HttpResponse.json<OrganizationResponse[]>(organizations),
|
|
})
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/cloud-marketplace/buyers/:buyer_id/contract-linking-eligibility',
|
|
response: () => HttpResponse.json<CloudMarketplaceContractLinkingEligibility>(eligibility),
|
|
})
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/cloud-marketplace/buyers/:buyer_id/onboarding-info',
|
|
response: () => HttpResponse.json<CloudMarketplaceOnboardingInfo>(onboardingInfo),
|
|
})
|
|
}
|
|
|
|
function mockOrganizationCreation() {
|
|
const requests: { create: unknown[]; survey: unknown[] } = { create: [], survey: [] }
|
|
|
|
mswServer.use(
|
|
http.post(`${API_URL}/platform/organizations/cloud-marketplace`, async ({ request }) => {
|
|
requests.create.push(await request.json())
|
|
return HttpResponse.json(
|
|
createMockOrganizationResponse({
|
|
id: 3,
|
|
name: 'Mock Marketplace Org',
|
|
slug: 'mock-marketplace-org',
|
|
billing_partner: 'aws_marketplace',
|
|
})
|
|
)
|
|
}),
|
|
http.post(`${API_URL}/platform/organizations/onboarding-survey`, async ({ request }) => {
|
|
requests.survey.push(await request.json())
|
|
return new HttpResponse(null, { status: 204 })
|
|
})
|
|
)
|
|
|
|
return requests
|
|
}
|
|
|
|
// Radix Selects render a hidden native <option> per item, so scope to the open listbox
|
|
async function chooseOption(
|
|
user: ReturnType<typeof userEvent.setup>,
|
|
question: string,
|
|
option: string
|
|
) {
|
|
await user.click(screen.getByRole('combobox', { name: question }))
|
|
await user.click(within(await screen.findByRole('listbox')).getByRole('option', { name: option }))
|
|
}
|
|
|
|
function renderScreen(props: Partial<Parameters<typeof AwsMarketplaceOnboardingScreen>[0]> = {}) {
|
|
return customRender(<AwsMarketplaceOnboardingScreen buyerId="buyer-test" {...props} />, {
|
|
profileContext: DEFAULT_PROFILE_CONTEXT,
|
|
})
|
|
}
|
|
|
|
describe('AwsMarketplaceOnboardingScreen', () => {
|
|
beforeEach(() => {
|
|
window.localStorage.clear()
|
|
})
|
|
|
|
test('renders linkable and unavailable organizations and disables link without selection', async () => {
|
|
const user = userEvent.setup()
|
|
mockAwsEndpoints()
|
|
renderScreen()
|
|
|
|
await screen.findByText('Acme Production')
|
|
const linkButton = screen.getByRole('button', { name: 'Link organization' })
|
|
expect(linkButton).toBeDisabled()
|
|
|
|
await user.click(screen.getByRole('button', { name: /Organizations that can't be linked/ }))
|
|
expect(screen.getByText('Legacy Billing')).toBeInTheDocument()
|
|
expect(screen.getByText('Already linked to AWS Marketplace')).toBeInTheDocument()
|
|
|
|
await user.click(screen.getByRole('button', { name: /Acme Production/ }))
|
|
expect(linkButton).toBeEnabled()
|
|
})
|
|
|
|
test('calls link mutation with buyerId and slug', async () => {
|
|
const user = userEvent.setup()
|
|
let linkRequest: { slug?: string; body?: unknown } | undefined
|
|
|
|
mockAwsEndpoints()
|
|
mswServer.use(
|
|
http.put(
|
|
`${API_URL}/platform/organizations/:slug/cloud-marketplace/link`,
|
|
async ({ params, request }) => {
|
|
linkRequest = {
|
|
slug: String(params.slug),
|
|
body: await request.json(),
|
|
}
|
|
return HttpResponse.json({})
|
|
}
|
|
)
|
|
)
|
|
|
|
renderScreen()
|
|
|
|
await user.click(await screen.findByRole('button', { name: /Acme Production/ }))
|
|
await user.click(screen.getByRole('button', { name: 'Link organization' }))
|
|
|
|
await waitFor(() => {
|
|
expect(linkRequest).toEqual({
|
|
slug: 'acme-production',
|
|
body: { buyer_id: 'buyer-test' },
|
|
})
|
|
})
|
|
await screen.findByText('Organization linked')
|
|
})
|
|
|
|
test('renders a link failure inline and keeps the action available', async () => {
|
|
const user = userEvent.setup()
|
|
mockAwsEndpoints()
|
|
mswServer.use(
|
|
http.put(`${API_URL}/platform/organizations/:slug/cloud-marketplace/link`, () =>
|
|
HttpResponse.json({ message: 'Marketplace link failed' }, { status: 500 })
|
|
)
|
|
)
|
|
|
|
renderScreen()
|
|
|
|
await user.click(await screen.findByRole('button', { name: /Acme Production/ }))
|
|
await user.click(screen.getByRole('button', { name: 'Link organization' }))
|
|
|
|
expect(await screen.findByRole('alert')).toHaveTextContent(
|
|
'Failed to link organization: Marketplace link failed'
|
|
)
|
|
expect(toast.error).not.toHaveBeenCalled()
|
|
expect(screen.queryByText(/Learn more/)).not.toBeInTheDocument()
|
|
expect(screen.getByRole('button', { name: 'Link organization' })).toBeEnabled()
|
|
})
|
|
|
|
test('creates an AWS-managed organization with buyerId and returns to linked state', async () => {
|
|
const user = userEvent.setup()
|
|
|
|
mockAwsEndpoints({
|
|
organizations: [],
|
|
onboardingInfo: createOnboardingInfo({ organizations: [] }),
|
|
})
|
|
const requests = mockOrganizationCreation()
|
|
|
|
renderScreen()
|
|
|
|
// With no existing organizations, only the primary create action is offered
|
|
const createButton = await screen.findByRole('button', { name: 'Create organization' })
|
|
expect(
|
|
screen.queryByRole('button', { name: /Create new organization/ })
|
|
).not.toBeInTheDocument()
|
|
|
|
await user.click(createButton)
|
|
await user.click(screen.getByPlaceholderText('Organization name'))
|
|
await user.paste('Mock Marketplace Org')
|
|
fireEvent.submit(document.getElementById(CREATE_AWS_MANAGED_ORG_FORM_ID)!)
|
|
|
|
await waitFor(() => {
|
|
expect(requests.create).toEqual([{ name: 'Mock Marketplace Org', buyer_id: 'buyer-test' }])
|
|
})
|
|
expect(await screen.findByText('Organization linked')).toBeInTheDocument()
|
|
expect(requests.survey).toEqual([])
|
|
})
|
|
|
|
test('sends survey answers to the survey endpoint and keeps them out of organization creation', async () => {
|
|
const user = userEvent.setup()
|
|
|
|
mockAwsEndpoints({
|
|
organizations: [],
|
|
onboardingInfo: createOnboardingInfo({ organizations: [] }),
|
|
})
|
|
const requests = mockOrganizationCreation()
|
|
|
|
renderScreen()
|
|
|
|
await user.click(await screen.findByRole('button', { name: 'Create organization' }))
|
|
await user.click(screen.getByPlaceholderText('Organization name'))
|
|
await user.paste('Mock Marketplace Org')
|
|
await chooseOption(user, 'Who is this org for?', 'Company')
|
|
await chooseOption(user, 'How many people?', '50 - 99')
|
|
await chooseOption(user, 'What are you building?', 'B2B SaaS application')
|
|
await chooseOption(user, 'Do you know how to code?', 'Yes')
|
|
fireEvent.submit(document.getElementById(CREATE_AWS_MANAGED_ORG_FORM_ID)!)
|
|
|
|
await waitFor(() => {
|
|
expect(requests.survey).toEqual([
|
|
{
|
|
slug: 'mock-marketplace-org',
|
|
kind: 'COMPANY',
|
|
size: '50',
|
|
building: 'b2b_saas',
|
|
can_code: 'yes',
|
|
},
|
|
])
|
|
})
|
|
expect(requests.create).toEqual([{ name: 'Mock Marketplace Org', buyer_id: 'buyer-test' }])
|
|
})
|
|
|
|
test('renders setup unavailable when the buyer ID is missing', async () => {
|
|
renderScreen({ buyerId: undefined })
|
|
|
|
expect(await screen.findByText('Setup unavailable')).toBeInTheDocument()
|
|
expect(screen.getByText('buyer_id')).toBeInTheDocument()
|
|
})
|
|
|
|
test('renders an error state when onboarding info fails to load', async () => {
|
|
mockAwsEndpoints()
|
|
mswServer.use(
|
|
http.get(`${API_URL}/platform/cloud-marketplace/buyers/:buyer_id/onboarding-info`, () =>
|
|
HttpResponse.json({ message: 'Failed to load onboarding info' }, { status: 500 })
|
|
)
|
|
)
|
|
|
|
renderScreen()
|
|
|
|
expect(await screen.findByText('Unable to load setup')).toBeInTheDocument()
|
|
})
|
|
|
|
test('renders the generic ineligible state', async () => {
|
|
mockAwsEndpoints({
|
|
eligibility: {
|
|
eligibility: {
|
|
is_eligible: false,
|
|
reasons: [],
|
|
aws_agreement_id: 'agreement-test',
|
|
},
|
|
},
|
|
})
|
|
|
|
renderScreen()
|
|
|
|
expect(
|
|
await screen.findByText('This AWS Marketplace subscription cannot be linked right now')
|
|
).toBeInTheDocument()
|
|
expect(screen.getByText('If the problem persists, contact support.')).toBeInTheDocument()
|
|
})
|
|
|
|
test('renders the already-linked ineligible state', async () => {
|
|
mockAwsEndpoints({
|
|
eligibility: {
|
|
eligibility: {
|
|
is_eligible: false,
|
|
reasons: ['AGREEMENT_BASED_OFFER'],
|
|
aws_agreement_id: 'agreement-test',
|
|
},
|
|
},
|
|
})
|
|
|
|
renderScreen()
|
|
|
|
expect(await screen.findByText('No action required')).toBeInTheDocument()
|
|
})
|
|
|
|
test('promotes the last visited organization into the first visible organizations', async () => {
|
|
const organizations = [
|
|
createMockOrganizationResponse({ id: 1, name: 'Alpha Team', slug: 'alpha-team' }),
|
|
createMockOrganizationResponse({ id: 2, name: 'Beta Team', slug: 'beta-team' }),
|
|
createMockOrganizationResponse({ id: 3, name: 'Delta Team', slug: 'delta-team' }),
|
|
createMockOrganizationResponse({ id: 4, name: 'Gamma Team', slug: 'gamma-team' }),
|
|
createMockOrganizationResponse({ id: 5, name: 'Zeta Team', slug: 'zeta-team' }),
|
|
]
|
|
|
|
window.localStorage.setItem(
|
|
LOCAL_STORAGE_KEYS.LAST_VISITED_ORGANIZATION(DEFAULT_PROFILE_CONTEXT.profile?.id),
|
|
JSON.stringify('zeta-team')
|
|
)
|
|
mockAwsEndpoints({
|
|
organizations,
|
|
onboardingInfo: createOnboardingInfo({
|
|
organizations,
|
|
eligibleSlugs: organizations.map(({ slug }) => slug),
|
|
}),
|
|
})
|
|
renderScreen()
|
|
|
|
const zeta = await screen.findByText('Zeta Team')
|
|
const alpha = await screen.findByText('Alpha Team')
|
|
expect(zeta.compareDocumentPosition(alpha) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
|
|
expect(screen.getByRole('button', { name: 'Show 2 more' })).toBeInTheDocument()
|
|
})
|
|
})
|