mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Problem `packages/api-types` has drifted from the production OpenAPI specs. #54394 regenerated them but was reverted in #54404, because the API had rolled out ahead of its OpenFGA model. That has since been fixed on the backend, so the regen can land. ...plus I need the new spec for #54391 and didn't want to blow up my branch. ## Solution Regenerated with `pnpm --filter=api-types codegen:prod` (production specs, not the localhost `codegen`), plus the type fixes the new specs require: - `platform-webhooks-fetchers.ts` — `page` is now a deep object in the spec, so the query params move from `page[limit]` keys to a nested `page` object with a `deepObject` serializer. - `InvoicesSettings.test.tsx` — four newly-required invoice fields in the mock. - `packages/shared-data` — `@supabase/shared-types` 0.1.98 → 0.1.102, matching `apps/studio`. Notable additions: the `environment_*` FGA scopes and `GET /v2/projects/{ref}/analytics/traces/{trace_id}`. ## Review instructions 1. `pnpm --filter=api-types run verify-production-types` — passes. 2. `pnpm typecheck` and `pnpm --filter=studio test` — pass. 3. Only the three non-generated files need reading; the rest is generated output. Note: `verify-production-api-types` was removed from the required checks during the #54394 incident and hasn't been restored. Worth putting back after this merges.
151 lines
4.3 KiB
TypeScript
151 lines
4.3 KiB
TypeScript
import { screen } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import { mockIntersectionObserver } from 'jsdom-testing-mocks'
|
|
import { toast } from 'sonner'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { InvoicesSettings } from './InvoicesSettings'
|
|
import { getInvoice } from '@/data/invoices/invoice-query'
|
|
import type { InvoicesData } from '@/data/invoices/invoices-query'
|
|
import { MANAGED_BY } from '@/lib/constants/infrastructure'
|
|
import { createMockOrganization, render } from '@/tests/helpers'
|
|
|
|
type Invoice = NonNullable<InvoicesData>[number]
|
|
|
|
mockIntersectionObserver()
|
|
|
|
const { mockSelectedOrganization, mockInvoicesQuery, mockInvoicesCountQuery } = vi.hoisted(() => ({
|
|
mockSelectedOrganization: vi.fn(),
|
|
mockInvoicesQuery: vi.fn(),
|
|
mockInvoicesCountQuery: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('@/hooks/misc/useSelectedOrganization', () => ({
|
|
useSelectedOrganizationQuery: () => ({ data: mockSelectedOrganization() }),
|
|
}))
|
|
|
|
vi.mock('@/data/invoices/invoices-query', () => ({
|
|
useInvoicesQuery: () => mockInvoicesQuery(),
|
|
}))
|
|
|
|
vi.mock('@/data/invoices/invoices-count-query', () => ({
|
|
useInvoicesCountQuery: () => mockInvoicesCountQuery(),
|
|
}))
|
|
|
|
vi.mock('@/data/invoices/invoice-query', () => ({
|
|
getInvoice: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('@/data/invoices/invoice-receipt-query', () => ({
|
|
getInvoiceReceipt: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('@/components/ui/PartnerManagedResource', () => ({
|
|
default: () => <div data-testid="partner-managed-resource" />,
|
|
}))
|
|
|
|
vi.mock('sonner', () => ({
|
|
toast: {
|
|
error: vi.fn(),
|
|
success: vi.fn(),
|
|
},
|
|
}))
|
|
|
|
const createMockInvoice = (details: Partial<Invoice> = {}): Invoice => ({
|
|
id: 'in_123',
|
|
number: 'ABCD-0001',
|
|
amount_due: 0,
|
|
amount_refunded_cents: 0,
|
|
credit_notes_applied_cents: 0,
|
|
payment_details: null,
|
|
total_cents: 0,
|
|
invoice_pdf: 'https://example.com/invoice.pdf',
|
|
payment_attempted: false,
|
|
payment_is_processing: false,
|
|
period_end: 1_700_000_000,
|
|
prepaid_credits_applied_cents: 0,
|
|
status: 'draft',
|
|
subscription: null,
|
|
subtotal: 0,
|
|
...details,
|
|
})
|
|
|
|
const createMockInvoiceWithoutPdf = (): Invoice => {
|
|
return createMockInvoice({
|
|
invoice_pdf: null,
|
|
})
|
|
}
|
|
|
|
describe('InvoicesSettings', () => {
|
|
beforeEach(() => {
|
|
mockSelectedOrganization.mockReturnValue(
|
|
createMockOrganization({
|
|
slug: 'stripe-org',
|
|
billing_partner: null,
|
|
integration_source: 'stripe_projects',
|
|
managed_by: MANAGED_BY.STRIPE_PROJECTS,
|
|
})
|
|
)
|
|
mockInvoicesCountQuery.mockReturnValue({ data: 0, isError: false })
|
|
mockInvoicesQuery.mockReturnValue({
|
|
data: [],
|
|
error: null,
|
|
isPending: false,
|
|
isError: false,
|
|
})
|
|
})
|
|
|
|
it('shows invoices in Studio for Stripe-connected orgs', () => {
|
|
render(<InvoicesSettings />)
|
|
|
|
expect(screen.queryByTestId('partner-managed-resource')).not.toBeInTheDocument()
|
|
expect(screen.getByText('No invoices for this organization yet')).toBeInTheDocument()
|
|
})
|
|
|
|
it('still routes billing-partner orgs to the partner-managed resource', () => {
|
|
mockSelectedOrganization.mockReturnValue(
|
|
createMockOrganization({
|
|
slug: 'aws-org',
|
|
billing_partner: 'aws_marketplace',
|
|
managed_by: MANAGED_BY.AWS_MARKETPLACE,
|
|
})
|
|
)
|
|
|
|
render(<InvoicesSettings />)
|
|
|
|
expect(screen.getByTestId('partner-managed-resource')).toBeInTheDocument()
|
|
})
|
|
|
|
it('disables the download button for invoices without a PDF', () => {
|
|
mockInvoicesCountQuery.mockReturnValue({ data: 1, isError: false })
|
|
mockInvoicesQuery.mockReturnValue({
|
|
data: [createMockInvoiceWithoutPdf()],
|
|
error: null,
|
|
isPending: false,
|
|
isError: false,
|
|
})
|
|
|
|
render(<InvoicesSettings />)
|
|
|
|
expect(screen.getByRole('button', { name: 'Download invoice' })).toBeAriaDisabled()
|
|
})
|
|
|
|
it('shows an error when the fetched invoice has no PDF', async () => {
|
|
mockInvoicesCountQuery.mockReturnValue({ data: 1, isError: false })
|
|
mockInvoicesQuery.mockReturnValue({
|
|
data: [createMockInvoice()],
|
|
error: null,
|
|
isPending: false,
|
|
isError: false,
|
|
})
|
|
vi.mocked(getInvoice).mockResolvedValue(createMockInvoiceWithoutPdf())
|
|
|
|
render(<InvoicesSettings />)
|
|
await userEvent.click(screen.getByRole('button', { name: 'Download invoice' }))
|
|
|
|
expect(toast.error).toHaveBeenCalledWith(
|
|
'Invoice PDF is not available yet. Please try again later.'
|
|
)
|
|
})
|
|
})
|