Skip to content

Commit f74f6c3

Browse files
committed
fix account tests
1 parent 71a616a commit f74f6c3

File tree

5 files changed

+23
-20
lines changed

5 files changed

+23
-20
lines changed

constants/general.constant.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,5 @@ module.exports = {
141141
CACHE_TIMEOUT_STATS: CACHE_TIMEOUT_STATS,
142142
CACHE_KEY_STATS: CACHE_KEY_STATS,
143143
MAX_TEAM_SIZE: MAX_TEAM_SIZE,
144-
SAMPLE_DIET_RESTRICTIONS,
144+
SAMPLE_DIET_RESTRICTIONS: SAMPLE_DIET_RESTRICTIONS,
145145
};

tests/account.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ const resetToken = util.reset.ResetToken;
2828
const Admin0 = util.account.staffAccounts.stored[0];
2929
const teamHackerAccount0 = util.account.hackerAccounts.stored.team[0];
3030

31-
32-
33-
3431
//This account has a confirmation token in the db
35-
const storedAccount2 = util.account.NonConfirmedAccount1;
32+
const storedAccount1 = util.account.NonConfirmedAccount1;
33+
const storedAccount2 = util.account.NonConfirmedAccount2;
34+
3635
//This account does not have a confirmation token in the DB
37-
const storedAccount3 = util.account.NonConfirmedAccount2;
36+
const storedAccount3 = util.account.NonConfirmedAccount3;
37+
3838
// admin role binding
3939

4040
const newAccount0 = util.account.unlinkedAccounts.new[0];
@@ -183,15 +183,15 @@ describe("POST create account", function () {
183183
chai.request(server.app)
184184
.post(`/api/account/`)
185185
.type("application/json")
186-
.send(teamHackerAccount0)
186+
.send(newAccount0)
187187
.end(function (err, res) {
188188
res.should.have.status(200);
189189
res.should.be.json;
190190
res.body.should.have.property("message");
191191
res.body.message.should.equal(Constants.Success.ACCOUNT_CREATE);
192192

193193
// use acc.toStrippedJSON to deal with hidden passwords and convert _id to id
194-
const acc = (new Account(teamHackerAccount0)).toStrippedJSON();
194+
const acc = (new Account(newAccount0)).toStrippedJSON();
195195
// delete id as those are generated
196196
delete acc.id;
197197
delete res.body.data.id;
@@ -470,7 +470,7 @@ describe("GET retrieve permissions", function () {
470470

471471
describe("GET resend confirmation email", function () {
472472
it("should SUCCEED and resend the confirmation email", function (done) {
473-
util.auth.login(agent, storedAccount3, (error) => {
473+
util.auth.login(agent, storedAccount1, (error) => {
474474
if (error) {
475475
agent.close();
476476
return done(error);
@@ -506,7 +506,7 @@ describe("GET resend confirmation email", function () {
506506
});
507507
});
508508
it("should FAIL as account confirmation token does not exist", function (done) {
509-
util.auth.login(agent, storedAccount2, (error) => {
509+
util.auth.login(agent, storedAccount3, (error) => {
510510
if (error) {
511511
agent.close();
512512
return done(error);

tests/util/account.test.util.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function generateRandomValue(atr) {
4848
case "password":
4949
return Math.random().toString(36).substr(0, 10);
5050
case "dietaryRestrictions":
51-
return Constants.SAMPLE_DIET_RESTRICTIONS[Math.floor(Math.random() * Constants.SAMPLE_DIET_RESTRICTIONS.length)];
51+
return [Constants.SAMPLE_DIET_RESTRICTIONS[Math.floor(Math.random() * Constants.SAMPLE_DIET_RESTRICTIONS.length)]];
5252
case "shirtSize":
5353
return Constants.SHIRT_SIZES[Math.floor(Math.random() * Constants.SHIRT_SIZES.length)];
5454
case "confirmed":
@@ -96,11 +96,12 @@ function createNAccounts(n, acc = {}) {
9696

9797
let hackerAccounts = {
9898
new: createNAccounts(10, {
99-
"accountType": Constants.HACKER
99+
"accountType": Constants.HACKER,
100100
}),
101101
stored: {
102102
team: createNAccounts(10, {
103-
"accountType": Constants.HACKER
103+
"accountType": Constants.HACKER,
104+
"confirmed": true,
104105
}),
105106
noTeam: createNAccounts(10, {
106107
"accountType": Constants.HACKER
@@ -131,7 +132,8 @@ let staffAccounts = {
131132

132133
let sponsorT1Accounts = {
133134
new: createNAccounts(5, {
134-
"accountType": Constants.SPONSOR_T1
135+
"accountType": Constants.SPONSOR_T1,
136+
"confirmed": false,
135137
}),
136138
stored: createNAccounts(5, {
137139
"accountType": Constants.SPONSOR_T1
@@ -206,7 +208,7 @@ const waitlistedHacker0 = {
206208
"firstName": "abcd",
207209
"lastName": "defg3",
208210
"pronoun": "They/Them",
209-
"email": "abc.def7@blahblah.com",
211+
"email": "waitlisted1@blahblah.com",
210212
"password": "probsShouldBeHashed2",
211213
"dietaryRestrictions": ["vegetarian"],
212214
"shirtSize": "M",
@@ -222,7 +224,7 @@ const NonConfirmedAccount1 = {
222224
"firstName": "LMAO",
223225
"lastName": "ROFL",
224226
"pronoun": "Ey/Em",
225-
"email": "abc.def6@blahblah.com",
227+
"email": "notconfirmed1@blahblah.com",
226228
"password": "probsShouldBeHashed5",
227229
"dietaryRestrictions": ["something1", "something2"],
228230
"shirtSize": "XXL",
@@ -246,7 +248,8 @@ const NonConfirmedAccount2 = {
246248

247249
const NonConfirmedAccount3 = createAccount({
248250
"confirmed": false,
249-
"accountType": Constants.HACKER
251+
"accountType": Constants.HACKER,
252+
"email": "notconfirmed3@blahblah.com"
250253
});
251254

252255
const extraAccounts = [waitlistedHacker0, NonConfirmedAccount1, NonConfirmedAccount2, NonConfirmedAccount3];

tests/util/accountConfirmation.test.util.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ const logger = require("../../services/logger.service");
1616

1717
const HackerConfirmation = {
1818
"_id": mongoose.Types.ObjectId(),
19-
"accountId": Util.Account.hackerAccounts.stored.noTeam[0],
19+
"accountId": Util.Account.NonConfirmedAccount1._id,
2020
"accountType": Constants.HACKER,
21-
"email": Util.Account.hackerAccounts.stored.noTeam[0].email
21+
"email": Util.Account.NonConfirmedAccount1.email
2222
};
2323

2424
const HackerConfirmation2 = {

tests/util/resetPassword.test.util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const logger = require("../../services/logger.service");
1414

1515
const ResetPasswordToken1 = {
1616
"_id": mongoose.Types.ObjectId(),
17-
"accountId": Util.Account.hackerAccounts.stored.team[0]
17+
"accountId": Util.Account.hackerAccounts.stored.team[0]._id
1818
};
1919

2020
const ResetToken = Services.resetPassword.generateToken(ResetPasswordToken1._id, ResetPasswordToken1.accountId);

0 commit comments

Comments
 (0)