Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions static/gsApp/views/amCheckout/reserveAdditionalVolume.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';

import {MONTHLY} from 'getsentry/constants';
import SubscriptionStore from 'getsentry/stores/subscriptionStore';
import {PlanTier} from 'getsentry/types';
import {PlanTier, type Subscription} from 'getsentry/types';
import ReserveAdditionalVolume from 'getsentry/views/amCheckout/reserveAdditionalVolume';

type SliderInfo = {
Expand Down Expand Up @@ -201,26 +201,17 @@ describe('ReserveAdditionalVolume', () => {
const transactions = screen.getByTestId('transactions-volume-item').textContent;
expect(transactions).not.toContain('Sentry Performance');
});

it('can hide sliders', async () => {
render(<ReserveAdditionalVolume {...stepProps} />);
await openSection();
expect(screen.getByTestId('errors-volume-item')).toBeInTheDocument();
await closeSection();
expect(screen.queryByTestId('errors-volume-item')).not.toBeInTheDocument();
});
});

describe('Modern Plans', () => {
const {organization} = initializeOrg();
const subscription = SubscriptionFixture({organization});
let subscription: Subscription;

const billingConfig = BillingConfigFixture(PlanTier.AM3);
const bizPlanMonthly = PlanDetailsLookupFixture('am3_business')!;

const stepProps = {
const stepProps: any = {
checkoutTier: PlanTier.AM3,
subscription,
isActive: true,
stepNumber: 2,
onUpdate: jest.fn(),
Expand All @@ -238,6 +229,8 @@ describe('ReserveAdditionalVolume', () => {
};

beforeEach(() => {
subscription = SubscriptionFixture({organization});
stepProps.subscription = subscription;
SubscriptionStore.set(organization.slug, subscription);
MockApiClient.addMockResponse({
url: `/customers/${organization.slug}/plan-migrations/?applied=0`,
Expand Down Expand Up @@ -304,5 +297,12 @@ describe('ReserveAdditionalVolume', () => {
await closeSection();
expect(screen.queryByTestId('errors-volume-item')).not.toBeInTheDocument();
});

it('auto-shows sliders if customer has reserved volume above platform', () => {
const paidSub = SubscriptionFixture({organization, plan: 'am3_business'});
paidSub.categories.errors!.reserved = 100_000;
render(<ReserveAdditionalVolume {...stepProps} subscription={paidSub} />);
expect(screen.getByTestId('errors-volume-item')).toBeInTheDocument();
});
});
});
23 changes: 20 additions & 3 deletions static/gsApp/views/amCheckout/reserveAdditionalVolume.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {t} from 'sentry/locale';
import type {DataCategory} from 'sentry/types/core';

import {PlanTier} from 'getsentry/types';
import {isAmPlan} from 'getsentry/utils/billing';
import {isAmPlan, isDeveloperPlan} from 'getsentry/utils/billing';
import trackGetsentryAnalytics from 'getsentry/utils/trackGetsentryAnalytics';
import VolumeSliders from 'getsentry/views/amCheckout/steps/volumeSliders';
import type {StepProps} from 'getsentry/views/amCheckout/types';
import {formatPrice, getShortInterval} from 'getsentry/views/amCheckout/utils';
import {formatPrice, getBucket, getShortInterval} from 'getsentry/views/amCheckout/utils';

function ReserveAdditionalVolume({
organization,
Expand All @@ -33,7 +33,24 @@ function ReserveAdditionalVolume({
| 'formData'
| 'onUpdate'
>) {
const [showSliders, setShowSliders] = useState(false);
// if the customer has any reserved volume above platform already, auto-show the sliders
const [showSliders, setShowSliders] = useState<boolean>(
isDeveloperPlan(subscription.planDetails)
? false
: Object.values(subscription.categories ?? {})
.filter(
({category}) =>
activePlan.checkoutCategories.includes(category) &&
category in activePlan.planCategories
)
.some(
({category, reserved}) =>
getBucket({
buckets: activePlan.planCategories[category],
events: reserved ?? 0,
}).price > 0
)
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: State Initialization Fails on Null Categories

The useState initialization for showSliders can throw a TypeError if subscription.categories is null or undefined. Also, Object.values() returns category data objects, so destructuring {category} results in undefined. This prevents the filter from working, causes getBucket to receive undefined buckets, and breaks the auto-show logic.

Fix in Cursor Fix in Web

const reservedVolumeTotal = useMemo(() => {
return Object.entries(formData.reserved).reduce((acc, [category, value]) => {
const bucket = activePlan.planCategories?.[category as DataCategory]?.find(
Expand Down
Loading