1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-23 00:22:19 +01:00

fix: traffic estimate should Math.floor price estimate to full million (#8468)

<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->

## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

<!-- Does it close an issue? Multiple? -->
Closes #

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
<!--
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#
-->

### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->


## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->
This commit is contained in:
Ivar Conradi Østhus 2024-10-17 09:45:45 +02:00 committed by GitHub
parent 3f8d4c3538
commit 2ec575b85c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View File

@ -34,13 +34,27 @@ describe('traffic overage calculation', () => {
expect(result).toBe(0); expect(result).toBe(0);
}); });
it('should return 5 if overage this month is atleast 1 request above included', () => { it('should return 0 if overage this month is atleast 1 request above included', () => {
const dataUsage = 53_000_001; const dataUsage = 53_000_001;
const includedTraffic = 53_000_000; const includedTraffic = 53_000_000;
const result = calculateOverageCost(dataUsage, includedTraffic); const result = calculateOverageCost(dataUsage, includedTraffic);
expect(result).toBe(0);
});
it('should return 5 if overage this month is atleast 1M request above included', () => {
const dataUsage = 54_000_000;
const includedTraffic = 53_000_000;
const result = calculateOverageCost(dataUsage, includedTraffic);
expect(result).toBe(5); expect(result).toBe(5);
}); });
it('should return 10 if overage this month is > 2M request above included', () => {
const dataUsage = 55_100_000;
const includedTraffic = 53_000_000;
const result = calculateOverageCost(dataUsage, includedTraffic);
expect(result).toBe(10);
});
it('doesnt estimate when having less than 5 days worth of data', () => { it('doesnt estimate when having less than 5 days worth of data', () => {
const now = new Date(); const now = new Date();
const period = toSelectablePeriod(now); const period = toSelectablePeriod(now);

View File

@ -172,7 +172,8 @@ export const calculateOverageCost = (
return 0; return 0;
} }
const overage = dataUsage - includedTraffic; const overage =
Math.floor((dataUsage - includedTraffic) / 1_000_000) * 1_000_000;
return overage > 0 ? calculateTrafficDataCost(overage) : 0; return overage > 0 ? calculateTrafficDataCost(overage) : 0;
}; };