Skip to content
Open
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
45 changes: 45 additions & 0 deletions static/gsApp/views/subscriptionPage/reservedUsageChart.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ import {act, render, screen} from 'sentry-test/reactTestingLibrary';
import {DataCategory} from 'sentry/types/core';
import {ChartDataTransform} from 'sentry/views/organizationStats/usageChart';

import {GIGABYTE} from 'getsentry/constants';
import {PlanTier, type BillingStats} from 'getsentry/types';
import {MILLISECONDS_IN_HOUR} from 'getsentry/utils/billing';

import ReservedUsageChart, {
getCategoryOptions,
mapCostStatsToChart,
mapReservedBudgetStatsToChart,
mapReservedToChart,
mapStatsToChart,
} from './reservedUsageChart';

Expand Down Expand Up @@ -62,6 +65,48 @@ describe('mapStatsToChart', () => {
});
});

describe('mapReservedToChart', () => {
it('should apply GIGABYTE multiplier for byte categories (attachments)', () => {
const reserved = 5; // 5 GB
const result = mapReservedToChart(reserved, DataCategory.ATTACHMENTS);
expect(result).toBe(reserved * GIGABYTE);
});

it('should apply GIGABYTE multiplier for byte categories (log bytes)', () => {
const reserved = 10; // 10 GB
const result = mapReservedToChart(reserved, DataCategory.LOG_BYTE);
expect(result).toBe(reserved * GIGABYTE);
});

it('should apply MILLISECONDS_IN_HOUR multiplier for duration categories', () => {
const reserved = 100; // 100 hours
const result = mapReservedToChart(reserved, DataCategory.PROFILE_DURATION);
expect(result).toBe(reserved * MILLISECONDS_IN_HOUR);
});

it('should apply multiplier of 1 for count categories (errors)', () => {
const reserved = 50000;
const result = mapReservedToChart(reserved, DataCategory.ERRORS);
expect(result).toBe(reserved);
});

it('should apply multiplier of 1 for count categories (transactions)', () => {
const reserved = 100000;
const result = mapReservedToChart(reserved, DataCategory.TRANSACTIONS);
expect(result).toBe(reserved);
});

it('should return 0 for unlimited reserved (-1)', () => {
const result = mapReservedToChart(-1, DataCategory.ERRORS);
expect(result).toBe(0);
});

it('should return 0 for null reserved', () => {
const result = mapReservedToChart(null, DataCategory.ERRORS);
expect(result).toBe(0);
});
});

describe('mapCostStatsToChart', () => {
const organization = OrganizationFixture();
const subscription = SubscriptionFixture({
Expand Down
12 changes: 5 additions & 7 deletions static/gsApp/views/subscriptionPage/reservedUsageChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
getTooltipFormatter,
} from 'sentry/views/organizationStats/usageChart/utils';

import {GIGABYTE} from 'getsentry/constants';
import {
ReservedBudgetCategoryType,
type BillingMetricHistory,
Expand All @@ -50,9 +49,9 @@ import {
isUnlimitedReserved,
} from 'getsentry/utils/billing';
import {
getCategoryInfoFromPlural,
getPlanCategoryName,
hasCategoryFeature,
isByteCategory,
isPartOfReservedBudget,
} from 'getsentry/utils/dataCategory';
import formatCurrency from 'getsentry/utils/formatCurrency';
Expand Down Expand Up @@ -181,15 +180,14 @@ function chartTooltip(category: DataCategory, displayMode: 'usage' | 'cost') {
});
}

function mapReservedToChart(reserved: number | null, category: DataCategory) {
export function mapReservedToChart(reserved: number | null, category: DataCategory) {
if (isUnlimitedReserved(reserved)) {
return 0;
}

if (isByteCategory(category)) {
return typeof reserved === 'number' ? reserved * GIGABYTE : 0;
}
return reserved || 0;
const categoryInfo = getCategoryInfoFromPlural(category);
const multiplier = categoryInfo?.formatting.reservedMultiplier ?? 1;
return typeof reserved === 'number' ? reserved * multiplier : 0;
}

function defaultChartData(): ChartStats {
Expand Down
17 changes: 12 additions & 5 deletions static/gsApp/views/subscriptionPage/usageAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ import {
isUnlimitedReserved,
UsageAction,
} from 'getsentry/utils/billing';
import {getPlanCategoryName, sortCategoriesWithKeys} from 'getsentry/utils/dataCategory';
import {
getCategoryInfoFromPlural,
getPlanCategoryName,
sortCategoriesWithKeys,
} from 'getsentry/utils/dataCategory';

import {ButtonWrapper, SubscriptionBody} from './styles';

Expand Down Expand Up @@ -64,13 +68,16 @@ function UsageAlert({subscription, usage}: Props) {
hadCustomDynamicSampling: subscription.hadCustomDynamicSampling,
});

const categoryInfo = getCategoryInfoFromPlural(category);
const isAbbreviated = categoryInfo?.formatting.projectedAbbreviated ?? true;

const formattedAmount = formatReservedWithUnits(projected, category, {
isAbbreviated: category !== DataCategory.ATTACHMENTS,
isAbbreviated,
});

return category === DataCategory.ATTACHMENTS
? `${formattedAmount} of attachments`
: `${formattedAmount} ${displayName}`;
return isAbbreviated
? `${formattedAmount} ${displayName}`
: `${formattedAmount} of ${displayName}`;
}

function projectedCategoryOverages() {
Expand Down
Loading