Skip to content

Commit ad6752b

Browse files
committed
inline taxableChargeFn at taxableCharge getter
1 parent 889e45f commit ad6752b

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/reading/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { baseRate, taxableChargeFn } = require('../tax-utils');
1+
const { baseRate, taxThreshold } = require('../tax-utils');
22

33
class Reading {
44
constructor(data) {
@@ -29,7 +29,7 @@ class Reading {
2929
}
3030

3131
get taxableCharge() {
32-
return taxableChargeFn(this);
32+
return Math.max(0, this.baseCharge - taxThreshold(this.year));
3333
}
3434
}
3535

src/reading/index.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ describe('Reading', () => {
2828

2929
describe('taxableCharge', () => {
3030
it('should calculate the correct taxable charge', () => {
31-
jest.spyOn(TaxUtils, 'taxableChargeFn').mockReturnValue(0.5);
31+
jest.spyOn(TaxUtils, 'taxThreshold').mockReturnValue(1);
32+
jest.spyOn(TaxUtils, 'baseRate').mockReturnValue(1);
3233

3334
const rawData = { customer: 'Ivan', quantity: 10, month: 5, year: 2017 };
3435
const reading = new Reading(rawData);
3536

36-
expect(reading.taxableCharge).toEqual(0.5);
37+
expect(reading.taxableCharge).toEqual(9);
3738
});
3839
});
3940
});

0 commit comments

Comments
 (0)