Skip to content

Commit

Permalink
Create Insurance.test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Dec 2, 2024
1 parent 42d9faf commit 2ed6f06
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("Insurance Contract", function () {
let Insurance, insurance, policyHolder;

beforeEach(async function () {
[policyHolder] = await ethers.getSigners();
Insurance = await ethers.getContractFactory("Insurance");
insurance = await Insurance.deploy();
await insurance.deployed();
});

it("should allow a user to purchase a policy", async function () {
await insurance.connect(policyHolder).purchasePolicy(ethers.utils.parseEther("1"), ethers.utils.parseEther("5"), { value: ethers.utils.parseEther("1") });
const policy = await insurance.policies(1);
expect(policy.policyHolder).to.equal(policyHolder.address);
expect(policy.coverageAmount).to.equal(ethers.utils.parseEther("5"));
expect(policy.isActive).to.be.true;
});

it("should allow a policy holder to claim a policy", async function () {
await insurance.connect(policyHolder).purchasePolicy(ethers.utils.parseEther("1"), ethers.utils.parseEther("5"), { value: ethers.utils.parseEther("1") });
await insurance.connect(policyHolder).claimPolicy(1);
const policy = await insurance.policies(1);
expect(policy.isActive).to.be.false;
});
});

0 comments on commit 2ed6f06

Please sign in to comment.