Last active
January 5, 2026 00:16
-
-
Save ikotse-code/a932c1a8344481c2a54fe33b12eba349 to your computer and use it in GitHub Desktop.
7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {BaseContract} from "../src/BaseContract"; | |
| //using before/afterEach | |
| let contract: BaseContract; | |
| beforeEach(() => { | |
| contract = new BaseContract("C-1", "Alice", false); | |
| contract.activate(); | |
| console.log(`Contract activated: ${contract.contractId}`); | |
| }) | |
| afterEach(() => { | |
| contract.deactivate(); | |
| console.log(`Contract deactivated: ${contract.contractId}`); | |
| }) | |
| test("can create a contract",() => { | |
| expect(contract.contractId).toBe("C-1"); | |
| expect(contract.clientName).toBe("Alice"); | |
| }) | |
| test("should activate the contract correctly", () => { | |
| expect(contract.isActive).toBe(true); | |
| }) | |
| test("should deactivate the contract when deactivate() is called", () => { | |
| contract.deactivate(); | |
| expect(contract.isActive).toBe(false); | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class BaseContract { | |
| contractId: string; | |
| clientName: string; | |
| isActive: boolean; | |
| constructor(contractId: string, clientName: string, isActive: boolean) { | |
| this.contractId = contractId; | |
| this.clientName = clientName; | |
| this.isActive = isActive; | |
| } | |
| activate(): void { | |
| this.isActive = true; | |
| } | |
| deactivate(): void { | |
| this.isActive = false; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {DepositContract} from "../src/DepositContract"; | |
| //using basic test approach | |
| test("can create a deposit contract",() => { | |
| const depositContract = new DepositContract("D-1", "Bob", false, 15, 10); | |
| expect(depositContract.contractId).toBe("D-1"); | |
| expect(depositContract.clientName).toBe("Bob"); | |
| expect(depositContract.isActive).toBe(false); | |
| expect(depositContract.amount).toBe(15); | |
| expect(depositContract.interestRate).toBe(10); | |
| }) | |
| test("activate and calculate interest for deposit contract",() => { | |
| const depositContract = new DepositContract("D-2", "James", false, 25, 5); | |
| depositContract.activate(); | |
| expect(depositContract.isActive).toBe(true); | |
| console.log(`Deposit contract activated: ${depositContract.contractId}`); | |
| expect(depositContract.calculateInterest()).toBe(125); | |
| }) | |
| test("deactivate deposit contract",() => { | |
| const depositContract = new DepositContract("D-3", "Jane", true, 25, 5); | |
| depositContract.deactivate(); | |
| expect(depositContract.isActive).toBe(false); | |
| console.log(`Deposit contract deactivated: ${depositContract.contractId}`); | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {BaseContract} from "./BaseContract"; | |
| export class DepositContract extends BaseContract { | |
| amount: number; | |
| interestRate: number; | |
| constructor(contractId: string, clientName: string, isActive: boolean, amount: number, interestRate: number) { | |
| super(contractId, clientName, isActive); | |
| this.amount = amount; | |
| this.interestRate = interestRate; | |
| } | |
| calculateInterest(): number { | |
| return this.amount * this.interestRate; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {InsuranceContract} from "../src/InsuranceContract"; | |
| //using basic test approach | |
| test("can create a insurance contract",() => { | |
| const insuranceContract = new InsuranceContract("I-1", "Bobby", false, "health", 10, 15); | |
| expect(insuranceContract.contractId).toBe("I-1"); | |
| expect(insuranceContract.clientName).toBe("Bobby"); | |
| expect(insuranceContract.isActive).toBe(false); | |
| expect(insuranceContract.insuranceType).toBe("health"); | |
| expect(insuranceContract.premium).toBe(10); | |
| expect(insuranceContract.termYears).toBe(15); | |
| }) | |
| test("activate and calculate total premium for insurance contract",() => { | |
| const insuranceContract = new InsuranceContract("I-2", "James", false,"property", 25, 5); | |
| insuranceContract.activate(); | |
| expect(insuranceContract.isActive).toBe(true); | |
| console.log(`Insurance contract activated: ${insuranceContract.contractId}`); | |
| expect(insuranceContract.calculateTotalPremium()).toBe(125); | |
| }) | |
| test("deactivate insurance contract",() => { | |
| const insuranceContract = new InsuranceContract("I-3", "Jane", true, "property", 25, 5); | |
| insuranceContract.deactivate(); | |
| expect(insuranceContract.isActive).toBe(false); | |
| console.log(`Insurance contract deactivated: ${insuranceContract.contractId}`); | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {BaseContract} from "./BaseContract"; | |
| export class InsuranceContract extends BaseContract { | |
| insuranceType: string; | |
| premium: number; | |
| termYears: number; | |
| constructor(contractId: string, clientName: string, isActive: boolean, insuranceType: string, premium: number, termYears: number) { | |
| super(contractId, clientName, isActive); | |
| this.insuranceType = insuranceType; | |
| this.premium = premium; | |
| this.termYears = termYears; | |
| } | |
| calculateTotalPremium(): number { | |
| return this.premium * this.termYears; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {LoanContract} from "../src/LoanContract"; | |
| //using before/afterEach | |
| let loanContract: LoanContract; | |
| beforeEach(() => { | |
| loanContract = new LoanContract("L-1", "Andy", false, 30, 20, 2); | |
| loanContract.activate(); | |
| console.log(`Loan contract activated: ${loanContract.contractId}`); | |
| }) | |
| afterEach(() => { | |
| loanContract.deactivate(); | |
| console.log(`Loan contract deactivated: ${loanContract.contractId}`); | |
| }) | |
| test("can create a loan contract",() => { | |
| expect(loanContract.contractId).toBe("L-1"); | |
| expect(loanContract.clientName).toBe("Andy"); | |
| expect(loanContract.loanAmount).toBe(30); | |
| expect(loanContract.monthlyPayment).toBe(20); | |
| expect(loanContract.loanTermMonths).toBe(2); | |
| }) | |
| test("should activate the loan contract correctly", () => { | |
| expect(loanContract.isActive).toBe(true); | |
| }) | |
| test("should deactivate the loan contract when deactivate() is called", () => { | |
| loanContract.deactivate(); | |
| expect(loanContract.isActive).toBe(false); | |
| }) | |
| test("should calculate total payment for loan contract correctly",() => { | |
| expect(loanContract.calculateTotalPayment()).toBe(40); | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {BaseContract} from "./BaseContract"; | |
| export class LoanContract extends BaseContract{ | |
| loanAmount: number; | |
| monthlyPayment: number; | |
| loanTermMonths: number; | |
| constructor(contractId: string, clientName: string, isActive: boolean, loanAmount: number, monthlyPayment: number, loanTermMonths: number) { | |
| super(contractId, clientName, isActive); | |
| this.loanAmount = loanAmount; | |
| this.monthlyPayment = monthlyPayment; | |
| this.loanTermMonths = loanTermMonths; | |
| } | |
| calculateTotalPayment(): number { | |
| return this.monthlyPayment * this.loanTermMonths; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment