diff --git a/.changeset/flat-moments-flash.md b/.changeset/flat-moments-flash.md new file mode 100644 index 0000000..edd834a --- /dev/null +++ b/.changeset/flat-moments-flash.md @@ -0,0 +1,5 @@ +--- +'@epilot/pricing': patch +--- + +Improve tier display string diff --git a/src/tiers/utils.test.ts b/src/tiers/utils.test.ts index 3c5ddf8..e2cb38c 100644 --- a/src/tiers/utils.test.ts +++ b/src/tiers/utils.test.ts @@ -204,7 +204,7 @@ describe('getTierDescription', () => { ${PricingModel.tieredVolume} | ${tierWithUnitAmount} | ${'kWh'} | ${'de'} | ${'EUR'} | ${mockedTranslationFn} | ${true} | ${false} | ${undefined} | ${undefined} | ${'Starts at 10,00 €/kWh'} ${PricingModel.tieredVolume} | ${tierWithUnitAmount} | ${'kWh'} | ${'en'} | ${'USD'} | ${mockedTranslationFn} | ${true} | ${false} | ${undefined} | ${undefined} | ${'Starts at $10.00/kWh'} ${PricingModel.tieredVolume} | ${tierWithUnitAmount} | ${'kWh'} | ${'en'} | ${'EUR'} | ${mockedTranslationFn} | ${true} | ${true} | ${undefined} | ${undefined} | ${'Starts at €10.00/kWh'} - ${PricingModel.tieredVolume} | ${tierWithSubunitAmount} | ${'kWh'} | ${'en'} | ${'EUR'} | ${mockedTranslationFn} | ${true} | ${true} | ${undefined} | ${undefined} | ${'Starts at 5.12 cents/kWh'} + ${PricingModel.tieredVolume} | ${tierWithSubunitAmount} | ${'kWh'} | ${'en'} | ${'EUR'} | ${mockedTranslationFn} | ${true} | ${true} | ${undefined} | ${undefined} | ${'Starts at 5.123412 cents/kWh'} ${PricingModel.tieredVolume} | ${tierWithSubunitAmount} | ${'kWh'} | ${'en'} | ${'EUR'} | ${mockedTranslationFn} | ${true} | ${true} | ${undefined} | ${4} | ${'Starts at 5.1234 cents/kWh'} ${PricingModel.tieredVolume} | ${tierWithUnitAmount} | ${undefined} | ${'en'} | ${'EUR'} | ${mockedTranslationFn} | ${true} | ${false} | ${undefined} | ${undefined} | ${'Starts at €10.00'} ${PricingModel.tieredVolume} | ${tierWithUnitAmount} | ${'unit'} | ${'en'} | ${'EUR'} | ${mockedTranslationFn} | ${true} | ${false} | ${undefined} | ${undefined} | ${'Starts at €10.00'} @@ -261,10 +261,10 @@ describe('getTierDescription', () => { it.each` pricingModel | tier | unit | locale | currency | t | showStartsAt | enableSubunitDisplay | shouldDisplayOnRequest | tax | expected - ${PricingModel.tieredGraduated} | ${tierWithUnitAmount} | ${'kWh'} | ${'en'} | ${'EUR'} | ${mockedTranslationFn} | ${true} | ${false} | ${undefined} | ${{ isInclusive: true, rate: 10 }} | ${'Starts at €9.09/kWh'} - ${PricingModel.tieredVolume} | ${tierWithUnitAmount} | ${'kWh'} | ${'en'} | ${'EUR'} | ${mockedTranslationFn} | ${true} | ${false} | ${undefined} | ${{ isInclusive: true, rate: 10 }} | ${'Starts at €9.09/kWh'} - ${PricingModel.tieredVolume} | ${tierWithSubunitAmount} | ${'kWh'} | ${'en'} | ${'EUR'} | ${mockedTranslationFn} | ${true} | ${true} | ${undefined} | ${{ isInclusive: true, rate: 10 }} | ${'Starts at 4.66 cents/kWh'} - ${PricingModel.tieredFlatFee} | ${tierWithFlatFeeAmount} | ${'kWh'} | ${'en'} | ${'EUR'} | ${mockedTranslationFn} | ${true} | ${false} | ${undefined} | ${{ isInclusive: true, rate: 10 }} | ${'Starts at €9.09'} + ${PricingModel.tieredGraduated} | ${tierWithUnitAmount} | ${'kWh'} | ${'en'} | ${'EUR'} | ${mockedTranslationFn} | ${true} | ${false} | ${undefined} | ${{ isInclusive: true, rate: 10 }} | ${'Starts at €9.090909090909/kWh'} + ${PricingModel.tieredVolume} | ${tierWithUnitAmount} | ${'kWh'} | ${'en'} | ${'EUR'} | ${mockedTranslationFn} | ${true} | ${false} | ${undefined} | ${{ isInclusive: true, rate: 10 }} | ${'Starts at €9.090909090909/kWh'} + ${PricingModel.tieredVolume} | ${tierWithSubunitAmount} | ${'kWh'} | ${'en'} | ${'EUR'} | ${mockedTranslationFn} | ${true} | ${true} | ${undefined} | ${{ isInclusive: true, rate: 10 }} | ${'Starts at 4.657647 cents/kWh'} + ${PricingModel.tieredFlatFee} | ${tierWithFlatFeeAmount} | ${'kWh'} | ${'en'} | ${'EUR'} | ${mockedTranslationFn} | ${true} | ${false} | ${undefined} | ${{ isInclusive: true, rate: 10 }} | ${'Starts at €9.090909090909'} `( 'should return correct net values for the tier, when pricingModel=$pricingModel, unit=$unit, locale=$locale, currency=$currency, showStartsAt=$showStartsAt', ({ diff --git a/src/tiers/utils.ts b/src/tiers/utils.ts index 71d8b3d..b8558d3 100644 --- a/src/tiers/utils.ts +++ b/src/tiers/utils.ts @@ -144,7 +144,7 @@ export function getTierDescription( return; } - const { showStartsAt = true, enableSubunitDisplay = false, precision = 2 } = options; + const { showStartsAt = true, enableSubunitDisplay = false, precision } = options; const showUnitAmount = (pricingModel === PricingModel.tieredGraduated || pricingModel === PricingModel.tieredVolume) && typeof tier.unit_amount === 'number'; @@ -161,7 +161,7 @@ export function getTierDescription( currency, locale, enableSubunitDisplay, - precision, + ...(precision !== undefined ? { precision } : { useRealPrecision: true }), }; const unitAmountDecimal =