Skip to content

Commit 3489ff3

Browse files
authored
Merge pull request #295 from hackmcgill/feature/287
Feature/287
2 parents c48d638 + 46de68f commit 3489ff3

21 files changed

+917
-786
lines changed

constants/general.constant.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ const HACKER_STATUSES = [
2424
HACKER_STATUS_CHECKED_IN
2525
];
2626

27+
const SAMPLE_DIET_RESTRICTIONS = [
28+
"None",
29+
"Vegan",
30+
"Vegetarian",
31+
"Keto",
32+
"Gluten free",
33+
"Pescetarian",
34+
"Peanut allergy",
35+
"Milk allergy",
36+
"Egg allergy",
37+
"Allergy",
38+
"No beef",
39+
"No porc",
40+
"No fish",
41+
"No shellfish"
42+
];
43+
2744
const HACKER = "Hacker";
2845
const VOLUNTEER = "Volunteer";
2946
const STAFF = "Staff";
@@ -123,5 +140,6 @@ module.exports = {
123140
POST_ROLES: POST_ROLES,
124141
CACHE_TIMEOUT_STATS: CACHE_TIMEOUT_STATS,
125142
CACHE_KEY_STATS: CACHE_KEY_STATS,
126-
MAX_TEAM_SIZE: MAX_TEAM_SIZE
143+
MAX_TEAM_SIZE: MAX_TEAM_SIZE,
144+
SAMPLE_DIET_RESTRICTIONS: SAMPLE_DIET_RESTRICTIONS,
127145
};

tests/account.test.js

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,26 @@ const util = {
1919
accountConfirmation: require("./util/accountConfirmation.test.util"),
2020
reset: require("./util/resetPassword.test.util")
2121
};
22-
// hacker role binding
23-
const storedAccount1 = util.account.Account1;
24-
//This account has a confirmation token in the db
25-
const storedAccount2 = util.account.NonConfirmedAccount1;
26-
//This account does not have a confirmation token in the DB
27-
const storedAccount3 = util.account.NonConfirmedAccount2;
28-
// admin role binding
29-
const Admin1 = util.account.Admin1;
30-
const newAccount1 = util.account.newAccount1;
3122
const agent = chai.request.agent(server.app);
23+
// tokens
3224
const confirmationToken = util.accountConfirmation.ConfirmationToken;
3325
const fakeToken = util.accountConfirmation.FakeToken;
3426
const resetToken = util.reset.ResetToken;
27+
// accounts
28+
const Admin0 = util.account.staffAccounts.stored[0];
29+
const teamHackerAccount0 = util.account.hackerAccounts.stored.team[0];
30+
31+
//This account has a confirmation token in the db
32+
const storedAccount1 = util.account.NonConfirmedAccount1;
33+
const storedAccount2 = util.account.NonConfirmedAccount2;
34+
35+
//This account does not have a confirmation token in the DB
36+
const storedAccount3 = util.account.NonConfirmedAccount3;
37+
38+
// admin role binding
39+
40+
const newAccount0 = util.account.unlinkedAccounts.new[0];
41+
3542

3643
describe("GET user account", function () {
3744
// fail on authentication
@@ -50,7 +57,7 @@ describe("GET user account", function () {
5057
// fail due to invalid login
5158
it("should fail due to invalid password", function (done) {
5259
agent.post("/api/auth/login").type("application/json").send({
53-
email: Admin1.email,
60+
email: Admin0.email,
5461
password: "FakePassword"
5562
}).end((err, res) => {
5663
res.should.have.status(401);
@@ -62,7 +69,7 @@ describe("GET user account", function () {
6269

6370
// success case
6471
it("should list the user's account on /api/account/self GET", function (done) {
65-
util.auth.login(agent, Admin1, (error) => {
72+
util.auth.login(agent, Admin0, (error) => {
6673
if (error) {
6774
agent.close();
6875
return done(error);
@@ -92,13 +99,13 @@ describe("GET user account", function () {
9299

93100
// success case - admin case
94101
it("should list another account specified by id using admin priviledge on /api/account/:id/ GET", function (done) {
95-
util.auth.login(agent, Admin1, (error) => {
102+
util.auth.login(agent, Admin0, (error) => {
96103
if (error) {
97104
agent.close();
98105
return done(error);
99106
}
100107
return agent
101-
.get(`/api/account/${storedAccount1._id}`)
108+
.get(`/api/account/${teamHackerAccount0._id}`)
102109
// does not have password because of to stripped json
103110
.end(function (err, res) {
104111
if (err) {
@@ -111,21 +118,21 @@ describe("GET user account", function () {
111118
res.body.should.have.property("data");
112119

113120
// use acc.toStrippedJSON to deal with hidden passwords and convert _id to id
114-
const acc = new Account(storedAccount1);
121+
const acc = new Account(teamHackerAccount0);
115122
chai.assert.equal(JSON.stringify(res.body.data), JSON.stringify(acc.toStrippedJSON()));
116123
done();
117124
});
118125
});
119126
});
120127
// success case - user case
121128
it("should list an account specified by id on /api/account/:id/ GET", function (done) {
122-
util.auth.login(agent, storedAccount1, (error) => {
129+
util.auth.login(agent, teamHackerAccount0, (error) => {
123130
if (error) {
124131
agent.close();
125132
return done(error);
126133
}
127134
return agent
128-
.get(`/api/account/${storedAccount1._id}`)
135+
.get(`/api/account/${teamHackerAccount0._id}`)
129136
// does not have password because of to stripped json
130137
.end(function (err, res) {
131138
if (err) {
@@ -138,7 +145,7 @@ describe("GET user account", function () {
138145
res.body.should.have.property("data");
139146

140147
// use acc.toStrippedJSON to deal with hidden passwords and convert _id to id
141-
const acc = new Account(storedAccount1);
148+
const acc = new Account(teamHackerAccount0);
142149
chai.assert.equal(JSON.stringify(res.body.data), JSON.stringify(acc.toStrippedJSON()));
143150
done();
144151
});
@@ -147,13 +154,13 @@ describe("GET user account", function () {
147154

148155
// // fail case on authorization
149156
it("should fail to list an account specified by id on /api/account/:id/ GET due to lack of authorization", function (done) {
150-
util.auth.login(agent, storedAccount1, (error) => {
157+
util.auth.login(agent, teamHackerAccount0, (error) => {
151158
if (error) {
152159
agent.close();
153160
return done(error);
154161
}
155162
return agent
156-
.get(`/api/account/${Admin1._id}`)
163+
.get(`/api/account/${Admin0._id}`)
157164
// does not have password because of to stripped json
158165
.end(function (err, res) {
159166
if (err) {
@@ -176,15 +183,15 @@ describe("POST create account", function () {
176183
chai.request(server.app)
177184
.post(`/api/account/`)
178185
.type("application/json")
179-
.send(newAccount1)
186+
.send(newAccount0)
180187
.end(function (err, res) {
181188
res.should.have.status(200);
182189
res.should.be.json;
183190
res.body.should.have.property("message");
184191
res.body.message.should.equal(Constants.Success.ACCOUNT_CREATE);
185192

186193
// use acc.toStrippedJSON to deal with hidden passwords and convert _id to id
187-
const acc = (new Account(newAccount1)).toStrippedJSON();
194+
const acc = (new Account(newAccount0)).toStrippedJSON();
188195
// delete id as those are generated
189196
delete acc.id;
190197
delete res.body.data.id;
@@ -197,7 +204,7 @@ describe("POST create account", function () {
197204
chai.request(server.app)
198205
.post(`/api/account/`)
199206
.type("application/json")
200-
.send(storedAccount1)
207+
.send(teamHackerAccount0)
201208
.end(function (err, res) {
202209
res.should.have.status(422);
203210
done();
@@ -243,13 +250,13 @@ describe("POST confirm account", function () {
243250

244251
describe("PATCH update account", function () {
245252
const updatedInfo = {
246-
"_id": storedAccount1._id,
253+
"_id": teamHackerAccount0._id,
247254
"firstName": "new",
248255
"lastName": "name"
249256
};
250257

251258
const failUpdatedInfo = {
252-
"_id": Admin1._id,
259+
"_id": Admin0._id,
253260
"firstName": "fail",
254261
"lastName": "fail"
255262
};
@@ -269,7 +276,7 @@ describe("PATCH update account", function () {
269276

270277
// succeed on :all case
271278
it("should SUCCEED and use admin to update another account", function (done) {
272-
util.auth.login(agent, Admin1, (error) => {
279+
util.auth.login(agent, Admin0, (error) => {
273280
if (error) {
274281
agent.close();
275282
return done(error);
@@ -294,7 +301,7 @@ describe("PATCH update account", function () {
294301

295302
// succeed on :self case
296303
it("should SUCCEED and update the user's own account", function (done) {
297-
util.auth.login(agent, storedAccount1, (error) => {
304+
util.auth.login(agent, teamHackerAccount0, (error) => {
298305
if (error) {
299306
agent.close();
300307
return done(error);
@@ -319,7 +326,7 @@ describe("PATCH update account", function () {
319326

320327
// fail due to lack of authorization
321328
it("should Fail to update an account due to lack of authorization", function (done) {
322-
util.auth.login(agent, storedAccount1, (error) => {
329+
util.auth.login(agent, teamHackerAccount0, (error) => {
323330
if (error) {
324331
agent.close();
325332
return done(error);
@@ -362,7 +369,7 @@ describe("POST reset password", function () {
362369

363370
describe("PATCH change password for logged in user", function () {
364371
const successChangePassword = {
365-
"oldPassword": Admin1.password,
372+
"oldPassword": Admin0.password,
366373
"newPassword": "password12345"
367374
};
368375
const failChangePassword = {
@@ -385,7 +392,7 @@ describe("PATCH change password for logged in user", function () {
385392
});
386393
// success case
387394
it("should change the logged in user's password to a new password", function (done) {
388-
util.auth.login(agent, Admin1, (error) => {
395+
util.auth.login(agent, Admin0, (error) => {
389396
if (error) {
390397
agent.close();
391398
return done(error);
@@ -405,7 +412,7 @@ describe("PATCH change password for logged in user", function () {
405412
});
406413
// fail case because old password in incorrect
407414
it("should fail to change the logged in user's password to a new password because old password is incorrect", function (done) {
408-
util.auth.login(agent, Admin1, (error) => {
415+
util.auth.login(agent, Admin0, (error) => {
409416
if (error) {
410417
agent.close();
411418
return done(error);
@@ -427,13 +434,13 @@ describe("PATCH change password for logged in user", function () {
427434

428435
describe("GET retrieve permissions", function () {
429436
it("should SUCCEED and retrieve the rolebindings for the user", function (done) {
430-
util.auth.login(agent, storedAccount1, (error) => {
437+
util.auth.login(agent, teamHackerAccount0, (error) => {
431438
if (error) {
432439
agent.close();
433440
return done(error);
434441
}
435442
agent
436-
.get("/api/auth/rolebindings/" + storedAccount1._id)
443+
.get("/api/auth/rolebindings/" + teamHackerAccount0._id)
437444
.type("application/json")
438445
.end(function (err, res) {
439446
res.should.have.status(200);
@@ -443,14 +450,14 @@ describe("GET retrieve permissions", function () {
443450
res.body.data.should.be.a("object");
444451
res.body.data.should.have.property("roles");
445452
res.body.data.should.have.property("accountId");
446-
res.body.data.accountId.should.equal(storedAccount1._id.toHexString());
453+
res.body.data.accountId.should.equal(teamHackerAccount0._id.toHexString());
447454
done();
448455
});
449456
});
450457
});
451458
it("should FAIL to retrieve the rolebindings as the account is not authenticated", function (done) {
452459
chai.request(server.app)
453-
.get("/api/auth/rolebindings/" + storedAccount1._id)
460+
.get("/api/auth/rolebindings/" + teamHackerAccount0._id)
454461
.type("application/json")
455462
.end(function (err, res) {
456463
res.should.have.status(401);
@@ -463,7 +470,7 @@ describe("GET retrieve permissions", function () {
463470

464471
describe("GET resend confirmation email", function () {
465472
it("should SUCCEED and resend the confirmation email", function (done) {
466-
util.auth.login(agent, storedAccount3, (error) => {
473+
util.auth.login(agent, storedAccount1, (error) => {
467474
if (error) {
468475
agent.close();
469476
return done(error);
@@ -481,7 +488,7 @@ describe("GET resend confirmation email", function () {
481488
});
482489
});
483490
it("should FAIL as the account is already confirmed", function (done) {
484-
util.auth.login(agent, storedAccount1, (error) => {
491+
util.auth.login(agent, teamHackerAccount0, (error) => {
485492
if (error) {
486493
agent.close();
487494
return done(error);
@@ -499,7 +506,7 @@ describe("GET resend confirmation email", function () {
499506
});
500507
});
501508
it("should FAIL as account confirmation token does not exist", function (done) {
502-
util.auth.login(agent, storedAccount2, (error) => {
509+
util.auth.login(agent, storedAccount3, (error) => {
503510
if (error) {
504511
agent.close();
505512
return done(error);
@@ -520,7 +527,7 @@ describe("GET resend confirmation email", function () {
520527

521528
describe("POST invite account", function () {
522529
it("Should succeed to invite a user to create an account", function (done) {
523-
util.auth.login(agent, Admin1, (error) => {
530+
util.auth.login(agent, Admin0, (error) => {
524531
if (error) {
525532
agent.close();
526533
return done(error);
@@ -529,7 +536,7 @@ describe("POST invite account", function () {
529536
.post("/api/account/invite")
530537
.type("application/json")
531538
.send({
532-
email: newAccount1.email,
539+
email: newAccount0.email,
533540
accountType: Constants.General.VOLUNTEER
534541
})
535542
// does not have password because of to stripped json
@@ -558,7 +565,7 @@ describe("GET invites", function () {
558565
});
559566
});
560567
it("Should FAIL to get all invites due to Authorization", function (done) {
561-
util.auth.login(agent, storedAccount1, (error) => {
568+
util.auth.login(agent, teamHackerAccount0, (error) => {
562569
if (error) {
563570
agent.close();
564571
return done(error);
@@ -574,7 +581,7 @@ describe("GET invites", function () {
574581
});
575582
});
576583
it("Should SUCCEED to get all invites", function (done) {
577-
util.auth.login(agent, Admin1, (error) => {
584+
util.auth.login(agent, Admin0, (error) => {
578585
if (error) {
579586
agent.close();
580587
return done(error);

tests/auth.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ const constants = {
2424
const roles = require("../constants/role.constant");
2525

2626
// hacker role binding
27-
const storedAccount1 = util.account.Account1;
27+
const teamHackerAccount0 = util.account.hackerAccounts.stored.team[0];
2828

2929
describe("GET roles", function () {
3030
it("should list all roles GET", function (done) {
31-
util.auth.login(agent, storedAccount1, (error) => {
31+
util.auth.login(agent, teamHackerAccount0, (error) => {
3232
if (error) {
3333
agent.close();
3434
return done(error);

0 commit comments

Comments
 (0)