Skip to content

Commit

Permalink
Merge pull request #78 from epilot-dev/feat/support-unit-decimal-getag
Browse files Browse the repository at this point in the history
Feat: Support Decimal Unitary Values In GetAG
  • Loading branch information
paulofph authored Jun 7, 2024
2 parents 8083be9 + 0a2cda9 commit 679f592
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/pricing-getag.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ describe('GetAG - computeAggregatedAndPriceTotals', () => {
amount_tax: 4101,
item_components: expect.arrayContaining([
expect.objectContaining({
unit_amount_net: 1293,
unit_amount_net_decimal: '12.925028011205',
unit_amount_gross: 1538,
unit_amount_gross_decimal: '15.380783333334',
get_ag: expect.objectContaining({
category: 'power',
markup_amount: 1000,
Expand All @@ -234,6 +238,10 @@ describe('GetAG - computeAggregatedAndPriceTotals', () => {
}),
}),
expect.objectContaining({
unit_amount_net: 20,
unit_amount_net_decimal: '0.202893613445',
unit_amount_gross: 24,
unit_amount_gross_decimal: '0.2414434',
get_ag: expect.objectContaining({
category: 'power',
markup_amount: 10,
Expand Down Expand Up @@ -263,6 +271,7 @@ describe('GetAG - computeAggregatedAndPriceTotals', () => {
}),
);
});

it('returns the correct amount_total having consumption input zero', () => {
const priceItems: PriceItemDto[] = [compositePriceGetAGWithZeroInputMapping];

Expand Down Expand Up @@ -457,7 +466,7 @@ describe('GetAG - computeAggregatedAndPriceTotals', () => {
});

describe('when model is tiered_flatfee', () => {
it('returns the correct amount_total', () => {
it('returns the correct amount_total', () => {
const priceItems: PriceItemDto[] = [compositePriceTieredFlatFeeGetAG];

const result = computeAggregatedAndPriceTotals(priceItems);
Expand Down
6 changes: 6 additions & 0 deletions src/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,12 @@ const convertPriceItemPrecision = (priceItem: PriceItem, precision = 2): PriceIt
...(typeof priceItem.unit_amount_net === 'number' && {
unit_amount_net: d(priceItem.unit_amount_net).convertPrecision(precision).getAmount(),
}),
...(typeof priceItem.unit_amount_net === 'number' && {
unit_amount_net_decimal: d(priceItem.unit_amount_net!).toUnit().toString(),
}),
...(typeof priceItem.unit_amount_gross === 'number' && {
unit_amount_gross_decimal: d(priceItem.unit_amount_gross!).toUnit().toString(),
}),
unit_amount_gross: d(priceItem.unit_amount_gross!).convertPrecision(precision).getAmount(),
amount_subtotal: d(priceItem.amount_subtotal!).convertPrecision(precision).getAmount(),
amount_subtotal_decimal: d(priceItem.amount_subtotal!).toUnit().toString(),
Expand Down

0 comments on commit 679f592

Please sign in to comment.