Skip to content

Commit b3e920a

Browse files
committed
introduce taxableChargeFn function
1 parent 847cb3d commit b3e920a

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/tax-utils/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,14 @@ function taxThreshold(year) {
2525
return THRESHOLDS_BY_YEAR[year];
2626
}
2727

28-
module.exports = { baseRate, taxThreshold, RATES_BY_MONTH_AND_YEAR, THRESHOLDS_BY_YEAR };
28+
function taxableChargeFn(aReading) {
29+
return Math.max(0, aReading.baseCharge - taxThreshold(aReading.year));
30+
}
31+
32+
module.exports = {
33+
baseRate,
34+
taxThreshold,
35+
taxableChargeFn,
36+
RATES_BY_MONTH_AND_YEAR,
37+
THRESHOLDS_BY_YEAR,
38+
};

src/tax-utils/index.test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
const { baseRate, RATES_BY_MONTH_AND_YEAR, taxThreshold, THRESHOLDS_BY_YEAR } = require('.');
1+
const {
2+
baseRate,
3+
RATES_BY_MONTH_AND_YEAR,
4+
taxThreshold,
5+
THRESHOLDS_BY_YEAR,
6+
taxableChargeFn,
7+
} = require('.');
28

39
describe('tax-utils', () => {
410
describe('baseRate', () => {
@@ -12,4 +18,14 @@ describe('tax-utils', () => {
1218
expect(taxThreshold(2017)).toEqual(THRESHOLDS_BY_YEAR[2017]);
1319
});
1420
});
21+
22+
describe('taxableChargeFn', () => {
23+
it('should return zero if result is negative', () => {
24+
expect(taxableChargeFn({ baseCharge: 0, year: 2017 })).toEqual(0);
25+
});
26+
27+
it('should calculate the correct taxable charge', () => {
28+
expect(taxableChargeFn({ baseCharge: 1, year: 2017 })).toEqual(0.5);
29+
});
30+
});
1531
});

0 commit comments

Comments
 (0)