Skip to content

Commit

Permalink
Make 2024/25 the default, add tests (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgb-io authored Apr 3, 2024
1 parent eb32d94 commit 9ba36c7
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
10 changes: 8 additions & 2 deletions src/hmrc.test.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand All @@ -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);
});
});
2 changes: 1 addition & 1 deletion src/hmrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const taxRates: Record<TaxYear, TaxRates> = {

export const getHmrcRates = (taxYear?: TaxYear) => {
if (!taxYear) {
return taxRates["2023/24"];
return taxRates["2024/25"];
}

return taxRates[taxYear];
Expand Down
93 changes: 90 additions & 3 deletions src/incomeTax.test.ts
Original file line number Diff line number Diff line change
@@ -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 },
Expand Down Expand Up @@ -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({
Expand All @@ -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,
});
});
});
});
35 changes: 35 additions & 0 deletions src/nationalInsurance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit 9ba36c7

Please sign in to comment.