1
0
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:
Jaanus Sellin 2025-10-17 15:09:52 +03:00 committed by GitHub
parent adb1d200ea
commit faad097915
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 2 deletions

View File

@ -14,7 +14,7 @@ const hasValidUsageData = (consumption?: number, limit?: number): boolean => {
const calculateOverage = (consumption?: number, limit?: number): number => {
return hasValidUsageData(consumption, limit)
? Math.max(0, consumption! - limit!)
? Math.floor(Math.max(0, consumption! - limit!))
: 0;
};

View File

@ -274,5 +274,27 @@ describe('calculateEstimateTotals', () => {
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,
});
});
});
});

View File

@ -25,7 +25,7 @@ export const calculateEstimateTotals = (
const usageLinesTotal = usageLines.reduce((sum, line) => {
const overage =
line.consumption && line.limit
? Math.max(0, line.consumption - line.limit)
? Math.floor(Math.max(0, line.consumption - line.limit))
: 0;
return sum + overage * (line.unitPrice || 0);
}, 0);