Skip to content

Commit 19ed5f5

Browse files
authored
1 parent b851b90 commit 19ed5f5

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed

static/gsApp/utils/billing.spec.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,54 @@ describe('formatReservedWithUnits', function () {
203203
);
204204
expect(formatReservedWithUnits(0, DataCategory.SPANS, {}, true)).toBe('$0.00');
205205
});
206+
207+
it('returns correct string for logs', function () {
208+
expect(formatReservedWithUnits(0, DataCategory.LOG_BYTE)).toBe('0 GB');
209+
expect(formatReservedWithUnits(0.1, DataCategory.LOG_BYTE)).toBe('0.1 GB');
210+
expect(formatReservedWithUnits(1, DataCategory.LOG_BYTE)).toBe('1 GB');
211+
expect(formatReservedWithUnits(1000, DataCategory.LOG_BYTE)).toBe('1,000 GB');
212+
213+
expect(
214+
formatReservedWithUnits(0.1234, DataCategory.LOG_BYTE, {
215+
isAbbreviated: true,
216+
})
217+
).toBe('0 GB');
218+
expect(
219+
formatReservedWithUnits(1.234, DataCategory.LOG_BYTE, {
220+
isAbbreviated: true,
221+
})
222+
).toBe('1 GB');
223+
expect(
224+
formatReservedWithUnits(0.1, DataCategory.LOG_BYTE, {
225+
useUnitScaling: true,
226+
})
227+
).toBe('0.1 GB');
228+
expect(
229+
formatReservedWithUnits(1, DataCategory.LOG_BYTE, {
230+
useUnitScaling: true,
231+
})
232+
).toBe('1 GB');
233+
expect(
234+
formatReservedWithUnits(1000, DataCategory.LOG_BYTE, {
235+
useUnitScaling: true,
236+
})
237+
).toBe('1 TB');
238+
expect(
239+
formatReservedWithUnits(1234, DataCategory.LOG_BYTE, {
240+
useUnitScaling: true,
241+
})
242+
).toBe('1.23 TB');
243+
expect(
244+
formatReservedWithUnits(1234 * BILLION, DataCategory.LOG_BYTE, {
245+
useUnitScaling: true,
246+
})
247+
).toBe('1.23 ZB');
248+
expect(
249+
formatReservedWithUnits(-1 / GIGABYTE, DataCategory.LOG_BYTE, {
250+
useUnitScaling: true,
251+
})
252+
).toBe(UNLIMITED);
253+
});
206254
});
207255

208256
describe('formatUsageWithUnits', function () {

static/gsApp/utils/billing.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ export function formatReservedWithUnits(
145145
if (isReservedBudget) {
146146
return displayPriceWithCents({cents: reservedQuantity ?? 0});
147147
}
148-
if (dataCategory !== DataCategory.ATTACHMENTS) {
148+
if (
149+
dataCategory !== DataCategory.ATTACHMENTS &&
150+
dataCategory !== DataCategory.LOG_BYTE
151+
) {
149152
return formatReservedNumberToString(reservedQuantity, options);
150153
}
151154
// convert reservedQuantity to BYTES to check for unlimited
@@ -158,23 +161,26 @@ export function formatReservedWithUnits(
158161
return `${formatted} GB`;
159162
}
160163

161-
return formatAttachmentUnits(reservedQuantity || 0, 3);
164+
return formatByteUnits(reservedQuantity || 0, 3);
162165
}
163166

164167
/**
165168
* This expects values from CustomerUsageEndpoint, which contains usage
166169
* quantities for the data categories that we sell.
167170
*
168-
* Note: usageQuantity for Attachments should be in BYTES
171+
* Note: usageQuantity for Attachments and Logs should be in BYTES
169172
*/
170173
export function formatUsageWithUnits(
171174
usageQuantity = 0,
172175
dataCategory: DataCategory,
173176
options: FormatOptions = {isAbbreviated: false, useUnitScaling: false}
174177
) {
175-
if (dataCategory === DataCategory.ATTACHMENTS) {
178+
if (
179+
dataCategory === DataCategory.ATTACHMENTS ||
180+
dataCategory === DataCategory.LOG_BYTE
181+
) {
176182
if (options.useUnitScaling) {
177-
return formatAttachmentUnits(usageQuantity);
183+
return formatByteUnits(usageQuantity);
178184
}
179185

180186
const usageGb = usageQuantity / GIGABYTE;
@@ -242,7 +248,7 @@ function formatReservedNumberToString(
242248
* For storage/memory/file sizes, please take a look at the function in
243249
* sentry/utils/formatBytes.
244250
*/
245-
function formatAttachmentUnits(bytes: number, u = 0) {
251+
function formatByteUnits(bytes: number, u = 0) {
246252
const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
247253
const threshold = 1000;
248254

0 commit comments

Comments
 (0)