mirror of
https://github.com/Unleash/unleash.git
synced 2025-10-27 11:02:16 +01:00
feat: overages should be rouned down to nearest integer (#10826)
This commit is contained in:
parent
adb1d200ea
commit
faad097915
@ -14,7 +14,7 @@ const hasValidUsageData = (consumption?: number, limit?: number): boolean => {
|
|||||||
|
|
||||||
const calculateOverage = (consumption?: number, limit?: number): number => {
|
const calculateOverage = (consumption?: number, limit?: number): number => {
|
||||||
return hasValidUsageData(consumption, limit)
|
return hasValidUsageData(consumption, limit)
|
||||||
? Math.max(0, consumption! - limit!)
|
? Math.floor(Math.max(0, consumption! - limit!))
|
||||||
: 0;
|
: 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -274,5 +274,27 @@ describe('calculateEstimateTotals', () => {
|
|||||||
totalAmount: 110,
|
totalAmount: 110,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('rounds down overages to integers', () => {
|
||||||
|
const usageLines = [
|
||||||
|
createUsageLine(150.7, 100, 2),
|
||||||
|
createUsageLine(200.3, 150, 1.5),
|
||||||
|
];
|
||||||
|
const result = calculateEstimateTotals(
|
||||||
|
'estimate',
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
10,
|
||||||
|
[],
|
||||||
|
usageLines,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
subtotal: 175,
|
||||||
|
taxAmount: 17.5,
|
||||||
|
totalAmount: 192.5,
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -25,7 +25,7 @@ export const calculateEstimateTotals = (
|
|||||||
const usageLinesTotal = usageLines.reduce((sum, line) => {
|
const usageLinesTotal = usageLines.reduce((sum, line) => {
|
||||||
const overage =
|
const overage =
|
||||||
line.consumption && line.limit
|
line.consumption && line.limit
|
||||||
? Math.max(0, line.consumption - line.limit)
|
? Math.floor(Math.max(0, line.consumption - line.limit))
|
||||||
: 0;
|
: 0;
|
||||||
return sum + overage * (line.unitPrice || 0);
|
return sum + overage * (line.unitPrice || 0);
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user