BillingCustomerData.test.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { screen } from '@testing-library/react'
  2. import type { ReactNode } from 'react'
  3. import { beforeEach, describe, expect, it, vi } from 'vitest'
  4. import { BillingCustomerData } from './BillingCustomerData'
  5. import { MANAGED_BY } from '@/lib/constants/infrastructure'
  6. import { createMockOrganization, render } from '@/tests/helpers'
  7. const mockSelectedOrganization = vi.hoisted(() => vi.fn())
  8. vi.mock('common', async (importOriginal) => {
  9. const original = (await importOriginal()) as typeof import('common')
  10. return {
  11. ...original,
  12. useParams: () => ({ slug: 'stripe-org' }),
  13. }
  14. })
  15. vi.mock('next-themes', () => ({
  16. useTheme: () => ({ resolvedTheme: 'dark' }),
  17. }))
  18. vi.mock('@stripe/react-stripe-js', () => ({
  19. Elements: ({ children }: { children: ReactNode }) => <div>{children}</div>,
  20. }))
  21. vi.mock('@stripe/stripe-js', () => ({
  22. loadStripe: vi.fn(() => Promise.resolve(null)),
  23. }))
  24. vi.mock('ui', async (importOriginal) => {
  25. const original = (await importOriginal()) as typeof import('ui')
  26. return {
  27. ...original,
  28. Form: ({ children }: { children: ReactNode }) => <div>{children}</div>,
  29. }
  30. })
  31. vi.mock('@/hooks/misc/useSelectedOrganization', () => ({
  32. useSelectedOrganizationQuery: () => ({ data: mockSelectedOrganization() }),
  33. }))
  34. vi.mock('@/hooks/misc/useCheckPermissions', () => ({
  35. useAsyncCheckPermissions: () => ({ can: true, isSuccess: true }),
  36. }))
  37. vi.mock('@/data/organizations/organization-customer-profile-query', () => ({
  38. useOrganizationCustomerProfileQuery: () => ({
  39. data: {
  40. address: {
  41. line1: '',
  42. line2: '',
  43. city: '',
  44. state: '',
  45. postal_code: '',
  46. country: 'US',
  47. },
  48. billing_name: 'Toolshed',
  49. },
  50. error: null,
  51. isPending: false,
  52. isSuccess: true,
  53. }),
  54. }))
  55. vi.mock('@/data/organizations/organization-tax-id-query', () => ({
  56. useOrganizationTaxIdQuery: () => ({
  57. data: null,
  58. error: null,
  59. isPending: false,
  60. isSuccess: true,
  61. }),
  62. }))
  63. vi.mock('@/data/organizations/organization-customer-profile-update-mutation', () => ({
  64. useOrganizationCustomerProfileUpdateMutation: () => ({
  65. mutateAsync: vi.fn(),
  66. }),
  67. }))
  68. vi.mock('./useBillingCustomerDataForm', () => ({
  69. useBillingCustomerDataForm: () => ({
  70. form: {},
  71. handleSubmit: vi.fn(),
  72. handleReset: vi.fn(),
  73. isDirty: false,
  74. resetKey: 0,
  75. onAddressChange: vi.fn(),
  76. applyAddressElementValue: vi.fn(),
  77. markCurrentValuesAsSaved: vi.fn(),
  78. addressCountry: 'US',
  79. addressOptions: {},
  80. }),
  81. }))
  82. vi.mock('./BillingCustomerDataForm', () => ({
  83. BillingCustomerDataForm: () => <div data-testid="billing-customer-data-form" />,
  84. }))
  85. vi.mock('@/components/ui/PartnerManagedResource', () => ({
  86. default: () => <div data-testid="partner-managed-resource" />,
  87. }))
  88. describe('BillingCustomerData', () => {
  89. beforeEach(() => {
  90. vi.clearAllMocks()
  91. mockSelectedOrganization.mockReturnValue(
  92. createMockOrganization({
  93. slug: 'stripe-org',
  94. billing_partner: null,
  95. integration_source: 'stripe_projects',
  96. managed_by: MANAGED_BY.STRIPE_PROJECTS,
  97. })
  98. )
  99. })
  100. it('keeps Stripe-connected orgs editable in Studio', () => {
  101. render(<BillingCustomerData />)
  102. expect(screen.queryByTestId('partner-managed-resource')).not.toBeInTheDocument()
  103. expect(screen.getByTestId('billing-customer-data-form')).toBeInTheDocument()
  104. })
  105. it('still blocks billing-partner orgs behind the partner-managed resource', () => {
  106. mockSelectedOrganization.mockReturnValue(
  107. createMockOrganization({
  108. slug: 'vercel-org',
  109. billing_partner: 'vercel_marketplace',
  110. managed_by: MANAGED_BY.VERCEL_MARKETPLACE,
  111. })
  112. )
  113. render(<BillingCustomerData />)
  114. expect(screen.getByTestId('partner-managed-resource')).toBeInTheDocument()
  115. })
  116. })