From 852a76ef717f9a989cf82a6ef82645844bb185d6 Mon Sep 17 00:00:00 2001 From: James Donnelly <4444684+JDIZM@users.noreply.github.com> Date: Mon, 29 Jan 2024 09:26:20 +0000 Subject: [PATCH] test: mortgage calculator unit tests --- calc/mortgageCalculator.test.ts | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 calc/mortgageCalculator.test.ts diff --git a/calc/mortgageCalculator.test.ts b/calc/mortgageCalculator.test.ts new file mode 100644 index 0000000..e854565 --- /dev/null +++ b/calc/mortgageCalculator.test.ts @@ -0,0 +1,50 @@ +import { describe, expect, it } from "vitest"; +import { mortgageCalculator } from "./mortgageCalculator"; + +describe("mortgageCalculator", () => { + it("should calculate an interest only mortgage with the correct payments and pricipal", () => { + const result = mortgageCalculator( + { + homeValue: 150_000, + deposit: 15_000, + interestRate: 6, + years: 25 + }, + "interestOnly" + ); + + expect(result).toMatchObject({ + homeValue: 150000, + deposit: 15000, + interestPayments: { + yearly: 8100, + monthly: 675, + period: 675 + }, + principal: 135000, + years: 25, + interestRate: 6 + }); + }); + + it("should calculate a repayment mortgage with the correct monthly payment and remaining principal rounded to two decimal places", () => { + const result = mortgageCalculator( + { + homeValue: 150_000, + deposit: 15_000, + interestRate: 6, + years: 25 + }, + "repayment" + ); + + expect(result).toMatchObject({ + deposit: 15000, + homeValue: 150000, + interestRate: 6, + monthlyRepayment: 869.81, + principal: 135000, + years: 25 + }); + }); +});