mirror of
https://github.com/supabase/supabase.git
synced 2026-12-05 07:59:03 +00:00
## Context
_TLDR: Changes here speeds up unit tests on CI from ~14 minutes to ~3
minutes_ 😂
_TLDR 2: The file changes are solely only test files +
`studio-unit-tests.yml`_
We've currently got a lot of unit tests in the repository which while
great for coverage, hasn't been ideally written. There's a lot of
redundancy + overly specific tests that break easily, and our current
unit test takes about 15 minutes to run in the GHA per PR. Hence am
doing a audit clean up of all existing unit tests in the studio repo.
## Changes involved
- `.test.ts` files now run in `node`, `.test.tsx` in `jsdom`
- jsdom costs about 1s of setup per file. A `.ts` test that needs the
DOM opts in with `// @vitest-environment jsdom` (46 files do).
- Removed redundant and over-specific tests
- Duplicates are merged into `test.each`. Tests that only covered
libraries, existed for coverage, or asserted class names and snapshots
are deleted. 19 files are merged into a sibling or deleted.
- Fixed about 15 tests that couldn't fail
- Examples: unawaited assertions, fixtures equal to the default, and a
`semverGte` test calling `semverLte`.
- Sped up the slowest files
- Real sleeps are replaced with fake timers, `user.type` with paste, and
Radix option queries are scoped to the open listbox. For example,
`RestoringState` went from 18s to 0.3s and
`useTableEditorFiltersSort.navigation` from 20s to 3s.
- These ^ already shave down the unit tests time from 14 mins to 9 mins,
but am also sharding unit tests across 4 jobs to increase speed up
further which then shaves down time to 3 mins now
79 lines
2.6 KiB
TypeScript
79 lines
2.6 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { castOrganizationSlugResponseToOrganization } from './organization-query'
|
|
import { castOrganizationResponseToOrganization } from './organizations-query'
|
|
import { MANAGED_BY } from '@/lib/constants/infrastructure'
|
|
|
|
const baseOrganizationResponse = {
|
|
billing_email: 'billing@example.com',
|
|
billing_partner: null,
|
|
id: 1,
|
|
integration_source: null,
|
|
is_owner: true,
|
|
name: 'Toolshed',
|
|
opt_in_tags: [] as string[],
|
|
organization_missing_address: false,
|
|
organization_missing_tax_id: false,
|
|
organization_requires_mfa: false,
|
|
requires_indirect_tax_declaration: false,
|
|
plan: { id: 'pro' as const, name: 'Pro' },
|
|
restriction_data: null,
|
|
restriction_status: null,
|
|
slug: 'toolshed',
|
|
stripe_customer_id: 'cus_123',
|
|
subscription_id: 'sub_123',
|
|
usage_billing_enabled: true,
|
|
}
|
|
|
|
const baseOrganizationSlugResponse = {
|
|
created_at: '2023-01-01T00:00:00Z',
|
|
billing_email: 'billing@example.com',
|
|
billing_partner: null,
|
|
has_oriole_project: false,
|
|
id: 1,
|
|
integration_source: null,
|
|
name: 'Toolshed',
|
|
opt_in_tags: [] as string[],
|
|
plan: { id: 'pro' as const, name: 'Pro' },
|
|
requires_indirect_tax_declaration: false,
|
|
restriction_data: null,
|
|
restriction_status: null,
|
|
slug: 'toolshed',
|
|
usage_billing_enabled: true,
|
|
}
|
|
|
|
describe('organization query mappers', () => {
|
|
it('keeps billing_partner unchanged while deriving Stripe display state from integration_source', () => {
|
|
const organization = castOrganizationResponseToOrganization({
|
|
...baseOrganizationResponse,
|
|
integration_source: 'stripe_projects',
|
|
})
|
|
|
|
expect(organization.billing_partner).toBeNull()
|
|
expect(organization.integration_source).toBe('stripe_projects')
|
|
expect(organization.managed_by).toBe(MANAGED_BY.STRIPE_PROJECTS)
|
|
})
|
|
|
|
it('lets billing_partner win over integration_source for organization list data', () => {
|
|
const organization = castOrganizationResponseToOrganization({
|
|
...baseOrganizationResponse,
|
|
billing_partner: 'aws_marketplace',
|
|
integration_source: 'stripe_projects',
|
|
})
|
|
|
|
expect(organization.billing_partner).toBe('aws_marketplace')
|
|
expect(organization.managed_by).toBe(MANAGED_BY.AWS_MARKETPLACE)
|
|
})
|
|
|
|
it('derives Stripe display state for organization detail data without rewriting billing_partner', () => {
|
|
const organization = castOrganizationSlugResponseToOrganization({
|
|
...baseOrganizationSlugResponse,
|
|
integration_source: 'stripe_projects',
|
|
})
|
|
|
|
expect(organization.billing_partner).toBeNull()
|
|
expect(organization.integration_source).toBe('stripe_projects')
|
|
expect(organization.managed_by).toBe(MANAGED_BY.STRIPE_PROJECTS)
|
|
})
|
|
})
|