Skip to content

Commit 20ef964

Browse files
brarsanmolpengyk
authored andcommitted
feat: implement attendance preference for hackers (#773)
* - Implement attendance preference for hackers. Questions: - Do we need to write unit tests for this? - Do we need to update/regenerate api docs to reflect the change in response data for the hacker model. * Fix spelling errors for accommodation in the codebase. - Drew JSON for testing from the api docs and was getting a validator error, on closer inspection, the spelling of acccommodation was incorrect in the docs, and in my own commit for hacker.validator.js. * feat: add unit testing for attendance preference. - unit test the following failures: - invalid enum. - option not passed to the request. - add valid attendance preferences that vary across the dummy hackers. * fix: remove accidental changes on valid test for code of conduct. * fix: add missing component on unit tests. * fix: add attendance preference field to remaining dummy hackers. * Potential fix to invalid input test Co-authored-by: Yun Kai Peng <yunkaipeng0129@gmail.com>
1 parent 4815e53 commit 20ef964

File tree

7 files changed

+209
-29
lines changed

7 files changed

+209
-29
lines changed

constants/general.constant.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ const SPONSOR_T5 = "SponsorT5";
8484
const JOB_INTERESTS = ["Internship", "Full Time", "None"];
8585
const SHIRT_SIZES = ["XS", "S", "M", "L", "XL", "XXL"];
8686
const PREVIOUS_HACKATHONS = [0, 1, 2, 3, 4, 5];
87+
const ATTENDANCE_PREFERENCES = ["Remote", "In Person"];
8788

8889
const ROLE_CATEGORIES = {
8990
SELF: ":self",
@@ -198,6 +199,7 @@ module.exports = {
198199
JOB_INTERESTS: JOB_INTERESTS,
199200
SHIRT_SIZES: SHIRT_SIZES,
200201
PREVIOUS_HACKATHONS: PREVIOUS_HACKATHONS,
202+
ATTENDANCE_PREFERENCES: ATTENDANCE_PREFERENCES,
201203
USER_TYPES: USER_TYPES,
202204
SPONSOR_TIERS: SPONSOR_TIERS,
203205
EXTENDED_USER_TYPES: EXTENDED_USER_TYPES,

docs/api/api_data.json

Lines changed: 6 additions & 6 deletions
Large diffs are not rendered by default.

middlewares/validators/hacker.validator.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ module.exports = {
3838
"application.accommodation.barriers",
3939
true
4040
),
41+
VALIDATOR.enumValidator(
42+
"body",
43+
"application.accommodation.attendancePreference",
44+
Constants.ATTENDANCE_PREFERENCES,
45+
false
46+
),
4147
VALIDATOR.stringValidator(
4248
"body",
4349
"application.general.URL.resume",

models/hacker.model.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,12 @@ const HackerSchema = new mongoose.Schema({
126126
enum: Constants.SHIRT_SIZES,
127127
required: true
128128
},
129-
travel: { type: Number, default: 0 }
129+
travel: { type: Number, default: 0 },
130+
attendancePreference: {
131+
type: String,
132+
enum: Constants.ATTENDANCE_PREFERENCES,
133+
required: true
134+
}
130135
},
131136
team: {
132137
type: mongoose.Schema.Types.ObjectId,
@@ -167,7 +172,8 @@ HackerSchema.methods.isApplicationComplete = function() {
167172
const question1Done = !!hs.application.shortAnswer.question1;
168173
const question2Done = !!hs.application.shortAnswer.question2;
169174
const previousHackathonsDone = !!hs.application.shortAnswer.previousHackathons;
170-
return portfolioDone && jobInterestDone && question1Done && question2Done && previousHackathonsDone;
175+
const attendancePreferenceDone = !!hs.application.accommodation.attendancePreference;
176+
return portfolioDone && jobInterestDone && question1Done && question2Done && previousHackathonsDone && attendancePreferenceDone;
171177
};
172178

173179
/**

routes/api/hacker.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ module.exports = {
125125
"privacyPolicy": true,
126126
"codeOfConduct": true,
127127
}
128-
"accomodation": {
128+
"accommodation": {
129129
"travel": 0
130130
},
131131
"location": {
@@ -173,7 +173,7 @@ module.exports = {
173173
"privacyPolicy": true,
174174
"codeOfConduct": true,
175175
}
176-
"accomodation": {
176+
"accommodation": {
177177
"travel": 0
178178
},
179179
"location": {
@@ -469,7 +469,7 @@ module.exports = {
469469
"privacyPolicy": true,
470470
"codeOfConduct": true,
471471
}
472-
"accomodation": {
472+
"accommodation": {
473473
"travel": 0
474474
},
475475
"location": {
@@ -517,7 +517,7 @@ module.exports = {
517517
"privacyPolicy": true,
518518
"codeOfConduct": true,
519519
}
520-
"accomodation": {
520+
"accommodation": {
521521
"travel": 0
522522
},
523523
"location": {
@@ -594,7 +594,7 @@ module.exports = {
594594
"privacyPolicy": true,
595595
"codeOfConduct": true,
596596
}
597-
"accomodation": {
597+
"accommodation": {
598598
"travel": 0
599599
},
600600
"location": {
@@ -667,7 +667,7 @@ module.exports = {
667667
"privacyPolicy": true,
668668
"codeOfConduct": true,
669669
}
670-
"accomodation": {
670+
"accommodation": {
671671
"travel": 0
672672
},
673673
"location": {

tests/hacker.test.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const newHacker0 = util.hacker.newHacker0;
3434
const invalidHackerAccount0 = util.account.hackerAccounts.invalid;
3535
const invalidHacker0 = util.hacker.invalidHacker0;
3636
const invalidHacker2 = util.hacker.invalidHacker2;
37+
const invalidHacker3 = util.hacker.invalidHacker3;
38+
const invalidHacker4 = util.hacker.invalidHacker4;
3739
const newHacker1 = util.hacker.newHacker1;
3840

3941
const noTeamHackerAccount0 = util.account.hackerAccounts.stored.noTeam[0];
@@ -612,6 +614,62 @@ describe("POST create hacker", function() {
612614
});
613615
});
614616

617+
// should fail due to 'asdf' on attendance preference.
618+
it("should FAIL if the new hacker does not have valid attendance preference", function(done) {
619+
util.auth.login(agent, newHackerAccount0, (error) => {
620+
if (error) {
621+
agent.close();
622+
return done(error);
623+
}
624+
return agent
625+
.post(`/api/hacker/`)
626+
.type("application/json")
627+
.send(invalidHacker3)
628+
.end(function(err, res) {
629+
res.should.have.status(422);
630+
res.should.be.json;
631+
res.body.should.have.property("message");
632+
res.body.message.should.equal("Validation failed");
633+
res.body.should.have.property("data");
634+
res.body.data.should.have.property(
635+
"application.accommodation.attendancePreference"
636+
);
637+
res.body.data[
638+
"application.accommodation.attendancePreference"
639+
].msg.should.equal("The value must be part of the enum");
640+
done();
641+
});
642+
});
643+
});
644+
645+
// should fail due to attendance preference not being passed in the request body.
646+
it("should FAIL if the new hacker does not have attendance preference", function(done) {
647+
util.auth.login(agent, newHackerAccount0, (error) => {
648+
if (error) {
649+
agent.close();
650+
return done(error);
651+
}
652+
return agent
653+
.post(`/api/hacker/`)
654+
.type("application/json")
655+
.send(invalidHacker4)
656+
.end(function(err, res) {
657+
res.should.have.status(422);
658+
res.should.be.json;
659+
res.body.should.have.property("message");
660+
res.body.message.should.equal("Validation failed");
661+
res.body.should.have.property("data");
662+
res.body.data.should.have.property(
663+
"application.accommodation.attendancePreference"
664+
);
665+
res.body.data[
666+
"application.accommodation.attendancePreference"
667+
].msg.should.equal("The value being checked agains the enums must exist.");
668+
done();
669+
});
670+
});
671+
});
672+
615673
// fail on unconfirmed account, using admin
616674
it("should FAIL to create a new hacker if the account hasn't been confirmed", function(done) {
617675
util.auth.login(agent, Admin0, (error) => {
@@ -711,6 +769,15 @@ describe("POST create hacker", function() {
711769
].msg.should.equal(
712770
"application.accommodation.travel must be an integer."
713771
);
772+
res.body.data.should.have.property(
773+
"application.accommodation.attendancePreference"
774+
);
775+
res.body.data[
776+
"application.accommodation.attendancePreference"
777+
].should.have.property("msg");
778+
res.body.data[
779+
"application.accommodation.attendancePreference"
780+
].msg.should.equal("The value must be part of the enum");
714781

715782
done();
716783
});

0 commit comments

Comments
 (0)