Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions blockchain/test/ElectionFactory.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ describe("ElectionFactory", function () {
options: ["Option 1", "Option 2", "Option 3"]
};

const mockCandidates = [
{
name: "Candidate 1",
description: "First candidate",
candidateID: 1
},
{
name: "Candidate 2",
description: "Second candidate",
candidateID: 2
}
];


beforeEach(async function () {
[owner, user1, user2, router] = await ethers.getSigners();

Expand All @@ -35,26 +49,26 @@ describe("ElectionFactory", function () {

describe("Election Creation", function () {
it("Should create a new election", async function () {
await factory.createElection(mockElectionInfo, 0, 0);
await factory.createElection(mockElectionInfo,mockCandidates, 0, 0);
expect(await factory.electionCount()).to.equal(1);

const openElections = await factory.getOpenElections();
expect(openElections.length).to.equal(1);
});

it("Should allow multiple elections creation", async function () {
await factory.createElection(mockElectionInfo, 0, 0);
await factory.createElection(mockElectionInfo, 0, 0);
await factory.createElection(mockElectionInfo,mockCandidates, 0, 0);
await factory.createElection(mockElectionInfo,mockCandidates, 0, 0);

expect(await factory.electionCount()).to.equal(2);
const openElections = await factory.getOpenElections();
expect(openElections.length).to.equal(2);
});
});

describe("Election Deletion", function () {
beforeEach(async function () {
await factory.createElection(mockElectionInfo, 0, 0);
await factory.createElection(mockElectionInfo, mockCandidates,0, 0);
});

it("Should allow owner to delete their election", async function () {
Expand Down Expand Up @@ -89,4 +103,4 @@ describe("ElectionFactory", function () {
).to.be.revertedWithCustomError(factory, "OwnerRestricted");
});
});
});
});