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:
parent
3f8d4c3538
commit
2ec575b85c
@ -34,13 +34,27 @@ describe('traffic overage calculation', () => {
|
||||
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 includedTraffic = 53_000_000;
|
||||
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);
|
||||
});
|
||||
|
||||
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', () => {
|
||||
const now = new Date();
|
||||
const period = toSelectablePeriod(now);
|
||||
|
@ -172,7 +172,8 @@ export const calculateOverageCost = (
|
||||
return 0;
|
||||
}
|
||||
|
||||
const overage = dataUsage - includedTraffic;
|
||||
const overage =
|
||||
Math.floor((dataUsage - includedTraffic) / 1_000_000) * 1_000_000;
|
||||
return overage > 0 ? calculateTrafficDataCost(overage) : 0;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user