Skip to content

Commit

Permalink
fix: tiers show incorrect volumes if denominator differs (#18041)
Browse files Browse the repository at this point in the history
* use correct denom for previous tier and show correct number

* test the func
  • Loading branch information
raquelmsmith authored Oct 17, 2023
1 parent af751e6 commit 700fbc9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
18 changes: 17 additions & 1 deletion frontend/src/scenes/billing/billing-utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { convertAmountToUsage, convertUsageToAmount, projectUsage, summarizeUsage } from './billing-utils'
import {
convertAmountToUsage,
convertLargeNumberToWords,
convertUsageToAmount,
projectUsage,
summarizeUsage,
} from './billing-utils'
import tk from 'timekeeper'
import { dayjs } from 'lib/dayjs'
import billingJson from '~/mocks/fixtures/_billing_v2.json'
Expand Down Expand Up @@ -159,3 +165,13 @@ describe('convertAmountToUsageWithPercentDiscount', () => {
}
)
})

describe('convertLargeNumberToWords', () => {
it('should convert large numbers to words', () => {
expect(convertLargeNumberToWords(250, null, true, 'survey')).toEqual('First 250 surveys/mo')
expect(convertLargeNumberToWords(500, 250, true, 'survey')).toEqual('251-500')
expect(convertLargeNumberToWords(1000, 500, true, 'survey')).toEqual('501-1k')
expect(convertLargeNumberToWords(10000, 1000, true, 'survey')).toEqual('1-10k')
expect(convertLargeNumberToWords(10000000, 1000000, true, 'survey')).toEqual('1-10 million')
})
})
10 changes: 8 additions & 2 deletions frontend/src/scenes/billing/billing-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,20 @@ export const convertLargeNumberToWords = (
}

let denominator = 1

if (num >= 1000000) {
denominator = 1000000
} else if (num >= 1000) {
denominator = 1000
}

return `${previousNum ? `${(previousNum / denominator).toFixed(0)}-` : multipleTiers ? 'First ' : ''}${(
let prevDenominator = 1
if (previousNum && previousNum >= 1000000) {
prevDenominator = 1000000
} else if (previousNum && previousNum >= 1000) {
prevDenominator = 1000
}

return `${previousNum ? `${((previousNum + 1) / prevDenominator).toFixed(0)}-` : multipleTiers ? 'First ' : ''}${(
num / denominator
).toFixed(0)}${denominator === 1000000 ? ' million' : denominator === 1000 ? 'k' : ''}${
!previousNum && multipleTiers ? ` ${productType}s/mo` : ''
Expand Down

0 comments on commit 700fbc9

Please sign in to comment.