Skip to content

Commit 9537c86

Browse files
committed
WIP account test refactor
1 parent e06498d commit 9537c86

13 files changed

+271
-483
lines changed

tests/account.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const storedAccount2 = util.account.NonConfirmedAccount1;
3737
const storedAccount3 = util.account.NonConfirmedAccount2;
3838
// admin role binding
3939

40-
const newAccount1 = util.account.newAccount1;
40+
const newAccount0 = util.account.unlinkedAccounts.new[0];
4141

4242

4343
describe("GET user account", function () {
@@ -536,7 +536,7 @@ describe("POST invite account", function () {
536536
.post("/api/account/invite")
537537
.type("application/json")
538538
.send({
539-
email: newAccount1.email,
539+
email: newAccount0.email,
540540
accountType: Constants.General.VOLUNTEER
541541
})
542542
// does not have password because of to stripped json

tests/hacker.test.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,18 @@ const util = {
2222
};
2323
const StorageService = require("../services/storage.service");
2424

25-
const Admin0 = util.account.Admin0;
25+
const Admin0 = util.account.staffAccounts.stored[0];
2626
const teamHackerAccount0 = util.account.hackerAccounts.stored.team[0];
27-
28-
29-
const Volunteer1 = util.account.Account4;
27+
// linked with hackerB - fix later
28+
const noTeamHackerAccount0 = util.account.hackerAccounts.stored.noTeam[0];
29+
const volunteerAccount0 = util.account.volunteerAccounts.stored[0];
3030

3131
// storedAccount1 and storedHacker1 are linked together, and have hacker priviledges
3232
// newHackerDuplicateAccountLink1 is also linked with Account1
3333
// storedHacker1 has status confirmed
3434
const storedHacker1 = util.hacker.HackerA;
3535
const newHackerDuplicateAccountLink1 = util.hacker.duplicateAccountLinkHacker1;
3636

37-
// storedAccount2 and storedHacker2 are linked together, and have hacker priviledges
38-
const storedAccount2 = util.account.Account2;
3937
const storedHacker2 = util.hacker.HackerB;
4038

4139
const newHacker1 = util.hacker.newHacker1;
@@ -165,7 +163,7 @@ describe("GET hacker", function () {
165163

166164
// fail due to lack of authorization
167165
it("should fail to list a hacker information due to lack of authorization on /api/hacker/:id GET", function (done) {
168-
util.auth.login(agent, storedAccount2, (error) => {
166+
util.auth.login(agent, noTeamHackerAccount0, (error) => {
169167
if (error) {
170168
agent.close();
171169
return done(error);
@@ -476,7 +474,7 @@ describe("PATCH update one hacker", function () {
476474

477475
// volunteer should successfully checkin hacker
478476
it("should SUCCEED and check in hacker as a volunteer", function (done) {
479-
util.auth.login(agent, Volunteer1, (error) => {
477+
util.auth.login(agent, volunteerAccount0, (error) => {
480478
if (error) {
481479
agent.close();
482480
return done(error);
@@ -527,7 +525,7 @@ describe("PATCH update one hacker", function () {
527525

528526
// should succeed on hacker case
529527
it("should SUCCEED and update the user's hacker info", function (done) {
530-
util.auth.login(agent, storedAccount2, (error) => {
528+
util.auth.login(agent, noTeamHackerAccount0, (error) => {
531529
if (error) {
532530
agent.close();
533531
return done(error);
@@ -554,7 +552,7 @@ describe("PATCH update one hacker", function () {
554552

555553
// should fail due to authorization
556554
it("should Fail to update hacker info due to lack of authorization", function (done) {
557-
util.auth.login(agent, storedAccount2, (error) => {
555+
util.auth.login(agent, noTeamHackerAccount0, (error) => {
558556
if (error) {
559557
agent.close();
560558
return done(error);
@@ -603,7 +601,7 @@ describe("PATCH update one hacker", function () {
603601

604602
// Succeed and change accepted to confirm
605603
it("should succeed for hacker to update their own status from accepted to confirmed", function (done) {
606-
util.auth.login(agent, storedAccount2, (error) => {
604+
util.auth.login(agent, noTeamHackerAccount0, (error) => {
607605
if (error) {
608606
agent.close();
609607
return done(error);
@@ -665,7 +663,7 @@ describe("PATCH update one hacker", function () {
665663

666664
// fail for a hacker that's not accepted
667665
it("should fail to update hacker status when hacker status is not accepted or confirmed", function (done) {
668-
util.auth.login(agent, util.account.Hacker3, (error) => {
666+
util.auth.login(agent, util.account.waitlistedHacker0, (error) => {
669667
if (error) {
670668
agent.close();
671669
return done(error);
@@ -693,7 +691,7 @@ describe("PATCH update one hacker", function () {
693691

694692
// fail for a hacker that's not accepted
695693
it("should fail for hacker trying to confirm someone else", function (done) {
696-
util.auth.login(agent, util.account.Hacker3, (error) => {
694+
util.auth.login(agent, util.account.waitlistedHacker0, (error) => {
697695
if (error) {
698696
agent.close();
699697
return done(error);

tests/search.service.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const badQuery = [{
4040

4141
const Admin0 = util.account.staffAccounts[0];
4242

43-
const HackerA = util.account.Account2;
43+
const noTeamHackerAccount0 = util.account.hackerAccounts.stored.noTeam[0];
4444

4545
describe("Searching for hackers", function () {
4646
it("Should FAIL to search due to invalid authentication", function (done) {
@@ -68,7 +68,7 @@ describe("Searching for hackers", function () {
6868
});
6969

7070
it("Should FAIL to search due to invalid authorization", function (done) {
71-
util.auth.login(agent, HackerA, (error) => {
71+
util.auth.login(agent, noTeamHackerAccount0, (error) => {
7272
if (error) {
7373
agent.close();
7474
return done(error);

tests/sponsor.test.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,19 @@ const util = {
2020

2121
const Admin0 = util.account.staffAccounts[0];
2222
const HackerAccount0 = util.account.hackerAccounts.stored.team[0];
23+
const T1SponsorAccount0 = util.account.sponsorT1Accounts.stored[0];
24+
const newT2SponsorAccount0 = util.account.sponsorT2Accounts.new[0];
25+
const T1Sponsor0 = util.sponsor.T1Sponsor0;
26+
const newT2Sponsor0 = util.sponsor.newT2Sponsor0;
2327

2428

25-
26-
// associated account
27-
let storedAccount = util.account.Account3;
28-
// configure sponsor data to be the same as output from query
29-
// stringify and parse for deep copy
30-
let storedSponsor = JSON.parse(JSON.stringify(util.sponsor.Sponsor1));
31-
storedSponsor.id = storedSponsor._id;
32-
delete storedSponsor._id;
33-
34-
let duplicateAccount = util.account.Account3;
3529
let duplicateSponsor = util.sponsor.duplicateAccountLinkSponsor1;
3630

37-
const newSponsor = util.sponsor.newSponsor1;
38-
const newSponsorAccount = util.account.Account5;
39-
4031

4132
describe("GET user sponsor", function () {
4233
it("should fail list a sponsor's information due to authentication from /api/sponsor/:id GET", function (done) {
4334
chai.request(server.app)
44-
.get(`/api/sponsor/` + util.sponsor.Sponsor1._id)
35+
.get(`/api/sponsor/` + T1Sponsor0._id)
4536
// does not have password because of to stripped json
4637
.end(function (err, res) {
4738
res.should.have.status(401);
@@ -61,7 +52,7 @@ describe("GET user sponsor", function () {
6152
return done(error);
6253
}
6354
return agent
64-
.get(`/api/sponsor/${util.sponsor.Sponsor1._id}`)
55+
.get(`/api/sponsor/${T1Sponsor0._id}`)
6556
.end(function (err, res) {
6657
if (err) {
6758
return done(err);
@@ -73,21 +64,21 @@ describe("GET user sponsor", function () {
7364
res.body.should.have.property("data");
7465
res.body.data.should.be.a("object");
7566

76-
chai.expect(res.body.data).to.deep.equal(storedSponsor);
67+
chai.expect(res.body.data).to.deep.equal(sponsorT1Account0);
7768
done();
7869
});
7970
});
8071
});
8172

8273
// regular user access success
8374
it("should succeed to list a user's sponsor info on /api/sponsor/:id GET", function (done) {
84-
util.auth.login(agent, storedAccount, (error) => {
75+
util.auth.login(agent, sponsorT1Account0, (error) => {
8576
if (error) {
8677
agent.close();
8778
return done(error);
8879
}
8980
return agent
90-
.get(`/api/sponsor/${util.sponsor.Sponsor1._id}`)
81+
.get(`/api/sponsor/${util.sponsor.T1Sponsor0._id}`)
9182
.end(function (err, res) {
9283
if (err) {
9384
return done(err);
@@ -99,7 +90,7 @@ describe("GET user sponsor", function () {
9990
res.body.should.have.property("data");
10091
res.body.data.should.be.a("object");
10192

102-
chai.expect(res.body.data).to.deep.equal(storedSponsor);
93+
chai.expect(res.body.data).to.deep.equal(T1SponsorAccount0);
10394
done();
10495
});
10596
});
@@ -200,7 +191,7 @@ describe("POST create sponsor", function () {
200191

201192
// fail case - duplicate accountId
202193
it("should fail to create a sponsor due to duplicate accountId", function (done) {
203-
util.auth.login(agent, duplicateAccount, (error) => {
194+
util.auth.login(agent, sponsorT1Account0, (error) => {
204195
if (error) {
205196
agent.close();
206197
return done(error);

tests/team.test.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ const Constants = {
2121
const agent = chai.request.agent(server.app);
2222

2323
const Admin0 = util.account.staffAccounts[0];
24-
const Hacker0 = util.account.hackerAccounts.stored.team[0];
24+
const teamHackerAccount0 = util.account.hackerAccounts.stored.team[0];
25+
const noTeamHackerAccount0 = util.account.hackerAccounts.stored.noTeam[0];
26+
const sponsorT1Account0 = util.account.sponsorT1Accounts.stored[0];
2527

2628
describe("GET team", function () {
2729
it("should FAIL to list a team's information due to lack of authentication", function (done) {
@@ -39,7 +41,7 @@ describe("GET team", function () {
3941
});
4042

4143
it("should Fail and list a team's information from /api/team/ GET due to non existant team id", function (done) {
42-
util.auth.login(agent, util.account.Hacker4, (error) => {
44+
util.auth.login(agent, util.account.hackerAccounts.stored.team[0], (error) => {
4345
if (error) {
4446
agent.close();
4547
return done(error);
@@ -59,7 +61,7 @@ describe("GET team", function () {
5961
});
6062

6163
it("should SUCCEED and list a team's information from /api/team/ GET", function (done) {
62-
util.auth.login(agent, util.account.Hacker3, (error) => {
64+
util.auth.login(agent, util.account.waitlistedHacker0, (error) => {
6365
if (error) {
6466
agent.close();
6567
return done(error);
@@ -108,7 +110,7 @@ describe("POST create team", function () {
108110
});
109111

110112
it("should FAIL to create a new team due to lack of authorization", function (done) {
111-
util.auth.login(agent, util.account.Account3, (error) => {
113+
util.auth.login(agent, sponsorT1Account0, (error) => {
112114
if (error) {
113115
agent.close();
114116
return done(error);
@@ -152,7 +154,7 @@ describe("POST create team", function () {
152154
});
153155

154156
it("should FAIL to create a new team due to duplicate team name", function (done) {
155-
util.auth.login(agent, util.account.Account2, (error) => {
157+
util.auth.login(agent, noTeamHackerAccount0, (error) => {
156158
if (error) {
157159
agent.close();
158160
return done(error);
@@ -175,7 +177,7 @@ describe("POST create team", function () {
175177
});
176178

177179
it("should Fail to create a new team due to hacker already being in a team", function (done) {
178-
util.auth.login(agent, Hacker0, (error) => {
180+
util.auth.login(agent, teamHackerAccount0, (error) => {
179181
if (error) {
180182
agent.close();
181183
return done(error);
@@ -196,7 +198,7 @@ describe("POST create team", function () {
196198
});
197199

198200
it("should SUCCEED and create a new team", function (done) {
199-
util.auth.login(agent, util.account.Account2, (error) => {
201+
util.auth.login(agent, noTeamHackerAccount0, (error) => {
200202
if (error) {
201203
agent.close();
202204
return done(error);
@@ -243,7 +245,7 @@ describe("PATCH join team", function () {
243245
});
244246

245247
it("should FAIL to join a volunteer to a team.", function (done) {
246-
util.auth.login(agent, util.account.Account5, (error) => {
248+
util.auth.login(agent, util.account.volunteerAccounts.stored[0], (error) => {
247249
if (error) {
248250
agent.close();
249251
return done(error);
@@ -267,7 +269,7 @@ describe("PATCH join team", function () {
267269
});
268270

269271
it("should FAIL to join a hacker to a team that doesn't exist.", function (done) {
270-
util.auth.login(agent, Hacker0, (error) => {
272+
util.auth.login(agent, teamHackerAccount0, (error) => {
271273
if (error) {
272274
agent.close();
273275
return done(error);
@@ -291,7 +293,7 @@ describe("PATCH join team", function () {
291293
});
292294

293295
it("should FAIL to join a hacker to a team that is full.", function (done) {
294-
util.auth.login(agent, Hacker0, (error) => {
296+
util.auth.login(agent, teamHackerAccount0, (error) => {
295297
if (error) {
296298
agent.close();
297299
return done(error);
@@ -315,7 +317,7 @@ describe("PATCH join team", function () {
315317
});
316318

317319
it("should SUCCEED and join a hacker without a team to a team.", function (done) {
318-
util.auth.login(agent, util.account.Account2, (error) => {
320+
util.auth.login(agent, noTeamHackerAccount0, (error) => {
319321
if (error) {
320322
agent.close();
321323
return done(error);
@@ -339,7 +341,7 @@ describe("PATCH join team", function () {
339341
});
340342

341343
it("should SUCCEED and join a hacker on a team to aother team.", function (done) {
342-
util.auth.login(agent, Hacker0, (error) => {
344+
util.auth.login(agent, teamHackerAccount0, (error) => {
343345
if (error) {
344346
agent.close();
345347
return done(error);
@@ -383,7 +385,7 @@ describe("PATCH change team info", function () {
383385
});
384386

385387
it("should FAIL for a hacker to change another team's information due to invalid authorization", function (done) {
386-
util.auth.login(agent, util.account.Hacker4, (error) => {
388+
util.auth.login(agent, util.account.hackerAccounts.stored.team[1], (error) => {
387389
if (error) {
388390
agent.close();
389391
return done(error);
@@ -406,8 +408,8 @@ describe("PATCH change team info", function () {
406408
});
407409
});
408410

409-
it("should SUCCEED to change the hacker's team information", function (done) {
410-
util.auth.login(agent, util.account.Hacker4, (error) => {
411+
it("should SUCCEED to change the hacker's team information (even though the hackers are different, the team is the same)", function (done) {
412+
util.auth.login(agent, util.account.hackerAccounts.stored.team[1], (error) => {
411413
if (error) {
412414
agent.close();
413415
return done(error);
@@ -432,7 +434,7 @@ describe("PATCH change team info", function () {
432434
});
433435

434436
it("should SUCCEED and leave a team.", function (done) {
435-
util.auth.login(agent, Hacker0, (error) => {
437+
util.auth.login(agent, teamHackerAccount0, (error) => {
436438
if (error) {
437439
agent.close();
438440
return done(error);

0 commit comments

Comments
 (0)