From 9ba36c73d3946a2ae417b41d2d088d6d24288b1a Mon Sep 17 00:00:00 2001 From: Sam Brown Date: Wed, 3 Apr 2024 08:24:47 +0100 Subject: [PATCH] Make 2024/25 the default, add tests (#19) --- README.md | 4 +- src/hmrc.test.ts | 10 +++- src/hmrc.ts | 2 +- src/incomeTax.test.ts | 93 +++++++++++++++++++++++++++++++++-- src/nationalInsurance.test.ts | 35 +++++++++++++ 5 files changed, 136 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6e06e45..59a83a3 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@ This library makes it easy to calculate, based on a PAYE taxable salary: Multiple versions of the HMRC rates can be supported, although only the follwing years have been implemented: -- 2024/25 -- 2023/24 (default) +- 2024/25 (default) +- 2023/24 - 2022/23 Works in all modern browsers and Node.js (LTS recommended). diff --git a/src/hmrc.test.ts b/src/hmrc.test.ts index 6859434..938a43f 100644 --- a/src/hmrc.test.ts +++ b/src/hmrc.test.ts @@ -1,8 +1,10 @@ import { getHmrcRates } from "./hmrc"; describe("getHmrcRates", () => { - test("It uses default 2023/24 rates", () => { - expect(getHmrcRates().DEFAULT_PERSONAL_ALLOWANCE).toEqual(12570); + test("It uses default 2024/25 rates", () => { + const rates = getHmrcRates(); + expect(rates.DEFAULT_PERSONAL_ALLOWANCE).toEqual(12570); + expect(rates.NI_MIDDLE_RATE).toEqual(0.08); }); test("It uses explicit 2022/23 rates", () => { @@ -12,4 +14,8 @@ describe("getHmrcRates", () => { test("It uses explicit 2023/24 rates", () => { expect(getHmrcRates("2023/24").DEFAULT_PERSONAL_ALLOWANCE).toEqual(12570); }); + + test("It uses explicit 2024/25 rates", () => { + expect(getHmrcRates("2024/25").DEFAULT_PERSONAL_ALLOWANCE).toEqual(12570); + }); }); diff --git a/src/hmrc.ts b/src/hmrc.ts index 0e9acba..dc911d9 100644 --- a/src/hmrc.ts +++ b/src/hmrc.ts @@ -106,7 +106,7 @@ const taxRates: Record = { export const getHmrcRates = (taxYear?: TaxYear) => { if (!taxYear) { - return taxRates["2023/24"]; + return taxRates["2024/25"]; } return taxRates[taxYear]; diff --git a/src/incomeTax.test.ts b/src/incomeTax.test.ts index a5d3cec..8c59188 100644 --- a/src/incomeTax.test.ts +++ b/src/incomeTax.test.ts @@ -1,7 +1,7 @@ import { calculateIncomeTax } from "./incomeTax"; import { calculatePersonalAllowance } from "./personalAllowance"; -const expectations = [ +const expectationsA = [ { 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 }, @@ -66,8 +66,8 @@ const expectations = [ }, ]; -describe("calculateIncomeTax", () => { - expectations.forEach((expectation) => { +describe("calculateIncomeTax (23/24)", () => { + expectationsA.forEach((expectation) => { const { taxableAnnualIncome, basic, higher, additional } = expectation; test(taxableAnnualIncome.toString(), () => { const personalAllowance = calculatePersonalAllowance({ @@ -87,3 +87,90 @@ describe("calculateIncomeTax", () => { }); }); }); + +const expectationsB = [ + { 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 }, + { taxableAnnualIncome: 22_500, basic: 1986, higher: 0, additional: 0 }, + { taxableAnnualIncome: 25_000, basic: 2486, higher: 0, additional: 0 }, + { taxableAnnualIncome: 50_000, basic: 7486, higher: 0, additional: 0 }, + { taxableAnnualIncome: 55_000, basic: 7540, higher: 1892, additional: 0 }, + { taxableAnnualIncome: 60_000, basic: 7540, higher: 3892, additional: 0 }, + { taxableAnnualIncome: 75_000, basic: 7540, higher: 9892, additional: 0 }, + { taxableAnnualIncome: 90_000, basic: 7540, higher: 15892, additional: 0 }, + { taxableAnnualIncome: 105_000, basic: 7540, higher: 22892, additional: 0 }, + { taxableAnnualIncome: 110_000, basic: 7540, higher: 25892, additional: 0 }, + { + taxableAnnualIncome: 130_000, + basic: 7540, + higher: 34976, + additional: 2187, + }, + { + taxableAnnualIncome: 145_000, + basic: 7540, + higher: 34976, + additional: 8937, + }, + { + taxableAnnualIncome: 160_000, + basic: 7540, + higher: 34976, + additional: 15687, + }, + { + taxableAnnualIncome: 175_000, + basic: 7540, + higher: 34976, + additional: 22437, + }, + { + taxableAnnualIncome: 200_000, + basic: 7540, + higher: 34976, + additional: 33687, + }, + { + taxableAnnualIncome: 250_000, + basic: 7540, + higher: 34976, + additional: 56187, + }, + { + taxableAnnualIncome: 500_000, + basic: 7540, + higher: 34976, + additional: 168687, + }, + { + taxableAnnualIncome: 1_000_000, + basic: 7540, + higher: 34976, + additional: 393687, + }, +]; + +describe("calculateIncomeTax (24/25)", () => { + expectationsB.forEach((expectation) => { + const { taxableAnnualIncome, basic, higher, additional } = expectation; + test(taxableAnnualIncome.toString(), () => { + const personalAllowance = calculatePersonalAllowance({ + taxYear: "2024/25", + taxableAnnualIncome, + }); + const taxAmounts = calculateIncomeTax({ + taxYear: "2024/25", + taxableAnnualIncome, + personalAllowance, + }); + expect(taxAmounts).toEqual({ + basicRateTax: basic, + higherRateTax: higher, + additionalRateTax: additional, + }); + }); + }); +}); diff --git a/src/nationalInsurance.test.ts b/src/nationalInsurance.test.ts index b47815d..a67cfc2 100644 --- a/src/nationalInsurance.test.ts +++ b/src/nationalInsurance.test.ts @@ -69,3 +69,38 @@ describe("calculateEmployeeNationalInsurance (23/24)", () => { }); }); }); + +const expectationsC = [ + { taxableAnnualIncome: 15_000, nics: 193.28 }, + { taxableAnnualIncome: 17_500, nics: 393.28 }, + { taxableAnnualIncome: 20_000, nics: 593.28 }, + { taxableAnnualIncome: 22_500, nics: 793.28 }, + { taxableAnnualIncome: 25_000, nics: 993.28 }, + { taxableAnnualIncome: 50_000, nics: 2993.28 }, + { taxableAnnualIncome: 55_000, nics: 3110.32 }, + { taxableAnnualIncome: 60_000, nics: 3210.32 }, + { taxableAnnualIncome: 75_000, nics: 3510.32 }, + { taxableAnnualIncome: 90_000, nics: 3810.32 }, + { taxableAnnualIncome: 110_000, nics: 4210.32 }, + { taxableAnnualIncome: 130_000, nics: 4610.32 }, + { taxableAnnualIncome: 150_000, nics: 5010.32 }, + { taxableAnnualIncome: 175_000, nics: 5510.32 }, + { taxableAnnualIncome: 200_000, nics: 6010.32 }, + { taxableAnnualIncome: 250_000, nics: 7010.32 }, + { taxableAnnualIncome: 500_000, nics: 12010.32 }, + { taxableAnnualIncome: 1_000_000, nics: 22010.32 }, +]; + +describe("calculateEmployeeNationalInsurance (24/25)", () => { + expectationsC.forEach((expectation) => { + const { taxableAnnualIncome, nics } = expectation; + test(taxableAnnualIncome.toString(), () => { + expect( + calculateEmployeeNationalInsurance({ + taxYear: "2024/25", + taxableAnnualIncome, + }) + ).toBeCloseTo(nics, 1); + }); + }); +});