Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions constants/general.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const SPONSOR_T5 = "SponsorT5";
const JOB_INTERESTS = ["Internship", "Full Time", "None"];
const SHIRT_SIZES = ["XS", "S", "M", "L", "XL", "XXL"];
const PREVIOUS_HACKATHONS = [0, 1, 2, 3, 4, 5];
const ATTENDANCE_PREFERENCES = ["Remote", "In Person"];

const ROLE_CATEGORIES = {
SELF: ":self",
Expand Down Expand Up @@ -198,6 +199,7 @@ module.exports = {
JOB_INTERESTS: JOB_INTERESTS,
SHIRT_SIZES: SHIRT_SIZES,
PREVIOUS_HACKATHONS: PREVIOUS_HACKATHONS,
ATTENDANCE_PREFERENCES: ATTENDANCE_PREFERENCES,
USER_TYPES: USER_TYPES,
SPONSOR_TIERS: SPONSOR_TIERS,
EXTENDED_USER_TYPES: EXTENDED_USER_TYPES,
Expand Down
12 changes: 6 additions & 6 deletions docs/api/api_data.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions middlewares/validators/hacker.validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ module.exports = {
"application.accommodation.barriers",
true
),
VALIDATOR.enumValidator(
"body",
"application.accommodation.attendancePreference",
Constants.ATTENDANCE_PREFERENCES,
false
),
VALIDATOR.stringValidator(
"body",
"application.general.URL.resume",
Expand Down
10 changes: 8 additions & 2 deletions models/hacker.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ const HackerSchema = new mongoose.Schema({
enum: Constants.SHIRT_SIZES,
required: true
},
travel: { type: Number, default: 0 }
travel: { type: Number, default: 0 },
attendancePreference: {
type: String,
enum: Constants.ATTENDANCE_PREFERENCES,
required: true
}
},
team: {
type: mongoose.Schema.Types.ObjectId,
Expand Down Expand Up @@ -167,7 +172,8 @@ HackerSchema.methods.isApplicationComplete = function() {
const question1Done = !!hs.application.shortAnswer.question1;
const question2Done = !!hs.application.shortAnswer.question2;
const previousHackathonsDone = !!hs.application.shortAnswer.previousHackathons;
return portfolioDone && jobInterestDone && question1Done && question2Done && previousHackathonsDone;
const attendancePreferenceDone = !!hs.application.accommodation.attendancePreference;
return portfolioDone && jobInterestDone && question1Done && question2Done && previousHackathonsDone && attendancePreferenceDone;
};

/**
Expand Down
12 changes: 6 additions & 6 deletions routes/api/hacker.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ module.exports = {
"privacyPolicy": true,
"codeOfConduct": true,
}
"accomodation": {
"accommodation": {
"travel": 0
},
"location": {
Expand Down Expand Up @@ -173,7 +173,7 @@ module.exports = {
"privacyPolicy": true,
"codeOfConduct": true,
}
"accomodation": {
"accommodation": {
"travel": 0
},
"location": {
Expand Down Expand Up @@ -469,7 +469,7 @@ module.exports = {
"privacyPolicy": true,
"codeOfConduct": true,
}
"accomodation": {
"accommodation": {
"travel": 0
},
"location": {
Expand Down Expand Up @@ -517,7 +517,7 @@ module.exports = {
"privacyPolicy": true,
"codeOfConduct": true,
}
"accomodation": {
"accommodation": {
"travel": 0
},
"location": {
Expand Down Expand Up @@ -594,7 +594,7 @@ module.exports = {
"privacyPolicy": true,
"codeOfConduct": true,
}
"accomodation": {
"accommodation": {
"travel": 0
},
"location": {
Expand Down Expand Up @@ -667,7 +667,7 @@ module.exports = {
"privacyPolicy": true,
"codeOfConduct": true,
}
"accomodation": {
"accommodation": {
"travel": 0
},
"location": {
Expand Down
67 changes: 67 additions & 0 deletions tests/hacker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const newHacker0 = util.hacker.newHacker0;
const invalidHackerAccount0 = util.account.hackerAccounts.invalid;
const invalidHacker0 = util.hacker.invalidHacker0;
const invalidHacker2 = util.hacker.invalidHacker2;
const invalidHacker3 = util.hacker.invalidHacker3;
const invalidHacker4 = util.hacker.invalidHacker4;
const newHacker1 = util.hacker.newHacker1;

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

// should fail due to 'asdf' on attendance preference.
it("should FAIL if the new hacker does not have valid attendance preference", function(done) {
util.auth.login(agent, newHackerAccount0, (error) => {
if (error) {
agent.close();
return done(error);
}
return agent
.post(`/api/hacker/`)
.type("application/json")
.send(invalidHacker3)
.end(function(err, res) {
res.should.have.status(422);
res.should.be.json;
res.body.should.have.property("message");
res.body.message.should.equal("Validation failed");
res.body.should.have.property("data");
res.body.data.should.have.property(
"application.accommodation.attendancePreference"
);
res.body.data[
"application.accommodation.attendancePreference"
].msg.should.equal("The value must be part of the enum");
done();
});
});
});

// should fail due to attendance preference not being passed in the request body.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: uneven indent

it("should FAIL if the new hacker does not have attendance preference", function(done) {
util.auth.login(agent, newHackerAccount0, (error) => {
if (error) {
agent.close();
return done(error);
}
return agent
.post(`/api/hacker/`)
.type("application/json")
.send(invalidHacker4)
.end(function(err, res) {
res.should.have.status(422);
res.should.be.json;
res.body.should.have.property("message");
res.body.message.should.equal("Validation failed");
res.body.should.have.property("data");
res.body.data.should.have.property(
"application.accommodation.attendancePreference"
);
res.body.data[
"application.accommodation.attendancePreference"
].msg.should.equal("The value being checked agains the enums must exist.");
done();
});
});
});

// fail on unconfirmed account, using admin
it("should FAIL to create a new hacker if the account hasn't been confirmed", function(done) {
util.auth.login(agent, Admin0, (error) => {
Expand Down Expand Up @@ -711,6 +769,15 @@ describe("POST create hacker", function() {
].msg.should.equal(
"application.accommodation.travel must be an integer."
);
res.body.data.should.have.property(
"application.accommodation.attendancePreference"
);
res.body.data[
"application.accommodation.attendancePreference"
].should.have.property("msg");
res.body.data[
"application.accommodation.attendancePreference"
].msg.should.equal("The value must be part of the enum");

done();
});
Expand Down
Loading