From f011f5fd0b2feef9a61b4762c47a17a53f29ee55 Mon Sep 17 00:00:00 2001 From: Sam Brown Date: Wed, 27 Sep 2023 19:24:50 +0100 Subject: [PATCH] Return zero taxes instead of throwing when income is below PA (#9) --- src/incomeTax.test.ts | 2 ++ src/incomeTax.ts | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/incomeTax.test.ts b/src/incomeTax.test.ts index dde7d6c..8571a6a 100644 --- a/src/incomeTax.test.ts +++ b/src/incomeTax.test.ts @@ -2,6 +2,8 @@ import { calculateIncomeTax } from "./incomeTax"; import { calculatePersonalAllowance } from "./personalAllowance"; const expectations = [ + { taxableAnnualIncome: 0, basic: 0, higher: 0, additional: 0 }, + { taxableAnnualIncome: 5_000, basic: 0, higher: 0, additional: 0 }, { taxableAnnualIncome: 15_000, basic: 486, higher: 0, additional: 0 }, { taxableAnnualIncome: 17_500, basic: 986, higher: 0, additional: 0 }, { taxableAnnualIncome: 20_000, basic: 1486, higher: 0, additional: 0 }, diff --git a/src/incomeTax.ts b/src/incomeTax.ts index b7357d0..bda2b8e 100644 --- a/src/incomeTax.ts +++ b/src/incomeTax.ts @@ -85,5 +85,10 @@ export const calculateIncomeTax = ({ }; } - throw new Error("Unexpected Input"); + // Income is lower than the personal allowance - no income tax + return { + basicRateTax: 0, + higherRateTax: 0, + additionalRateTax: 0, + }; };