|
| 1 | +import {render, screen} from 'sentry-test/reactTestingLibrary'; |
| 2 | + |
| 3 | +import CustomerContractDetails from 'admin/views/customerContractDetails'; |
| 4 | + |
| 5 | +const MOCK_CONTRACT = { |
| 6 | + metadata: {id: 'contract-123', organizationId: 'org-456'}, |
| 7 | + billingConfig: { |
| 8 | + billingType: 'BILLING_TYPE_CREDIT_CARD', |
| 9 | + channel: 'CHANNEL_SALES', |
| 10 | + address: {countryCode: 'US'}, |
| 11 | + contractStartDate: {year: 2024, month: 1, day: 1}, |
| 12 | + contractEndDate: {year: 2025, month: 1, day: 1}, |
| 13 | + }, |
| 14 | + pricingConfig: { |
| 15 | + skuConfigs: [ |
| 16 | + { |
| 17 | + sku: 'SKU_ERRORS', |
| 18 | + basePriceCents: '10000', |
| 19 | + paygBudgetCents: '5000', |
| 20 | + reservedVolume: '100000', |
| 21 | + reservedRate: {tiers: [{ratePerUnitCpe: '100'}]}, |
| 22 | + paygRate: {tiers: [{ratePerUnitCpe: '200'}]}, |
| 23 | + }, |
| 24 | + ], |
| 25 | + sharedSkuBudgets: [], |
| 26 | + billingPeriodStartDate: {year: 2024, month: 1, day: 1}, |
| 27 | + billingPeriodEndDate: {year: 2024, month: 2, day: 1}, |
| 28 | + maxSpendCents: '50000', |
| 29 | + basePriceCents: '10000', |
| 30 | + }, |
| 31 | +}; |
| 32 | + |
| 33 | +const ROUTER_CONFIG = { |
| 34 | + location: {pathname: '/_admin/customers/test-org/contract/'}, |
| 35 | + route: '/_admin/customers/:orgId/contract/', |
| 36 | +}; |
| 37 | + |
| 38 | +describe('CustomerContractDetails', () => { |
| 39 | + beforeEach(() => { |
| 40 | + MockApiClient.clearMockResponses(); |
| 41 | + }); |
| 42 | + |
| 43 | + it('renders contract data', async () => { |
| 44 | + MockApiClient.addMockResponse({ |
| 45 | + url: '/_admin/customers/test-org/contract/', |
| 46 | + body: MOCK_CONTRACT, |
| 47 | + }); |
| 48 | + |
| 49 | + render(<CustomerContractDetails />, { |
| 50 | + initialRouterConfig: ROUTER_CONFIG, |
| 51 | + }); |
| 52 | + |
| 53 | + expect(await screen.findByText('Contract Overview')).toBeInTheDocument(); |
| 54 | + |
| 55 | + expect(screen.getByText('Billing Period:')).toBeInTheDocument(); |
| 56 | + expect(screen.getByText('Contract Period:')).toBeInTheDocument(); |
| 57 | + expect(screen.getAllByText('Base Price:').length).toBeGreaterThan(0); |
| 58 | + expect(screen.getByText('Max Spend:')).toBeInTheDocument(); |
| 59 | + expect(screen.getByText('Contract ID:')).toBeInTheDocument(); |
| 60 | + expect(screen.getByText('Type:')).toBeInTheDocument(); |
| 61 | + expect(screen.getByText('Channel:')).toBeInTheDocument(); |
| 62 | + expect(screen.getByText('Billing Country:')).toBeInTheDocument(); |
| 63 | + |
| 64 | + expect(screen.getByText('contract-123')).toBeInTheDocument(); |
| 65 | + expect(screen.getByText('Credit Card')).toBeInTheDocument(); |
| 66 | + expect(screen.getByText('Sales')).toBeInTheDocument(); |
| 67 | + expect(screen.getByText('United States')).toBeInTheDocument(); |
| 68 | + |
| 69 | + expect(screen.getByText('SKU Pricing')).toBeInTheDocument(); |
| 70 | + expect(screen.getByText('Errors')).toBeInTheDocument(); |
| 71 | + expect(screen.getByText('Reserved Volume:')).toBeInTheDocument(); |
| 72 | + expect(screen.getByText('100,000')).toBeInTheDocument(); |
| 73 | + expect(screen.getByText('$0.00000100')).toBeInTheDocument(); |
| 74 | + expect(screen.getByText('$0.00000200')).toBeInTheDocument(); |
| 75 | + }); |
| 76 | + |
| 77 | + it('renders error state', async () => { |
| 78 | + MockApiClient.addMockResponse({ |
| 79 | + url: '/_admin/customers/test-org/contract/', |
| 80 | + body: {detail: 'Not found'}, |
| 81 | + statusCode: 404, |
| 82 | + }); |
| 83 | + |
| 84 | + render(<CustomerContractDetails />, { |
| 85 | + initialRouterConfig: ROUTER_CONFIG, |
| 86 | + }); |
| 87 | + |
| 88 | + expect( |
| 89 | + await screen.findByText('There was an error loading data.') |
| 90 | + ).toBeInTheDocument(); |
| 91 | + }); |
| 92 | + |
| 93 | + it('renders shared budgets when present', async () => { |
| 94 | + const contractWithBudgets = { |
| 95 | + ...MOCK_CONTRACT, |
| 96 | + pricingConfig: { |
| 97 | + ...MOCK_CONTRACT.pricingConfig, |
| 98 | + sharedSkuBudgets: [ |
| 99 | + { |
| 100 | + skus: ['SKU_ERRORS', 'SKU_TRANSACTIONS'], |
| 101 | + reservedBudgetCents: '20000', |
| 102 | + paygBudgetCents: '10000', |
| 103 | + }, |
| 104 | + ], |
| 105 | + }, |
| 106 | + }; |
| 107 | + |
| 108 | + MockApiClient.addMockResponse({ |
| 109 | + url: '/_admin/customers/test-org/contract/', |
| 110 | + body: contractWithBudgets, |
| 111 | + }); |
| 112 | + |
| 113 | + render(<CustomerContractDetails />, { |
| 114 | + initialRouterConfig: ROUTER_CONFIG, |
| 115 | + }); |
| 116 | + |
| 117 | + expect(await screen.findByText('Shared Budgets')).toBeInTheDocument(); |
| 118 | + expect(screen.getByText('Errors, Transactions')).toBeInTheDocument(); |
| 119 | + expect(screen.getByText('Reserved Budget:')).toBeInTheDocument(); |
| 120 | + expect(screen.getAllByText('PAYG Budget:').length).toBeGreaterThan(0); |
| 121 | + }); |
| 122 | + |
| 123 | + it('handles missing optional fields gracefully', async () => { |
| 124 | + const minimalContract = { |
| 125 | + metadata: {}, |
| 126 | + billingConfig: {}, |
| 127 | + pricingConfig: {}, |
| 128 | + }; |
| 129 | + |
| 130 | + MockApiClient.addMockResponse({ |
| 131 | + url: '/_admin/customers/test-org/contract/', |
| 132 | + body: minimalContract, |
| 133 | + }); |
| 134 | + |
| 135 | + render(<CustomerContractDetails />, { |
| 136 | + initialRouterConfig: ROUTER_CONFIG, |
| 137 | + }); |
| 138 | + |
| 139 | + expect(await screen.findByText('Contract Overview')).toBeInTheDocument(); |
| 140 | + expect(screen.getAllByText('N/A').length).toBeGreaterThan(0); |
| 141 | + }); |
| 142 | +}); |
0 commit comments