From acf2987a82a0593f8a45c84aa3465b5b7bde56bc Mon Sep 17 00:00:00 2001 From: Yun Kai Peng Date: Thu, 10 Jun 2021 01:22:48 -0400 Subject: [PATCH 1/4] fix: improved account tests --- tests/account.test.js | 176 +++++++++++++++++++++++++++++++- tests/setup.spec.js | 18 +--- tests/util/account.test.util.js | 52 +++++++++- 3 files changed, 225 insertions(+), 21 deletions(-) diff --git a/tests/account.test.js b/tests/account.test.js index 567a2dae..fe32151c 100644 --- a/tests/account.test.js +++ b/tests/account.test.js @@ -40,8 +40,37 @@ const newAccount0 = util.account.unlinkedAccounts.new[0]; //This account should NOT have a phone number const noPhoneAccount = util.account.NoPhoneHackerAccount0; +const Util = { + Account: require("./util/account.test.util"), + Bus: require("./util/bus.test.util"), + Hacker: require("./util/hacker.test.util"), + Role: require("./util/role.test.util"), + RoleBinding: require("./util/roleBinding.test.util"), + Settings: require("./util/settings.test.util"), + Sponsor: require("./util/sponsor.test.util"), + Staff: require("./util/staff.test.util"), + Team: require("./util/team.test.util"), + Volunteer: require("./util/volunteer.test.util"), + AccountConfirmation: require("./util/accountConfirmation.test.util"), + ResetPassword: require("./util/resetPassword.test.util.js") +}; + describe("GET user account", function() { - // fail on authentication + async function storeAll() { + await Util.Account.storeHackerStaffAccounts(); + await Util.Role.storeAll(); + await Util.RoleBinding.storeAll(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("should FAIL to list the user's account on /api/account/self GET due to authentication", function(done) { chai.request(server.app) .get("/api/account/self") @@ -207,6 +236,21 @@ describe("GET user account", function() { }); describe("POST create account", function() { + async function storeAll() { + await Util.Account.storeHackerStaffAccounts(); + await Util.Role.storeAll(); + await Util.RoleBinding.storeAll(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("should SUCCEED and create a new account", function(done) { chai.request(server.app) .post(`/api/account/`) @@ -230,7 +274,6 @@ describe("POST create account", function() { done(); }); }); - it("should FAIL to create an account because the email is already in use", function(done) { chai.request(server.app) .post(`/api/account/`) @@ -241,7 +284,6 @@ describe("POST create account", function() { done(); }); }); - it("should SUCCEED and create a new account without a phone number", function(done) { chai.request(server.app) .post("/api/account") @@ -269,6 +311,22 @@ describe("POST create account", function() { }); describe("POST confirm account", function() { + async function storeAll() { + await Util.Account.storeExtraAccounts(); + await Util.AccountConfirmation.storeAll(); + await Util.Role.storeAll(); + await Util.RoleBinding.storeAll(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("should SUCCEED and confirm the account", function(done) { chai.request(server.app) .post(`/api/auth/confirm/${confirmationToken}`) @@ -282,6 +340,7 @@ describe("POST confirm account", function() { done(); }); }); + it("should FAIL confirming the account", function(done) { chai.request(server.app) .post(`/api/auth/confirm/${fakeToken}`) @@ -295,6 +354,7 @@ describe("POST confirm account", function() { done(); }); }); + it("should FAIL to confirm account that has token with email but no account", function(done) { chai.request(server.app) .post(`/api/auth/confirm/${fakeToken}`) @@ -324,7 +384,22 @@ describe("PATCH update account", function() { lastName: "fail", email: storedAccount1.email }; - + async function storeAll() { + await Util.Account.storePatchUpdateAccount(); + await Util.AccountConfirmation.storeAll(); + await Util.Role.storeAll(); + await Util.RoleBinding.storeAll(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); // fail on authentication it("should FAIL to update an account due to authentication", function(done) { chai.request(server.app) @@ -446,6 +521,22 @@ describe("POST reset password", function() { const password = { password: "NewPassword" }; + async function storeAll() { + await Util.Account.storePostResetPasswordAccounts(); + await Util.ResetPassword.storeAll(); + await Util.Role.storeAll(); + await Util.RoleBinding.storeAll(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("should SUCCEED and change the password", function(done) { chai.request(server.app) .post("/api/auth/password/reset") @@ -472,6 +563,23 @@ describe("PATCH change password for logged in user", function() { oldPassword: "WrongPassword", newPassword: "password12345" }; + async function storeAll() { + // can use same function as storeGetInviteAccounts + await Util.Account.storeGetInviteAccounts(); + await Util.ResetPassword.storeAll(); + await Util.Role.storeAll(); + await Util.RoleBinding.storeAll(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); // fail on authentication it("should FAIL to change the user's password because they are not logged in", function(done) { chai.request(server.app) @@ -533,6 +641,21 @@ describe("PATCH change password for logged in user", function() { }); describe("GET retrieve permissions", function() { + async function storeAll() { + await Util.Account.storeHackerStaffAccounts(); + await Util.Role.storeAll(); + await Util.RoleBinding.storeAll(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("should SUCCEED and retrieve the rolebindings for the user", function(done) { util.auth.login(agent, teamHackerAccount0, (error) => { if (error) { @@ -573,6 +696,20 @@ describe("GET retrieve permissions", function() { }); describe("GET resend confirmation email", function() { + async function storeAll() { + await Util.Account.storeVerifyConfirmationAccounts(); + await Util.AccountConfirmation.storeAll(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("should SUCCEED and resend the confirmation email", function(done) { util.auth.login(agent, storedAccount1, (error) => { if (error) { @@ -634,6 +771,21 @@ describe("GET resend confirmation email", function() { }); describe("POST invite account", function() { + async function storeAll() { + await Util.Account.storePostInviteAccount(); + await Util.Role.storeAll(); + await Util.RoleBinding.storeAll(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("Should succeed to invite a user to create an account", function(done) { util.auth.login(agent, Admin0, (error) => { if (error) { @@ -666,6 +818,22 @@ describe("POST invite account", function() { }); describe("GET invites", function() { + async function storeAll() { + await Util.Account.storeGetInviteAccounts(); + await Util.AccountConfirmation.storeAll(); + await Util.Role.storeAll(); + await Util.RoleBinding.storeAll(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("Should FAIL to get all invites due to Authentication", function(done) { chai.request(server.app) .get("/api/account/invite") diff --git a/tests/setup.spec.js b/tests/setup.spec.js index fd04be3b..ea387b65 100644 --- a/tests/setup.spec.js +++ b/tests/setup.spec.js @@ -35,9 +35,9 @@ before(function(done) { }); }); -beforeEach(function(done) { +after(function(done) { this.timeout(60000); - storeAll() + dropAll() .then(() => { done(); }) @@ -56,20 +56,6 @@ afterEach(function(done) { done(error); }); }); -async function storeAll() { - await Util.Account.storeAll(); - await Util.Settings.storeAll(); - await Util.Hacker.storeAll(); - await Util.Sponsor.storeAll(); - await Util.Team.storeAll(); - await Util.Staff.storeAll(); - await Util.AccountConfirmation.storeAll(); - await Util.ResetPassword.storeAll(); - await Util.Bus.storeAll(); - await Util.Volunteer.storeAll(); - await Util.Role.storeAll(); - await Util.RoleBinding.storeAll(); -} async function dropAll() { await Util.RoleBinding.dropAll(); diff --git a/tests/util/account.test.util.js b/tests/util/account.test.util.js index 0c98d81a..7e5049bd 100644 --- a/tests/util/account.test.util.js +++ b/tests/util/account.test.util.js @@ -317,7 +317,7 @@ const NoPhoneHackerAccount0 = { confirmed: false, birthDate: "1980-07-30", accountType: Constants.HACKER -} +}; const extraAccounts = [ waitlistedHacker0, @@ -346,6 +346,14 @@ module.exports = { extraAccounts: extraAccounts, storeAll: storeAll, + storeStaffAccounts: storeStaffAccounts, + storeHackerStaffAccounts: storeHackerStaffAccounts, + storeVerifyConfirmationAccounts: storeVerifyConfirmationAccounts, + storePostInviteAccount: storePostInviteAccount, + storeGetInviteAccounts: storeGetInviteAccounts, + storeExtraAccounts: storeExtraAccounts, + storePatchUpdateAccount: storePatchUpdateAccount, + storePostResetPasswordAccounts: storePostResetPasswordAccounts, dropAll: dropAll, equals: equals }; @@ -368,6 +376,48 @@ function store(attributes) { return Account.collection.insertMany(acctDocs); } +async function storePostResetPasswordAccounts() { + await store(hackerAccounts.stored.team); +} + +async function storeStaffAccounts() { + await store(hackerAccounts.stored.team); + await store(hackerAccounts.stored.noTeam); + await store(hackerAccounts.stored.unconfirmed); + await store(staffAccounts.stored); +} + +async function storeGetInviteAccounts() { + await store(hackerAccounts.stored.team); + await store(staffAccounts.stored); +} + +async function storePatchUpdateAccount() { + await store(hackerAccounts.stored.team); + await store(staffAccounts.stored); + await store(extraAccounts); +} + +async function storeHackerStaffAccounts() { + await store(hackerAccounts.stored.team); + await store(hackerAccounts.stored.noTeam); + await store(staffAccounts.stored); +} + +async function storeExtraAccounts() { + await store(extraAccounts); +} + +async function storeVerifyConfirmationAccounts() { + await store(hackerAccounts.stored.team); + await store(extraAccounts); +} + +async function storePostInviteAccount() { + await store(staffAccounts.stored); + await store(unlinkedAccounts.stored); +} + async function storeAll() { await store(hackerAccounts.stored.team); await store(hackerAccounts.stored.noTeam); From 37ed0739238effdc960525fa976116d9b9628151 Mon Sep 17 00:00:00 2001 From: James Xu <36768789+jamesxu123@users.noreply.github.com> Date: Sun, 20 Jun 2021 21:52:05 -0400 Subject: [PATCH 2/4] empty: trigger CI --- tests/account.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/account.test.js b/tests/account.test.js index fe32151c..689c7774 100644 --- a/tests/account.test.js +++ b/tests/account.test.js @@ -17,6 +17,7 @@ const util = { accountConfirmation: require("./util/accountConfirmation.test.util"), reset: require("./util/resetPassword.test.util") }; + const agent = chai.request.agent(server.app); // tokens const confirmationToken = util.accountConfirmation.ConfirmationToken; From 48ebbe1b0e7e63ca8a34ce4a045bffc6ac8c1d5e Mon Sep 17 00:00:00 2001 From: James Xu <36768789+jamesxu123@users.noreply.github.com> Date: Mon, 21 Jun 2021 00:29:58 -0400 Subject: [PATCH 3/4] empty: trigger github actions --- tests/account.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/account.test.js b/tests/account.test.js index 689c7774..fe32151c 100644 --- a/tests/account.test.js +++ b/tests/account.test.js @@ -17,7 +17,6 @@ const util = { accountConfirmation: require("./util/accountConfirmation.test.util"), reset: require("./util/resetPassword.test.util") }; - const agent = chai.request.agent(server.app); // tokens const confirmationToken = util.accountConfirmation.ConfirmationToken; From 1526effa25aa1f1e74f841bbb1bbff2cd3b5492f Mon Sep 17 00:00:00 2001 From: Yun Kai Peng Date: Sun, 27 Jun 2021 00:14:17 -0400 Subject: [PATCH 4/4] fixed: added all improvements --- tests/account.test.js | 90 ++++++++---------- tests/auth.test.js | 13 +++ tests/hacker.test.js | 139 ++++++++++++++++++++++++++- tests/role.test.js | 18 +++- tests/search.service.spec.js | 22 ++++- tests/settings.test.js | 36 ++++++- tests/sponsor.test.js | 68 ++++++++++++- tests/team.test.js | 164 +++++++++++++++++++++++--------- tests/util/account.test.util.js | 51 ++++++++-- tests/volunteer.test.js | 36 ++++++- 10 files changed, 525 insertions(+), 112 deletions(-) diff --git a/tests/account.test.js b/tests/account.test.js index fe32151c..14d525ec 100644 --- a/tests/account.test.js +++ b/tests/account.test.js @@ -15,7 +15,11 @@ const util = { account: require("./util/account.test.util"), auth: require("./util/auth.test.util"), accountConfirmation: require("./util/accountConfirmation.test.util"), - reset: require("./util/resetPassword.test.util") + reset: require("./util/resetPassword.test.util"), + role: require("./util/role.test.util"), + roleBinding: require("./util/roleBinding.test.util"), + accountConfirmation: require("./util/accountConfirmation.test.util"), + resetPassword: require("./util/resetPassword.test.util.js") }; const agent = chai.request.agent(server.app); // tokens @@ -40,26 +44,11 @@ const newAccount0 = util.account.unlinkedAccounts.new[0]; //This account should NOT have a phone number const noPhoneAccount = util.account.NoPhoneHackerAccount0; -const Util = { - Account: require("./util/account.test.util"), - Bus: require("./util/bus.test.util"), - Hacker: require("./util/hacker.test.util"), - Role: require("./util/role.test.util"), - RoleBinding: require("./util/roleBinding.test.util"), - Settings: require("./util/settings.test.util"), - Sponsor: require("./util/sponsor.test.util"), - Staff: require("./util/staff.test.util"), - Team: require("./util/team.test.util"), - Volunteer: require("./util/volunteer.test.util"), - AccountConfirmation: require("./util/accountConfirmation.test.util"), - ResetPassword: require("./util/resetPassword.test.util.js") -}; - describe("GET user account", function() { async function storeAll() { - await Util.Account.storeHackerStaffAccounts(); - await Util.Role.storeAll(); - await Util.RoleBinding.storeAll(); + await util.account.storeHackerStaffAccounts(); + await util.role.storeAll(); + await util.roleBinding.storeAll(); } beforeEach(function(done) { this.timeout(60000); @@ -237,9 +226,9 @@ describe("GET user account", function() { describe("POST create account", function() { async function storeAll() { - await Util.Account.storeHackerStaffAccounts(); - await Util.Role.storeAll(); - await Util.RoleBinding.storeAll(); + await util.account.storeHackerStaffAccounts(); + await util.role.storeAll(); + await util.roleBinding.storeAll(); } beforeEach(function(done) { this.timeout(60000); @@ -312,10 +301,10 @@ describe("POST create account", function() { describe("POST confirm account", function() { async function storeAll() { - await Util.Account.storeExtraAccounts(); - await Util.AccountConfirmation.storeAll(); - await Util.Role.storeAll(); - await Util.RoleBinding.storeAll(); + await util.account.storeExtraAccounts(); + await util.accountConfirmation.storeAll(); + await util.role.storeAll(); + await util.roleBinding.storeAll(); } beforeEach(function(done) { this.timeout(60000); @@ -385,10 +374,10 @@ describe("PATCH update account", function() { email: storedAccount1.email }; async function storeAll() { - await Util.Account.storePatchUpdateAccount(); - await Util.AccountConfirmation.storeAll(); - await Util.Role.storeAll(); - await Util.RoleBinding.storeAll(); + await util.account.storeHackerStaffExtraAccount(); + await util.accountConfirmation.storeAll(); + await util.role.storeAll(); + await util.roleBinding.storeAll(); } beforeEach(function(done) { this.timeout(60000); @@ -522,10 +511,10 @@ describe("POST reset password", function() { password: "NewPassword" }; async function storeAll() { - await Util.Account.storePostResetPasswordAccounts(); - await Util.ResetPassword.storeAll(); - await Util.Role.storeAll(); - await Util.RoleBinding.storeAll(); + await util.account.storeStoredTeamAccounts(); + await util.resetPassword.storeAll(); + await util.role.storeAll(); + await util.roleBinding.storeAll(); } beforeEach(function(done) { this.timeout(60000); @@ -564,11 +553,10 @@ describe("PATCH change password for logged in user", function() { newPassword: "password12345" }; async function storeAll() { - // can use same function as storeGetInviteAccounts - await Util.Account.storeGetInviteAccounts(); - await Util.ResetPassword.storeAll(); - await Util.Role.storeAll(); - await Util.RoleBinding.storeAll(); + await util.account.storeGetInviteAccounts(); + await util.resetPassword.storeAll(); + await util.role.storeAll(); + await util.roleBinding.storeAll(); } beforeEach(function(done) { this.timeout(60000); @@ -642,9 +630,9 @@ describe("PATCH change password for logged in user", function() { describe("GET retrieve permissions", function() { async function storeAll() { - await Util.Account.storeHackerStaffAccounts(); - await Util.Role.storeAll(); - await Util.RoleBinding.storeAll(); + await util.account.storeHackerStaffAccounts(); + await util.role.storeAll(); + await util.roleBinding.storeAll(); } beforeEach(function(done) { this.timeout(60000); @@ -697,8 +685,8 @@ describe("GET retrieve permissions", function() { describe("GET resend confirmation email", function() { async function storeAll() { - await Util.Account.storeVerifyConfirmationAccounts(); - await Util.AccountConfirmation.storeAll(); + await util.account.storeVerifyConfirmationAccounts(); + await util.accountConfirmation.storeAll(); } beforeEach(function(done) { this.timeout(60000); @@ -772,9 +760,9 @@ describe("GET resend confirmation email", function() { describe("POST invite account", function() { async function storeAll() { - await Util.Account.storePostInviteAccount(); - await Util.Role.storeAll(); - await Util.RoleBinding.storeAll(); + await util.account.storeStaffUnlinkedAccount(); + await util.role.storeAll(); + await util.roleBinding.storeAll(); } beforeEach(function(done) { this.timeout(60000); @@ -819,10 +807,10 @@ describe("POST invite account", function() { describe("GET invites", function() { async function storeAll() { - await Util.Account.storeGetInviteAccounts(); - await Util.AccountConfirmation.storeAll(); - await Util.Role.storeAll(); - await Util.RoleBinding.storeAll(); + await util.account.storeGetInviteAccounts(); + await util.accountConfirmation.storeAll(); + await util.role.storeAll(); + await util.roleBinding.storeAll(); } beforeEach(function(done) { this.timeout(60000); diff --git a/tests/auth.test.js b/tests/auth.test.js index 2a488f92..e833cf53 100644 --- a/tests/auth.test.js +++ b/tests/auth.test.js @@ -27,6 +27,19 @@ const roles = require("../constants/role.constant"); const teamHackerAccount0 = util.account.hackerAccounts.stored.team[0]; describe("GET roles", function() { + async function storeAll() { + await util.role.storeAll(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("should list all roles GET", function(done) { util.auth.login(agent, teamHackerAccount0, (error) => { if (error) { diff --git a/tests/hacker.test.js b/tests/hacker.test.js index 027dfa34..23d3d076 100644 --- a/tests/hacker.test.js +++ b/tests/hacker.test.js @@ -19,7 +19,9 @@ const util = { hacker: require("./util/hacker.test.util"), account: require("./util/account.test.util"), settings: require("./util/settings.test.util"), - accountConfirmation: require("./util/accountConfirmation.test.util") + accountConfirmation: require("./util/accountConfirmation.test.util"), + role: require("./util/role.test.util"), + roleBinding: require("./util/roleBinding.test.util") }; const StorageService = require("../services/storage.service"); @@ -63,6 +65,22 @@ const BatchAcceptHackerArrayInvalid = [ ]; describe("GET hacker", function() { + async function storeAll() { + await util.hacker.storeAll(); + await util.account.storeStaffNoTeamTeamUnconfirmedInvalid(); + await util.role.storeAll(); + await util.roleBinding.storeAll(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); // fail on authentication it("should FAIL to list a hacker's information on /api/hacker/:id GET due to authentication", function(done) { chai.request(server.app) @@ -369,6 +387,23 @@ describe("GET hacker", function() { }); describe("POST create hacker", function() { + async function storeAll() { + await util.roleBinding.storeAll(); + await util.role.storeAll(); + await util.settings.storeAll(); + await util.hacker.storeAll(); + await util.account.storeOneOfEach(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); // fail on authentication it("should FAIL to create a new hacker due to lack of authentication", function(done) { chai.request(server.app) @@ -684,6 +719,23 @@ describe("POST create hacker", function() { }); describe("PATCH update multiple hackers", function() { + async function storeAll() { + await util.roleBinding.storeAll(); + await util.role.storeAll(); + await util.settings.storeAll(); + await util.hacker.storeAll(); + await util.account.storeOneOfEach(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("should FAIL input validation on /api/hacker/batchAccept as an Admin", function(done) { util.auth.login(agent, Admin0, (error) => { if (error) { @@ -784,6 +836,23 @@ describe("PATCH update multiple hackers", function() { }); describe("PATCH update one hacker", function() { + async function storeAll() { + await util.roleBinding.storeAll(); + await util.role.storeAll(); + await util.settings.storeAll(); + await util.hacker.storeAll(); + await util.account.storeOneOfEach(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); // fail on authentication it("should FAIL to update a hacker on /api/hacker/:id GET due to authentication", function(done) { chai.request(server.app) @@ -1516,6 +1585,23 @@ describe("PATCH update one hacker", function() { }); describe("POST add a hacker resume", function() { + async function storeAll() { + await util.roleBinding.storeAll(); + await util.role.storeAll(); + await util.settings.storeAll(); + await util.hacker.storeAll(); + await util.account.storeOneOfEach(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("It should SUCCEED and upload a resume for a hacker", function(done) { //this takes a lot of time for some reason util.auth.login(agent, noTeamHacker0, (error) => { @@ -1563,6 +1649,23 @@ describe("POST add a hacker resume", function() { }); describe("GET Hacker stats", function() { + async function storeAll() { + await util.roleBinding.storeAll(); + await util.role.storeAll(); + await util.settings.storeAll(); + await util.hacker.storeAll(); + await util.account.storeHackerStaffAccounts(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("It should FAIL and get hacker stats (invalid validation)", function(done) { //this takes a lot of time for some reason util.auth.login(agent, Admin0, (error) => { @@ -1646,6 +1749,23 @@ describe("GET Hacker stats", function() { }); describe("POST send week-of email", function() { + async function storeAll() { + await util.roleBinding.storeAll(); + await util.role.storeAll(); + await util.settings.storeAll(); + await util.hacker.storeAll(); + await util.account.storeStaffNoTeamTeamUnconfirmedInvalid(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("It should FAIL to send the week-of email due to invalid Authentication", function(done) { //this takes a lot of time for some reason chai.request(server.app) @@ -1723,6 +1843,23 @@ describe("POST send week-of email", function() { }); describe("POST send day-of email", function() { + async function storeAll() { + await util.roleBinding.storeAll(); + await util.role.storeAll(); + await util.settings.storeAll(); + await util.hacker.storeAll(); + await util.account.storeOneOfEach(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("It should FAIL to send the day-of email due to invalid Authentication", function(done) { //this takes a lot of time for some reason chai.request(server.app) diff --git a/tests/role.test.js b/tests/role.test.js index 43298793..bcbf217a 100644 --- a/tests/role.test.js +++ b/tests/role.test.js @@ -10,7 +10,8 @@ const should = chai.should(); const util = { role: require("./util/role.test.util"), account: require("./util/account.test.util"), - auth: require("./util/auth.test.util") + auth: require("./util/auth.test.util"), + roleBinding: require("./util/roleBinding.test.util") }; const Constants = { @@ -22,6 +23,21 @@ const Admin0 = util.account.staffAccounts.stored[0]; const Hacker0 = util.account.hackerAccounts.stored.team[0]; describe("POST create role", function() { + async function storeAll() { + await util.account.storeHackerStaffAccounts(); + await util.roleBinding.storeAll(); + await util.role.storeAll(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("should Fail to create a role because staff is not logged in", function(done) { chai.request(server.app) .post(`/api/role/`) diff --git a/tests/search.service.spec.js b/tests/search.service.spec.js index 0495c1a2..4b681eea 100644 --- a/tests/search.service.spec.js +++ b/tests/search.service.spec.js @@ -17,7 +17,10 @@ const Constants = { const util = { hacker: require("./util/hacker.test.util"), account: require("./util/account.test.util"), - auth: require("./util/auth.test.util") + auth: require("./util/auth.test.util"), + role: require("./util/role.test.util"), + roleBinding: require("./util/roleBinding.test.util"), + settings: require("./util/settings.test.util") }; const queryToExecute = [ @@ -49,6 +52,23 @@ const Admin0 = util.account.staffAccounts.stored[0]; const noTeamHackerAccount0 = util.account.hackerAccounts.stored.noTeam[0]; describe("Searching for hackers", function() { + async function storeAll() { + await util.roleBinding.storeAll(); + await util.role.storeAll(); + await util.settings.storeAll(); + await util.hacker.storeAll(); + await util.account.storeOneOfEach(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("Should FAIL to search due to invalid authentication", function(done) { util.auth.login( agent, diff --git a/tests/settings.test.js b/tests/settings.test.js index 12c6f55e..5f3c8163 100644 --- a/tests/settings.test.js +++ b/tests/settings.test.js @@ -8,7 +8,9 @@ chai.should(); const util = { account: require("./util/account.test.util"), auth: require("./util/auth.test.util"), - settings: require("./util/settings.test.util") + settings: require("./util/settings.test.util"), + role: require("./util/role.test.util"), + roleBinding: require("./util/roleBinding.test.util") }; const Constants = { @@ -20,6 +22,22 @@ const invalidAccount = util.account.hackerAccounts.stored.noTeam[0]; const Admin = util.account.staffAccounts.stored[0]; describe("GET settings", function() { + async function storeAll() { + await util.account.storeHackerStaffExtraAccount(); + await util.settings.storeAll(); + await util.role.storeAll(); + await util.roleBinding.storeAll(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("should get the current settings", function(done) { chai.request(server.app) .get(`/api/settings/`) @@ -35,6 +53,22 @@ describe("GET settings", function() { }); describe("PATCH settings", function() { + async function storeAll() { + await util.account.storeHackerStaffExtraAccount(); + await util.settings.storeAll(); + await util.role.storeAll(); + await util.roleBinding.storeAll(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("should FAIL to update the settings due to lack of authentication", function(done) { chai.request(server.app) .patch(`/api/settings/`) diff --git a/tests/sponsor.test.js b/tests/sponsor.test.js index e48d1076..bf27c9f0 100644 --- a/tests/sponsor.test.js +++ b/tests/sponsor.test.js @@ -15,7 +15,9 @@ const Constants = { const util = { sponsor: require("./util/sponsor.test.util"), auth: require("./util/auth.test.util"), - account: require("./util/account.test.util") + account: require("./util/account.test.util"), + role: require("./util/role.test.util"), + roleBinding: require("./util/roleBinding.test.util") }; const Admin0 = util.account.staffAccounts.stored[0]; @@ -28,6 +30,22 @@ const newT2Sponsor0 = util.sponsor.newT2Sponsor0; let duplicateSponsor = util.sponsor.duplicateAccountLinkSponsor1; describe("GET user's sponsor info", function() { + async function storeAll() { + await util.roleBinding.storeAll(); + await util.role.storeAll(); + await util.sponsor.storeAll(); + await util.account.storeSponsorAccount(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("should FAIL list a sponsor's information due to authentication from /api/sponsor/self GET", function(done) { chai.request(server.app) .get(`/api/sponsor/self`) @@ -138,6 +156,22 @@ describe("GET user's sponsor info", function() { }); describe("GET sponsor by id", function() { + async function storeAll() { + await util.roleBinding.storeAll(); + await util.role.storeAll(); + await util.sponsor.storeAll(); + await util.account.storeSponsorAccount(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("should FAIL list a sponsor's information due to authentication from /api/sponsor/:id GET", function(done) { chai.request(server.app) .get(`/api/sponsor/` + T1Sponsor0._id) @@ -270,6 +304,22 @@ describe("GET sponsor by id", function() { }); describe("POST create sponsor", function() { + async function storeAll() { + await util.roleBinding.storeAll(); + await util.role.storeAll(); + await util.sponsor.storeAll(); + await util.account.storeSponsorAccount(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("should FAIL to create a new sponsor due to lack of authentication", function(done) { chai.request(server.app) .post(`/api/sponsor`) @@ -368,6 +418,22 @@ describe("POST create sponsor", function() { }); describe("PATCH update sponsor", function() { + async function storeAll() { + await util.roleBinding.storeAll(); + await util.role.storeAll(); + await util.sponsor.storeAll(); + await util.account.storeSponsorAccount(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("should FAIL to update a sponsor due to lack of authentication", function(done) { chai.request(server.app) .patch(`/api/sponsor/${T1Sponsor0._id}/`) diff --git a/tests/team.test.js b/tests/team.test.js index d6c596ce..5223ae26 100644 --- a/tests/team.test.js +++ b/tests/team.test.js @@ -10,7 +10,9 @@ const util = { team: require("./util/team.test.util"), hacker: require("./util/hacker.test.util"), account: require("./util/account.test.util"), - auth: require("./util/auth.test.util") + auth: require("./util/auth.test.util"), + role: require("./util/role.test.util"), + roleBinding: require("./util/roleBinding.test.util") }; const Constants = { @@ -25,11 +27,28 @@ const teamHackerAccount0 = util.account.hackerAccounts.stored.team[0]; const noTeamHackerAccount0 = util.account.hackerAccounts.stored.noTeam[0]; const sponsorT1Account0 = util.account.sponsorT1Accounts.stored[0]; -describe("GET team", function () { - it("should FAIL to list a team's information due to lack of authentication", function (done) { +describe("GET team", function() { + async function storeAll() { + await util.roleBinding.storeAll(); + await util.role.storeAll(); + await util.team.storeAll(); + await util.account.storeTeamAccount(); + await util.hacker.storeAll(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); + it("should FAIL to list a team's information due to lack of authentication", function(done) { chai.request(server.app) .get(`/api/team/${util.team.Team3._id}`) - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(401); res.should.be.json; res.body.should.have.property("message"); @@ -40,7 +59,7 @@ describe("GET team", function () { }); }); - it("should Fail and list a team's information from /api/team/ GET due to non existant team id", function (done) { + it("should Fail and list a team's information from /api/team/ GET due to non existant team id", function(done) { util.auth.login( agent, util.account.hackerAccounts.stored.team[0], @@ -51,7 +70,7 @@ describe("GET team", function () { } return agent .get(`/api/team/${util.team.newTeam1._id}`) - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(404); res.should.be.json; res.body.should.have.property("message"); @@ -66,7 +85,7 @@ describe("GET team", function () { ); }); - it("should SUCCEED and list a team's information from /api/team/ GET", function (done) { + it("should SUCCEED and list a team's information from /api/team/ GET", function(done) { util.auth.login(agent, util.account.waitlistedHacker0, (error) => { if (error) { agent.close(); @@ -74,7 +93,7 @@ describe("GET team", function () { } return agent .get(`/api/team/${util.team.Team3._id}`) - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); @@ -152,13 +171,30 @@ describe("GET team", function () { }); }); -describe("POST create team", function () { - it("should FAIL to create a new team due to lack of authentication", function (done) { +describe("POST create team", function() { + async function storeAll() { + await util.roleBinding.storeAll(); + await util.role.storeAll(); + await util.team.storeAll(); + await util.account.storeTeamAccount(); + await util.hacker.storeAll(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); + it("should FAIL to create a new team due to lack of authentication", function(done) { chai.request(server.app) .post(`/api/team/`) .type("application/json") .send(util.team.newTeam1) - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(401); res.should.be.json; res.body.should.have.property("message"); @@ -169,7 +205,7 @@ describe("POST create team", function () { }); }); - it("should FAIL to create a new team due to lack of authorization", function (done) { + it("should FAIL to create a new team due to lack of authorization", function(done) { util.auth.login(agent, sponsorT1Account0, (error) => { if (error) { agent.close(); @@ -179,7 +215,7 @@ describe("POST create team", function () { .post(`/api/team/`) .type("application/json") .send(util.team.newTeam1) - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(403); res.should.be.json; res.body.should.have.property("message"); @@ -193,7 +229,7 @@ describe("POST create team", function () { }); }); - it("should FAIL to create a new team due to logged in user not being a hacker", function (done) { + it("should FAIL to create a new team due to logged in user not being a hacker", function(done) { util.auth.login(agent, Admin0, (error) => { if (error) { agent.close(); @@ -203,7 +239,7 @@ describe("POST create team", function () { .post(`/api/team/`) .type("application/json") .send(util.team.newTeam1) - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(404); res.should.be.json; res.body.should.have.property("message"); @@ -217,7 +253,7 @@ describe("POST create team", function () { }); }); - it("should FAIL to create a new team due to duplicate team name", function (done) { + it("should FAIL to create a new team due to duplicate team name", function(done) { util.auth.login(agent, noTeamHackerAccount0, (error) => { if (error) { agent.close(); @@ -227,7 +263,7 @@ describe("POST create team", function () { .post(`/api/team/`) .type("application/json") .send(util.team.duplicateTeamName1) - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(409); res.should.be.json; res.body.should.have.property("message"); @@ -244,7 +280,7 @@ describe("POST create team", function () { }); }); - it("should Fail to create a new team due to hacker already being in a team", function (done) { + it("should Fail to create a new team due to hacker already being in a team", function(done) { util.auth.login(agent, teamHackerAccount0, (error) => { if (error) { agent.close(); @@ -254,7 +290,7 @@ describe("POST create team", function () { .post(`/api/team/`) .type("application/json") .send(util.team.newTeam1) - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(409); res.should.be.json; res.body.should.have.property("message"); @@ -267,7 +303,7 @@ describe("POST create team", function () { }); }); - it("should SUCCEED and create a new team", function (done) { + it("should SUCCEED and create a new team", function(done) { util.auth.login(agent, noTeamHackerAccount0, (error) => { if (error) { agent.close(); @@ -277,7 +313,7 @@ describe("POST create team", function () { .post(`/api/team/`) .type("application/json") .send(util.team.newTeam1) - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); @@ -300,15 +336,32 @@ describe("POST create team", function () { }); }); -describe("PATCH join team", function () { - it("should FAIL to join a hacker to a team due to lack of authentication", function (done) { +describe("PATCH join team", function() { + async function storeAll() { + await util.roleBinding.storeAll(); + await util.role.storeAll(); + await util.team.storeAll(); + await util.hacker.storeAll(); + await util.account.storeOneOfEach(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); + it("should FAIL to join a hacker to a team due to lack of authentication", function(done) { chai.request(server.app) .patch(`/api/team/join/`) .type("application/json") .send({ name: "BronzeTeam" }) - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(401); res.should.be.json; res.body.should.have.property("message"); @@ -319,7 +372,7 @@ describe("PATCH join team", function () { }); }); - it("should FAIL to join a volunteer to a team.", function (done) { + it("should FAIL to join a volunteer to a team.", function(done) { util.auth.login( agent, util.account.volunteerAccounts.stored[0], @@ -334,7 +387,7 @@ describe("PATCH join team", function () { .send({ name: "BronzeTeam" }) - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(403); res.should.be.json; res.body.should.have.property("message"); @@ -349,7 +402,7 @@ describe("PATCH join team", function () { ); }); - it("should FAIL to join a hacker to a team that doesn't exist.", function (done) { + it("should FAIL to join a hacker to a team that doesn't exist.", function(done) { util.auth.login(agent, teamHackerAccount0, (error) => { if (error) { agent.close(); @@ -361,7 +414,7 @@ describe("PATCH join team", function () { .send({ name: "NonExistTeam" }) - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(404); res.should.be.json; res.body.should.have.property("message"); @@ -375,7 +428,7 @@ describe("PATCH join team", function () { }); }); - it("should FAIL to join a hacker to a team that is full.", function (done) { + it("should FAIL to join a hacker to a team that is full.", function(done) { util.auth.login(agent, teamHackerAccount0, (error) => { if (error) { agent.close(); @@ -387,7 +440,7 @@ describe("PATCH join team", function () { .send({ name: "FullTeam" }) - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(409); res.should.be.json; res.body.should.have.property("message"); @@ -401,7 +454,7 @@ describe("PATCH join team", function () { }); }); - it("should SUCCEED and join a hacker without a team to a team.", function (done) { + it("should SUCCEED and join a hacker without a team to a team.", function(done) { util.auth.login(agent, noTeamHackerAccount0, (error) => { if (error) { agent.close(); @@ -413,7 +466,7 @@ describe("PATCH join team", function () { .send({ name: "BronzeTeam" }) - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); @@ -425,7 +478,7 @@ describe("PATCH join team", function () { }); }); - it("should SUCCEED and join a hacker on a team to aother team.", function (done) { + it("should SUCCEED and join a hacker on a team to aother team.", function(done) { util.auth.login(agent, teamHackerAccount0, (error) => { if (error) { agent.close(); @@ -437,7 +490,7 @@ describe("PATCH join team", function () { .send({ name: "SilverTeam" }) - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); @@ -450,15 +503,32 @@ describe("PATCH join team", function () { }); }); -describe("PATCH change team info", function () { - it("should FAIL to change a hacker's team information due to invalid authentication", function (done) { +describe("PATCH change team info", function() { + async function storeAll() { + await util.roleBinding.storeAll(); + await util.role.storeAll(); + await util.team.storeAll(); + await util.account.storeTeamAccount(); + await util.hacker.storeAll(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); + it("should FAIL to change a hacker's team information due to invalid authentication", function(done) { chai.request(server.app) .patch(`/api/team/${util.hacker.TeamHacker4._id}`) .type("application/json") .send({ name: "BronzeTeamASDF" }) - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(401); res.should.be.json; res.body.should.have.property("message"); @@ -469,7 +539,7 @@ describe("PATCH change team info", function () { }); }); - it("should FAIL for a hacker to change another team's information due to invalid authorization", function (done) { + it("should FAIL for a hacker to change another team's information due to invalid authorization", function(done) { util.auth.login( agent, util.account.hackerAccounts.stored.team[1], @@ -484,7 +554,7 @@ describe("PATCH change team info", function () { .send({ name: "SuccessTeamASDF" }) - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(403); res.should.be.json; res.body.should.have.property("message"); @@ -499,7 +569,7 @@ describe("PATCH change team info", function () { ); }); - it("should SUCCEED to change the hacker's team information", function (done) { + it("should SUCCEED to change the hacker's team information", function(done) { util.auth.login( agent, util.account.hackerAccounts.stored.team[1], @@ -514,7 +584,7 @@ describe("PATCH change team info", function () { .send({ name: "SuccessTeamASDF" }) - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); @@ -530,7 +600,7 @@ describe("PATCH change team info", function () { ); }); - it("should SUCCEED and leave a team.", function (done) { + it("should SUCCEED and leave a team.", function(done) { util.auth.login(agent, teamHackerAccount0, (error) => { if (error) { agent.close(); @@ -539,7 +609,7 @@ describe("PATCH change team info", function () { return agent .patch(`/api/team/leave/`) .type("application/json") - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); @@ -552,7 +622,7 @@ describe("PATCH change team info", function () { }); }); - it("should SUCCEED for an admin to change a team information", function (done) { + it("should SUCCEED for an admin to change a team information", function(done) { util.auth.login(agent, Admin0, (error) => { if (error) { agent.close(); @@ -564,7 +634,7 @@ describe("PATCH change team info", function () { .send({ name: "SuccessTeamASDF" }) - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); @@ -580,11 +650,11 @@ describe("PATCH change team info", function () { }); }); - it("should FAIL to leave a team due to invalid authentication.", function (done) { + it("should FAIL to leave a team due to invalid authentication.", function(done) { chai.request(server.app) .patch(`/api/team/leave/`) .type("application/json") - .end(function (err, res) { + .end(function(err, res) { res.should.have.status(401); res.should.be.json; res.body.should.have.property("message"); diff --git a/tests/util/account.test.util.js b/tests/util/account.test.util.js index 7e5049bd..cc0140fb 100644 --- a/tests/util/account.test.util.js +++ b/tests/util/account.test.util.js @@ -346,14 +346,17 @@ module.exports = { extraAccounts: extraAccounts, storeAll: storeAll, - storeStaffAccounts: storeStaffAccounts, storeHackerStaffAccounts: storeHackerStaffAccounts, storeVerifyConfirmationAccounts: storeVerifyConfirmationAccounts, - storePostInviteAccount: storePostInviteAccount, + storeStaffUnlinkedAccount: storeStaffUnlinkedAccount, storeGetInviteAccounts: storeGetInviteAccounts, storeExtraAccounts: storeExtraAccounts, - storePatchUpdateAccount: storePatchUpdateAccount, - storePostResetPasswordAccounts: storePostResetPasswordAccounts, + storeHackerStaffExtraAccount: storeHackerStaffExtraAccount, + storeStoredTeamAccounts: storeStoredTeamAccounts, + storeSponsorAccount: storeSponsorAccount, + storeTeamAccount: storeTeamAccount, + storeStaffNoTeamTeamUnconfirmedInvalid: storeStaffNoTeamTeamUnconfirmedInvalid, + storeOneOfEach: storeOneOfEach, dropAll: dropAll, equals: equals }; @@ -376,15 +379,18 @@ function store(attributes) { return Account.collection.insertMany(acctDocs); } -async function storePostResetPasswordAccounts() { +async function storeStoredTeamAccounts() { await store(hackerAccounts.stored.team); } -async function storeStaffAccounts() { +async function storeStaffNoTeamTeamUnconfirmedInvalid() { await store(hackerAccounts.stored.team); await store(hackerAccounts.stored.noTeam); await store(hackerAccounts.stored.unconfirmed); await store(staffAccounts.stored); + await store(unlinkedAccounts.stored); + await store(hackerAccounts.new); + await store(extraAccounts); } async function storeGetInviteAccounts() { @@ -392,7 +398,24 @@ async function storeGetInviteAccounts() { await store(staffAccounts.stored); } -async function storePatchUpdateAccount() { +async function storeTeamAccount() { + await store(hackerAccounts.stored.noTeam); + await store(hackerAccounts.stored.team); + await store(staffAccounts.stored); + await store(sponsorT1Accounts.stored); +} + +async function storeSponsorAccount() { + await store(hackerAccounts.stored.team); + await store(staffAccounts.stored); + await store(sponsorT1Accounts.stored); + await store(sponsorT2Accounts.stored); + await store(sponsorT1Accounts.new); + await store(sponsorT2Accounts.new); +} + +async function storeHackerStaffExtraAccount() { + await store(hackerAccounts.stored.noTeam); await store(hackerAccounts.stored.team); await store(staffAccounts.stored); await store(extraAccounts); @@ -413,9 +436,21 @@ async function storeVerifyConfirmationAccounts() { await store(extraAccounts); } -async function storePostInviteAccount() { +async function storeStaffUnlinkedAccount() { + await store(staffAccounts.stored); + await store(unlinkedAccounts.stored); +} + +async function storeOneOfEach() { + await store(hackerAccounts.stored.team); + await store(hackerAccounts.stored.noTeam); + await store(hackerAccounts.stored.unconfirmed); + await store(volunteerAccounts.stored); await store(staffAccounts.stored); await store(unlinkedAccounts.stored); + await store(hackerAccounts.new); + await store(volunteerAccounts.new); + await store(extraAccounts); } async function storeAll() { diff --git a/tests/volunteer.test.js b/tests/volunteer.test.js index df42dbbc..7a700417 100644 --- a/tests/volunteer.test.js +++ b/tests/volunteer.test.js @@ -14,7 +14,9 @@ const Constants = { const util = { volunteer: require("./util/volunteer.test.util"), account: require("./util/account.test.util"), - auth: require("./util/auth.test.util") + auth: require("./util/auth.test.util"), + role: require("./util/role.test.util"), + roleBinding: require("./util/roleBinding.test.util") }; const Admin0 = util.account.staffAccounts.stored[0]; @@ -30,6 +32,22 @@ const duplicateVolunteer = util.volunteer.duplicateVolunteer1; const invalidVolunteer0 = util.volunteer.invalidVolunteer0; describe("GET volunteer", function() { + async function storeAll() { + await util.roleBinding.storeAll(); + await util.role.storeAll(); + await util.volunteer.storeAll(); + await util.account.storeOneOfEach(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("should FAIL to get volunteer due to lack of authentication", function(done) { chai.request(server.app) .get(`/api/volunteer/${Volunteer0._id}`) @@ -152,6 +170,22 @@ describe("GET volunteer", function() { }); describe("POST create volunteer", function() { + async function storeAll() { + await util.roleBinding.storeAll(); + await util.role.storeAll(); + await util.volunteer.storeAll(); + await util.account.storeOneOfEach(); + } + beforeEach(function(done) { + this.timeout(60000); + storeAll() + .then(() => { + done(); + }) + .catch((error) => { + done(error); + }); + }); it("should FAIL to create a new volunteer due to lack of authentication", function(done) { chai.request(server.app) .post(`/api/volunteer`)