Skip to content

Commit 8da6b2a

Browse files
pengykjamesxu123
andauthored
Fix/691 Improved test suite (#697)
* fix: improved account tests * empty: trigger CI * empty: trigger github actions * fixed: added all improvements Co-authored-by: James Xu <36768789+jamesxu123@users.noreply.github.com>
1 parent 12f9fbe commit 8da6b2a

File tree

11 files changed

+692
-74
lines changed

11 files changed

+692
-74
lines changed

tests/account.test.js

Lines changed: 161 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ const util = {
1515
account: require("./util/account.test.util"),
1616
auth: require("./util/auth.test.util"),
1717
accountConfirmation: require("./util/accountConfirmation.test.util"),
18-
reset: require("./util/resetPassword.test.util")
18+
reset: require("./util/resetPassword.test.util"),
19+
role: require("./util/role.test.util"),
20+
roleBinding: require("./util/roleBinding.test.util"),
21+
accountConfirmation: require("./util/accountConfirmation.test.util"),
22+
resetPassword: require("./util/resetPassword.test.util.js")
1923
};
2024
const agent = chai.request.agent(server.app);
2125
// tokens
@@ -41,7 +45,21 @@ const newAccount0 = util.account.unlinkedAccounts.new[0];
4145
const noPhoneAccount = util.account.NoPhoneHackerAccount0;
4246

4347
describe("GET user account", function() {
44-
// fail on authentication
48+
async function storeAll() {
49+
await util.account.storeHackerStaffAccounts();
50+
await util.role.storeAll();
51+
await util.roleBinding.storeAll();
52+
}
53+
beforeEach(function(done) {
54+
this.timeout(60000);
55+
storeAll()
56+
.then(() => {
57+
done();
58+
})
59+
.catch((error) => {
60+
done(error);
61+
});
62+
});
4563
it("should FAIL to list the user's account on /api/account/self GET due to authentication", function(done) {
4664
chai.request(server.app)
4765
.get("/api/account/self")
@@ -207,6 +225,21 @@ describe("GET user account", function() {
207225
});
208226

209227
describe("POST create account", function() {
228+
async function storeAll() {
229+
await util.account.storeHackerStaffAccounts();
230+
await util.role.storeAll();
231+
await util.roleBinding.storeAll();
232+
}
233+
beforeEach(function(done) {
234+
this.timeout(60000);
235+
storeAll()
236+
.then(() => {
237+
done();
238+
})
239+
.catch((error) => {
240+
done(error);
241+
});
242+
});
210243
it("should SUCCEED and create a new account", function(done) {
211244
chai.request(server.app)
212245
.post(`/api/account/`)
@@ -230,7 +263,6 @@ describe("POST create account", function() {
230263
done();
231264
});
232265
});
233-
234266
it("should FAIL to create an account because the email is already in use", function(done) {
235267
chai.request(server.app)
236268
.post(`/api/account/`)
@@ -241,7 +273,6 @@ describe("POST create account", function() {
241273
done();
242274
});
243275
});
244-
245276
it("should SUCCEED and create a new account without a phone number", function(done) {
246277
chai.request(server.app)
247278
.post("/api/account")
@@ -269,6 +300,22 @@ describe("POST create account", function() {
269300
});
270301

271302
describe("POST confirm account", function() {
303+
async function storeAll() {
304+
await util.account.storeExtraAccounts();
305+
await util.accountConfirmation.storeAll();
306+
await util.role.storeAll();
307+
await util.roleBinding.storeAll();
308+
}
309+
beforeEach(function(done) {
310+
this.timeout(60000);
311+
storeAll()
312+
.then(() => {
313+
done();
314+
})
315+
.catch((error) => {
316+
done(error);
317+
});
318+
});
272319
it("should SUCCEED and confirm the account", function(done) {
273320
chai.request(server.app)
274321
.post(`/api/auth/confirm/${confirmationToken}`)
@@ -282,6 +329,7 @@ describe("POST confirm account", function() {
282329
done();
283330
});
284331
});
332+
285333
it("should FAIL confirming the account", function(done) {
286334
chai.request(server.app)
287335
.post(`/api/auth/confirm/${fakeToken}`)
@@ -295,6 +343,7 @@ describe("POST confirm account", function() {
295343
done();
296344
});
297345
});
346+
298347
it("should FAIL to confirm account that has token with email but no account", function(done) {
299348
chai.request(server.app)
300349
.post(`/api/auth/confirm/${fakeToken}`)
@@ -324,7 +373,22 @@ describe("PATCH update account", function() {
324373
lastName: "fail",
325374
email: storedAccount1.email
326375
};
327-
376+
async function storeAll() {
377+
await util.account.storeHackerStaffExtraAccount();
378+
await util.accountConfirmation.storeAll();
379+
await util.role.storeAll();
380+
await util.roleBinding.storeAll();
381+
}
382+
beforeEach(function(done) {
383+
this.timeout(60000);
384+
storeAll()
385+
.then(() => {
386+
done();
387+
})
388+
.catch((error) => {
389+
done(error);
390+
});
391+
});
328392
// fail on authentication
329393
it("should FAIL to update an account due to authentication", function(done) {
330394
chai.request(server.app)
@@ -446,6 +510,22 @@ describe("POST reset password", function() {
446510
const password = {
447511
password: "NewPassword"
448512
};
513+
async function storeAll() {
514+
await util.account.storeStoredTeamAccounts();
515+
await util.resetPassword.storeAll();
516+
await util.role.storeAll();
517+
await util.roleBinding.storeAll();
518+
}
519+
beforeEach(function(done) {
520+
this.timeout(60000);
521+
storeAll()
522+
.then(() => {
523+
done();
524+
})
525+
.catch((error) => {
526+
done(error);
527+
});
528+
});
449529
it("should SUCCEED and change the password", function(done) {
450530
chai.request(server.app)
451531
.post("/api/auth/password/reset")
@@ -472,6 +552,22 @@ describe("PATCH change password for logged in user", function() {
472552
oldPassword: "WrongPassword",
473553
newPassword: "password12345"
474554
};
555+
async function storeAll() {
556+
await util.account.storeGetInviteAccounts();
557+
await util.resetPassword.storeAll();
558+
await util.role.storeAll();
559+
await util.roleBinding.storeAll();
560+
}
561+
beforeEach(function(done) {
562+
this.timeout(60000);
563+
storeAll()
564+
.then(() => {
565+
done();
566+
})
567+
.catch((error) => {
568+
done(error);
569+
});
570+
});
475571
// fail on authentication
476572
it("should FAIL to change the user's password because they are not logged in", function(done) {
477573
chai.request(server.app)
@@ -533,6 +629,21 @@ describe("PATCH change password for logged in user", function() {
533629
});
534630

535631
describe("GET retrieve permissions", function() {
632+
async function storeAll() {
633+
await util.account.storeHackerStaffAccounts();
634+
await util.role.storeAll();
635+
await util.roleBinding.storeAll();
636+
}
637+
beforeEach(function(done) {
638+
this.timeout(60000);
639+
storeAll()
640+
.then(() => {
641+
done();
642+
})
643+
.catch((error) => {
644+
done(error);
645+
});
646+
});
536647
it("should SUCCEED and retrieve the rolebindings for the user", function(done) {
537648
util.auth.login(agent, teamHackerAccount0, (error) => {
538649
if (error) {
@@ -573,6 +684,20 @@ describe("GET retrieve permissions", function() {
573684
});
574685

575686
describe("GET resend confirmation email", function() {
687+
async function storeAll() {
688+
await util.account.storeVerifyConfirmationAccounts();
689+
await util.accountConfirmation.storeAll();
690+
}
691+
beforeEach(function(done) {
692+
this.timeout(60000);
693+
storeAll()
694+
.then(() => {
695+
done();
696+
})
697+
.catch((error) => {
698+
done(error);
699+
});
700+
});
576701
it("should SUCCEED and resend the confirmation email", function(done) {
577702
util.auth.login(agent, storedAccount1, (error) => {
578703
if (error) {
@@ -634,6 +759,21 @@ describe("GET resend confirmation email", function() {
634759
});
635760

636761
describe("POST invite account", function() {
762+
async function storeAll() {
763+
await util.account.storeStaffUnlinkedAccount();
764+
await util.role.storeAll();
765+
await util.roleBinding.storeAll();
766+
}
767+
beforeEach(function(done) {
768+
this.timeout(60000);
769+
storeAll()
770+
.then(() => {
771+
done();
772+
})
773+
.catch((error) => {
774+
done(error);
775+
});
776+
});
637777
it("Should succeed to invite a user to create an account", function(done) {
638778
util.auth.login(agent, Admin0, (error) => {
639779
if (error) {
@@ -666,6 +806,22 @@ describe("POST invite account", function() {
666806
});
667807

668808
describe("GET invites", function() {
809+
async function storeAll() {
810+
await util.account.storeGetInviteAccounts();
811+
await util.accountConfirmation.storeAll();
812+
await util.role.storeAll();
813+
await util.roleBinding.storeAll();
814+
}
815+
beforeEach(function(done) {
816+
this.timeout(60000);
817+
storeAll()
818+
.then(() => {
819+
done();
820+
})
821+
.catch((error) => {
822+
done(error);
823+
});
824+
});
669825
it("Should FAIL to get all invites due to Authentication", function(done) {
670826
chai.request(server.app)
671827
.get("/api/account/invite")

tests/auth.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ const roles = require("../constants/role.constant");
2727
const teamHackerAccount0 = util.account.hackerAccounts.stored.team[0];
2828

2929
describe("GET roles", function() {
30+
async function storeAll() {
31+
await util.role.storeAll();
32+
}
33+
beforeEach(function(done) {
34+
this.timeout(60000);
35+
storeAll()
36+
.then(() => {
37+
done();
38+
})
39+
.catch((error) => {
40+
done(error);
41+
});
42+
});
3043
it("should list all roles GET", function(done) {
3144
util.auth.login(agent, teamHackerAccount0, (error) => {
3245
if (error) {

0 commit comments

Comments
 (0)