InvoicesSettings.test.tsx78 lines · main
1import { screen } from '@testing-library/react'
2import { beforeEach, describe, expect, it, vi } from 'vitest'
3
4import { InvoicesSettings } from './InvoicesSettings'
5import { MANAGED_BY } from '@/lib/constants/infrastructure'
6import { createMockOrganization, render } from '@/tests/helpers'
7
8const { mockSelectedOrganization, mockInvoicesQuery, mockInvoicesCountQuery } = vi.hoisted(() => ({
9 mockSelectedOrganization: vi.fn(),
10 mockInvoicesQuery: vi.fn(),
11 mockInvoicesCountQuery: vi.fn(),
12}))
13
14vi.mock('@/hooks/misc/useSelectedOrganization', () => ({
15 useSelectedOrganizationQuery: () => ({ data: mockSelectedOrganization() }),
16}))
17
18vi.mock('@/data/invoices/invoices-query', () => ({
19 useInvoicesQuery: () => mockInvoicesQuery(),
20}))
21
22vi.mock('@/data/invoices/invoices-count-query', () => ({
23 useInvoicesCountQuery: () => mockInvoicesCountQuery(),
24}))
25
26vi.mock('@/data/invoices/invoice-query', () => ({
27 getInvoice: vi.fn(),
28}))
29
30vi.mock('@/data/invoices/invoice-receipt-query', () => ({
31 getInvoiceReceipt: vi.fn(),
32}))
33
34vi.mock('@/components/ui/PartnerManagedResource', () => ({
35 default: () => <div data-testid="partner-managed-resource" />,
36}))
37
38describe('InvoicesSettings', () => {
39 beforeEach(() => {
40 vi.clearAllMocks()
41 mockSelectedOrganization.mockReturnValue(
42 createMockOrganization({
43 slug: 'stripe-org',
44 billing_partner: null,
45 integration_source: 'stripe_projects',
46 managed_by: MANAGED_BY.STRIPE_PROJECTS,
47 })
48 )
49 mockInvoicesCountQuery.mockReturnValue({ data: 0, isError: false })
50 mockInvoicesQuery.mockReturnValue({
51 data: [],
52 error: null,
53 isPending: false,
54 isError: false,
55 })
56 })
57
58 it('shows invoices in Studio for Stripe-connected orgs', () => {
59 render(<InvoicesSettings />)
60
61 expect(screen.queryByTestId('partner-managed-resource')).not.toBeInTheDocument()
62 expect(screen.getByText('No invoices for this organization yet')).toBeInTheDocument()
63 })
64
65 it('still routes billing-partner orgs to the partner-managed resource', () => {
66 mockSelectedOrganization.mockReturnValue(
67 createMockOrganization({
68 slug: 'aws-org',
69 billing_partner: 'aws_marketplace',
70 managed_by: MANAGED_BY.AWS_MARKETPLACE,
71 })
72 )
73
74 render(<InvoicesSettings />)
75
76 expect(screen.getByTestId('partner-managed-resource')).toBeInTheDocument()
77 })
78})