InvoicesSettings.test.tsx 2.3 KB

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