Skip to content

Commit 71a616a

Browse files
committed
Fix errors that interpreter points out, add roleBindings
1 parent 9537c86 commit 71a616a

12 files changed

+209
-120
lines changed

tests/account.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const confirmationToken = util.accountConfirmation.ConfirmationToken;
2525
const fakeToken = util.accountConfirmation.FakeToken;
2626
const resetToken = util.reset.ResetToken;
2727
// accounts
28-
const Admin0 = util.account.staffAccounts[0];
28+
const Admin0 = util.account.staffAccounts.stored[0];
2929
const teamHackerAccount0 = util.account.hackerAccounts.stored.team[0];
3030

3131

tests/hacker.test.js

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,29 @@ const util = {
2323
const StorageService = require("../services/storage.service");
2424

2525
const Admin0 = util.account.staffAccounts.stored[0];
26-
const teamHackerAccount0 = util.account.hackerAccounts.stored.team[0];
27-
// linked with hackerB - fix later
28-
const noTeamHackerAccount0 = util.account.hackerAccounts.stored.noTeam[0];
29-
const volunteerAccount0 = util.account.volunteerAccounts.stored[0];
3026

31-
// storedAccount1 and storedHacker1 are linked together, and have hacker priviledges
32-
// newHackerDuplicateAccountLink1 is also linked with Account1
33-
// storedHacker1 has status confirmed
34-
const storedHacker1 = util.hacker.HackerA;
35-
const newHackerDuplicateAccountLink1 = util.hacker.duplicateAccountLinkHacker1;
27+
const volunteerAccount0 = util.account.volunteerAccounts.stored[0];
3628

37-
const storedHacker2 = util.hacker.HackerB;
29+
const newHackerAccount0 = util.account.hackerAccounts.new[0];
30+
const newHacker0 = util.hacker.newHacker0;
31+
const invalidHacker0 = util.hacker.invalidHacker0;
3832

3933
const newHacker1 = util.hacker.newHacker1;
40-
// badConductHacker1 is the same as newHacker1, even linking to the same account
41-
// the difference is that badConductHacker1 does not accept the code of conducts
42-
const badConductHacker1 = util.hacker.badCodeOfConductHacker1;
43-
const newHackerAccount1 = util.account.allAccounts[13];
4434

45-
const newHacker2 = util.hacker.newHacker2;
35+
const noTeamHackerAccount0 = util.account.hackerAccounts.stored.noTeam[0];
36+
const noTeamHacker0 = util.hacker.NoTeamHacker0;
37+
38+
const teamHackerAccount0 = util.account.hackerAccounts.stored.team[0];
39+
const TeamHacker0 = util.hacker.TeamHacker0;
40+
const duplicateAccountLinkHacker0 = util.hacker.duplicateAccountLinkHacker0;
41+
4642
const invalidHacker1 = util.hacker.invalidHacker1;
4743

4844
describe("GET hacker", function () {
4945
// fail on authentication
5046
it("should fail to list a hacker's information on /api/hacker/:id GET due to authentication", function (done) {
5147
chai.request(server.app)
52-
.get(`/api/hacker/` + storedHacker1._id)
48+
.get(`/api/hacker/` + TeamHacker0._id)
5349
.end(function (err, res) {
5450
res.should.have.status(401);
5551
res.should.be.json;
@@ -78,7 +74,7 @@ describe("GET hacker", function () {
7874
res.body.message.should.equal(Constants.Success.HACKER_READ);
7975
res.body.should.have.property("data");
8076

81-
let hacker = new Hacker(storedHacker1);
77+
let hacker = new Hacker(TeamHacker0);
8278
chai.assert.equal(JSON.stringify(res.body.data), JSON.stringify(hacker.toJSON()));
8379
done();
8480
});
@@ -112,7 +108,7 @@ describe("GET hacker", function () {
112108
return done(error);
113109
}
114110
return agent
115-
.get(`/api/hacker/${storedHacker1._id}`)
111+
.get(`/api/hacker/${TeamHacker0._id}`)
116112
// does not have password because of to stripped json
117113
.end(function (err, res) {
118114
if (err) {
@@ -124,7 +120,7 @@ describe("GET hacker", function () {
124120
res.body.message.should.equal(Constants.Success.HACKER_READ);
125121
res.body.should.have.property("data");
126122

127-
let hacker = new Hacker(storedHacker1);
123+
let hacker = new Hacker(TeamHacker0);
128124
chai.assert.equal(JSON.stringify(res.body.data), JSON.stringify(hacker.toJSON()));
129125

130126
done();
@@ -140,7 +136,7 @@ describe("GET hacker", function () {
140136
return done(error);
141137
}
142138
return agent
143-
.get(`/api/hacker/${storedHacker1._id}`)
139+
.get(`/api/hacker/${TeamHacker0._id}`)
144140
// does not have password because of to stripped json
145141
.end(function (err, res) {
146142
if (err) {
@@ -152,7 +148,7 @@ describe("GET hacker", function () {
152148
res.body.message.should.equal(Constants.Success.HACKER_READ);
153149
res.body.should.have.property("data");
154150

155-
let hacker = new Hacker(storedHacker1);
151+
let hacker = new Hacker(TeamHacker0);
156152

157153
chai.assert.equal(JSON.stringify(res.body.data), JSON.stringify(hacker.toJSON()));
158154

@@ -169,7 +165,7 @@ describe("GET hacker", function () {
169165
return done(error);
170166
}
171167
return agent
172-
.get(`/api/hacker/${storedHacker1._id}`)
168+
.get(`/api/hacker/${TeamHacker0._id}`)
173169
// does not have password because of to stripped json
174170
.end(function (err, res) {
175171
if (err) {
@@ -239,7 +235,7 @@ describe("POST create hacker", function () {
239235
return agent
240236
.post(`/api/hacker/`)
241237
.type("application/json")
242-
.send(newHacker1)
238+
.send(newHacker0)
243239
.end(function (err, res) {
244240
res.should.have.status(200);
245241
res.should.be.json;
@@ -250,7 +246,7 @@ describe("POST create hacker", function () {
250246
// create JSON version of model
251247
// delete id as they will be different between model objects
252248
// update status to be applied on the comparator hacker object
253-
const hacker = (new Hacker(newHacker1)).toJSON();
249+
const hacker = (new Hacker(newHacker0)).toJSON();
254250
hacker.status = Constants.General.HACKER_STATUS_APPLIED;
255251
delete res.body.data.id;
256252
delete hacker.id;
@@ -263,7 +259,7 @@ describe("POST create hacker", function () {
263259

264260
// succeed on user case
265261
it("should SUCCEED and create a new hacker for user (with an account that has been confirmed)", function (done) {
266-
util.auth.login(agent, newHackerAccount1, (error) => {
262+
util.auth.login(agent, newHackerAccount0, (error) => {
267263
if (error) {
268264
agent.close();
269265
return done(error);
@@ -282,7 +278,7 @@ describe("POST create hacker", function () {
282278
// create JSON version of model
283279
// delete id as they will be different between model objects
284280
// update status to be applied on the comparator hacker object
285-
const hacker = (new Hacker(newHacker1)).toJSON();
281+
const hacker = (new Hacker(newHacker0)).toJSON();
286282
hacker.status = Constants.General.HACKER_STATUS_APPLIED;
287283
delete res.body.data.id;
288284
delete hacker.id;
@@ -294,15 +290,15 @@ describe("POST create hacker", function () {
294290

295291
// should fail due to 'false' on code of conduct
296292
it("should FAIL if the new hacker does not accept code of conduct", function (done) {
297-
util.auth.login(agent, newHackerAccount1, (error) => {
293+
util.auth.login(agent, newHacker0, (error) => {
298294
if (error) {
299295
agent.close();
300296
return done(error);
301297
}
302298
return agent
303299
.post(`/api/hacker/`)
304300
.type("application/json")
305-
.send(badConductHacker1)
301+
.send(invalidHacker0)
306302
.end(function (err, res) {
307303
res.should.have.status(422);
308304
res.should.be.json;
@@ -326,7 +322,7 @@ describe("POST create hacker", function () {
326322
return agent
327323
.post(`/api/hacker/`)
328324
.type("application/json")
329-
.send(newHacker2)
325+
.send(util.hacker.unconfirmedAccountHacker0)
330326
.end(function (err, res) {
331327
res.should.be.json;
332328
res.body.should.have.property("message");
@@ -347,7 +343,7 @@ describe("POST create hacker", function () {
347343
return agent
348344
.post(`/api/hacker/`)
349345
.type("application/json")
350-
.send(newHackerDuplicateAccountLink1)
346+
.send(duplicateAccountLinkHacker0)
351347
.end(function (err, res) {
352348
res.should.have.status(409);
353349
res.body.should.have.property("message");
@@ -382,7 +378,7 @@ describe("PATCH update one hacker", function () {
382378
// fail on authentication
383379
it("should fail to update a hacker on /api/hacker/:id GET due to authentication", function (done) {
384380
chai.request(server.app)
385-
.patch(`/api/hacker/${storedHacker1._id}`)
381+
.patch(`/api/hacker/${TeamHacker0._id}`)
386382
.type("application/json")
387383
.send({
388384
gender: "Other"
@@ -404,7 +400,7 @@ describe("PATCH update one hacker", function () {
404400
return done(error);
405401
}
406402
return agent
407-
.patch(`/api/hacker/${storedHacker1._id}`)
403+
.patch(`/api/hacker/${TeamHacker0._id}`)
408404
.type("application/json")
409405
.send({
410406
gender: "Other"
@@ -430,7 +426,7 @@ describe("PATCH update one hacker", function () {
430426
return done(error);
431427
}
432428
return agent
433-
.patch(`/api/hacker/status/${storedHacker1._id}`)
429+
.patch(`/api/hacker/status/${TeamHacker0._id}`)
434430
.type("application/json")
435431
.send({
436432
status: "Accepted"
@@ -456,7 +452,7 @@ describe("PATCH update one hacker", function () {
456452
return done(error);
457453
}
458454
return agent
459-
.patch(`/api/hacker/status/${storedHacker1._id}`)
455+
.patch(`/api/hacker/status/${TeamHacker0._id}`)
460456
.type("application/json")
461457
.send({
462458
status: "Accepted"
@@ -480,7 +476,7 @@ describe("PATCH update one hacker", function () {
480476
return done(error);
481477
}
482478
return agent
483-
.patch(`/api/hacker/checkin/${storedHacker1._id}`)
479+
.patch(`/api/hacker/checkin/${TeamHacker0._id}`)
484480
.type("application/json")
485481
.send({
486482
status: "Checked-in"
@@ -507,7 +503,7 @@ describe("PATCH update one hacker", function () {
507503
return done(error);
508504
}
509505
return agent
510-
.patch(`/api/hacker/checkin/${storedHacker1._id}`)
506+
.patch(`/api/hacker/checkin/${TeamHacker0._id}`)
511507
.type("application/json")
512508
.send({
513509
status: "Checked-in"
@@ -531,7 +527,7 @@ describe("PATCH update one hacker", function () {
531527
return done(error);
532528
}
533529
return agent
534-
.patch(`/api/hacker/${storedHacker2._id}`)
530+
.patch(`/api/hacker/${noTeamHacker0._id}`)
535531
.type("application/json")
536532
.send({
537533
gender: "Other"
@@ -558,7 +554,7 @@ describe("PATCH update one hacker", function () {
558554
return done(error);
559555
}
560556
return agent
561-
.patch(`/api/hacker/${storedHacker1._id}`)
557+
.patch(`/api/hacker/${noTeamHacker0._id}`)
562558
.type("application/json")
563559
.send({
564560
gender: "Other"
@@ -607,7 +603,7 @@ describe("PATCH update one hacker", function () {
607603
return done(error);
608604
}
609605
return agent
610-
.patch(`/api/hacker/confirmation/${storedHacker2._id}`)
606+
.patch(`/api/hacker/confirmation/${noTeamHacker0._id}`)
611607
.type("application/json")
612608
.send({
613609
confirm: true
@@ -638,7 +634,7 @@ describe("PATCH update one hacker", function () {
638634
return done(error);
639635
}
640636
return agent
641-
.patch(`/api/hacker/confirmation/${storedHacker1._id}`)
637+
.patch(`/api/hacker/confirmation/${noTeamHacker0._id}`)
642638
.type("application/json")
643639
.send({
644640
confirm: false
@@ -697,7 +693,7 @@ describe("PATCH update one hacker", function () {
697693
return done(error);
698694
}
699695
return agent
700-
.patch(`/api/hacker/confirmation/${storedHacker1._id}`)
696+
.patch(`/api/hacker/confirmation/${noTeamHacker0._id}`)
701697
.type("application/json")
702698
.send({
703699
confirm: true
@@ -720,12 +716,12 @@ describe("PATCH update one hacker", function () {
720716
describe("POST add a hacker resume", function () {
721717
it("It should SUCCEED and upload a resume for a hacker", function (done) {
722718
//this takes a lot of time for some reason
723-
util.auth.login(agent, storedHacker1, (error) => {
719+
util.auth.login(agent, noTeamHacker0, (error) => {
724720
if (error) {
725721
return done(error);
726722
}
727723
return agent
728-
.post(`/api/hacker/resume/${storedHacker1._id}`)
724+
.post(`/api/hacker/resume/${noTeamHacker0._id}`)
729725
.type("multipart/form-data")
730726
.attach("resume", fs.createReadStream(path.join(__dirname, "testResume.pdf")), {
731727
contentType: "application/pdf"

tests/setup.spec.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,19 @@ afterEach(function (done) {
5353
});
5454
});
5555
async function storeAll() {
56-
await Util.Account.storeAll(Util.Account.allAccounts);
56+
await Util.Account.storeAll(Util.Account.hackerAccounts.stored.team);
57+
await Util.Account.storeAll(Util.Account.hackerAccounts.stored.noTeam);
58+
await Util.Account.storeAll(Util.Account.volunteerAccounts.stored);
59+
await Util.Account.storeAll(Util.Account.staffAccounts.stored);
60+
await Util.Account.storeAll(Util.Account.sponsorT1Accounts.stored);
61+
await Util.Account.storeAll(Util.Account.sponsorT2Accounts.stored);
62+
await Util.Account.storeAll(Util.Account.sponsorT3Accounts.stored);
63+
await Util.Account.storeAll(Util.Account.sponsorT4Accounts.stored);
64+
await Util.Account.storeAll(Util.Account.sponsorT5Accounts.stored);
65+
await Util.Account.storeAll(Util.Account.unlinkedAccounts.stored);
66+
67+
await Util.Account.storeAll(Util.Account.extraAccounts);
68+
5769
await Util.Hacker.storeAll(Util.Hacker.Hackers);
5870
await Util.Sponsor.storeAll(Util.Sponsor.Sponsors);
5971
await Util.Team.storeAll(Util.Team.Teams);
@@ -63,7 +75,16 @@ async function storeAll() {
6375
await Util.Bus.storeAll(Util.Bus.Busses);
6476
await Util.Volunteer.storeAll(Util.Volunteer.Volunteers);
6577
await Util.Role.storeAll(Constants.Role.allRolesArray);
66-
await Util.RoleBinding.storeAll(Util.RoleBinding.RoleBindings);
78+
79+
await Util.RoleBinding.storeAll(Util.RoleBinding.TeamHackerRB);
80+
await Util.RoleBinding.storeAll(Util.RoleBinding.NoTeamHackerRB);
81+
await Util.RoleBinding.storeAll(Util.RoleBinding.VolunteerRB);
82+
await Util.RoleBinding.storeAll(Util.RoleBinding.StaffRB);
83+
await Util.RoleBinding.storeAll(Util.RoleBinding.SponsorT1RB);
84+
await Util.RoleBinding.storeAll(Util.RoleBinding.SponsorT2RB);
85+
await Util.RoleBinding.storeAll(Util.RoleBinding.SponsorT3RB);
86+
await Util.RoleBinding.storeAll(Util.RoleBinding.SponsorT4RB);
87+
await Util.RoleBinding.storeAll(Util.RoleBinding.SponsorT5RB);
6788
}
6889

6990
async function dropAll() {

tests/util/account.test.util.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function createAccount(acc = {}) {
8686
}
8787

8888
function createNAccounts(n, acc = {}) {
89-
let accounts = []
89+
let accounts = [];
9090
for (let i = 0; i < n; i++) {
9191
accounts.push(createAccount(acc));
9292
}
@@ -201,7 +201,6 @@ let unlinkedAccounts = {
201201
})]
202202
};
203203

204-
205204
const waitlistedHacker0 = {
206205
"_id": mongoose.Types.ObjectId(),
207206
"firstName": "abcd",
@@ -245,6 +244,13 @@ const NonConfirmedAccount2 = {
245244
"accountType": Constants.HACKER,
246245
};
247246

247+
const NonConfirmedAccount3 = createAccount({
248+
"confirmed": false,
249+
"accountType": Constants.HACKER
250+
});
251+
252+
const extraAccounts = [waitlistedHacker0, NonConfirmedAccount1, NonConfirmedAccount2, NonConfirmedAccount3];
253+
248254
module.exports = {
249255
hackerAccounts: hackerAccounts,
250256
volunteerAccounts: volunteerAccounts,
@@ -259,10 +265,13 @@ module.exports = {
259265
waitlistedHacker0: waitlistedHacker0,
260266
NonConfirmedAccount1: NonConfirmedAccount1,
261267
NonConfirmedAccount2: NonConfirmedAccount2,
268+
NonConfirmedAccount3: NonConfirmedAccount3,
269+
270+
extraAccounts: extraAccounts,
262271

263272
storeAll: storeAll,
264273
dropAll: dropAll,
265-
equals: equals
274+
equals: equals,
266275
};
267276

268277
function encryptPassword(user) {
@@ -312,5 +321,5 @@ function equals(acc1, acc2) {
312321
const email = (acc1.email === acc2.email);
313322
const dietaryRestrictions = (acc1.dietaryRestrictions.join(",") === acc2.dietaryRestrictions.join(","));
314323
const shirtSize = (acc1.shirtSize === acc2.shirtSize);
315-
return [id, firstName, lastName, email, dietaryRestrictions, shirtSize];
324+
return [id, firstName, lastName, email, dietaryRestrictions, shirtSize, pronoun];
316325
}

tests/util/bus.test.util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const Bus1 = {
1515
"addr2": "addr2-1"
1616
},
1717
"capacity": 10,
18-
"hackers": [Util.Hacker.HackerA._id]
18+
"hackers": [Util.Hacker.TeamHacker0._id]
1919
};
2020
const Busses = [
2121
Bus1,

0 commit comments

Comments
 (0)