Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion frontend/src/hooks/useTrafficData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/hooks/useTrafficData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
Loading