useUpgradeNowParams.spec.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {BillingConfigFixture} from 'getsentry-test/fixtures/billingConfig';
  3. import {PlanDetailsLookupFixture} from 'getsentry-test/fixtures/planDetailsLookup';
  4. import {SubscriptionFixture} from 'getsentry-test/fixtures/subscription';
  5. import {makeTestQueryClient} from 'sentry-test/queryClient';
  6. import {renderHook, waitFor} from 'sentry-test/reactTestingLibrary';
  7. import {QueryClientProvider} from 'sentry/utils/queryClient';
  8. import {PlanTier} from 'getsentry/types';
  9. import useUpgradeNowParams from './useUpgradeNowParams';
  10. const teamPlan = PlanDetailsLookupFixture('am2_team');
  11. const mockAM2BillingConfig = BillingConfigFixture(PlanTier.AM2);
  12. describe('useUpgradeNowParams', () => {
  13. const organization = OrganizationFixture();
  14. it('should return the plan that matches the subscription settings', async () => {
  15. const subscription = SubscriptionFixture({
  16. organization,
  17. plan: 'am2_team',
  18. });
  19. const billingConfigRequest = MockApiClient.addMockResponse({
  20. url: `/customers/${organization.slug}/billing-config/`,
  21. method: 'GET',
  22. body: mockAM2BillingConfig,
  23. });
  24. const {result} = renderHook(useUpgradeNowParams, {
  25. initialProps: {
  26. organization,
  27. subscription,
  28. },
  29. wrapper: ({children}) => (
  30. <QueryClientProvider client={makeTestQueryClient()}>
  31. {children}
  32. </QueryClientProvider>
  33. ),
  34. });
  35. expect(billingConfigRequest).toHaveBeenCalledTimes(1);
  36. expect(result.current).toStrictEqual({
  37. plan: undefined,
  38. reservations: undefined,
  39. });
  40. await waitFor(() => expect(billingConfigRequest).toHaveBeenCalledTimes(1));
  41. await waitFor(() =>
  42. expect(result.current).toStrictEqual({
  43. plan: teamPlan,
  44. reservations: {
  45. reservedErrors: 50000,
  46. reservedTransactions: 100000,
  47. reservedReplays: 500,
  48. reservedAttachments: 1,
  49. reservedMonitorSeats: 1,
  50. reservedUptime: 1,
  51. },
  52. })
  53. );
  54. });
  55. });