diff --git a/constants/general.constant.js b/constants/general.constant.js index c9a15d95..5e23d2fe 100644 --- a/constants/general.constant.js +++ b/constants/general.constant.js @@ -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", @@ -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, diff --git a/docs/api/api_data.json b/docs/api/api_data.json index 2c40a0dd..cfc8a3ab 100644 --- a/docs/api/api_data.json +++ b/docs/api/api_data.json @@ -1501,7 +1501,7 @@ "examples": [ { "title": "application: ", - "content": "{\n \"application\":{\n \"general\":{\n \"school\": \"McGill University\",\n \"degree\": \"Undergraduate\",\n \"fieldOfStudy\": \"Computer Science\",\n \"graduationYear\": \"2021\",\n \"jobInterest\":\"Internship\",\n \"URL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n },\n \"shortAnswer\": {\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"question1\": \"I love McHacks\",\n \"question2\":\"Pls accept me\",\n \"previousHackathons\": \"5\",\n \"comments\":\"hi!\",\n },\n \"other:\" {\n \"gender\": \"male\",\n \"ethnicity\": \"Asian or Pacific Islander\",\n \"privacyPolicy\": true,\n \"codeOfConduct\": true,\n }\n \"accomodation\": {\n \"travel\": 0\n },\n \"location:\" {\n \"timeZone\": \"GMT-5\",\n \"country\": \"Canada\",\n \"city\": \"Montreal\",\n }\n }\n}", + "content": "{\n \"application\":{\n \"general\":{\n \"school\": \"McGill University\",\n \"degree\": \"Undergraduate\",\n \"fieldOfStudy\": \"Computer Science\",\n \"graduationYear\": \"2021\",\n \"jobInterest\":\"Internship\",\n \"URL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n },\n \"shortAnswer\": {\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"question1\": \"I love McHacks\",\n \"question2\":\"Pls accept me\",\n \"previousHackathons\": \"5\",\n \"comments\":\"hi!\",\n },\n \"other:\" {\n \"gender\": \"male\",\n \"ethnicity\": \"Asian or Pacific Islander\",\n \"privacyPolicy\": true,\n \"codeOfConduct\": true,\n }\n \"accommodation\": {\n \"travel\": 0\n },\n \"location:\" {\n \"timeZone\": \"GMT-5\",\n \"country\": \"Canada\",\n \"city\": \"Montreal\",\n }\n }\n}", "type": "Json" } ] @@ -1528,7 +1528,7 @@ "examples": [ { "title": "Success-Response: ", - "content": "{\n \"message\": \"Hacker creation successful\", \n \"data\": {\n \"id\":\"5bff4d736f86be0a41badb91\",\n \"application\":{\n \"general\":{\n \"school\": \"McGill University\",\n \"degree\": \"Undergraduate\",\n \"fieldOfStudy\": \"Computer Science\",\n \"graduationYear\": \"2021\",\n \"jobInterest\":\"Internship\",\n \"URL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n },\n \"shortAnswer\": {\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"question1\": \"I love McHacks\",\n \"question2\":\"Pls accept me\",\n \"previousHackathons\": \"5\",\n \"comments\":\"hi!\",\n },\n \"other:\" {\n \"gender\": \"male\",\n \"ethnicity\": \"Asian or Pacific Islander\",\n \"privacyPolicy\": true,\n \"codeOfConduct\": true,\n }\n \"accomodation\": {\n \"travel\": 0\n },\n \"location:\" {\n \"timeZone\": \"GMT-5\",\n \"country\": \"Canada\",\n \"city\": \"Montreal\",\n }\n }\n}", + "content": "{\n \"message\": \"Hacker creation successful\", \n \"data\": {\n \"id\":\"5bff4d736f86be0a41badb91\",\n \"application\":{\n \"general\":{\n \"school\": \"McGill University\",\n \"degree\": \"Undergraduate\",\n \"fieldOfStudy\": \"Computer Science\",\n \"graduationYear\": \"2021\",\n \"jobInterest\":\"Internship\",\n \"URL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n },\n \"shortAnswer\": {\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"question1\": \"I love McHacks\",\n \"question2\":\"Pls accept me\",\n \"previousHackathons\": \"5\",\n \"comments\":\"hi!\",\n },\n \"other:\" {\n \"gender\": \"male\",\n \"ethnicity\": \"Asian or Pacific Islander\",\n \"privacyPolicy\": true,\n \"codeOfConduct\": true,\n }\n \"accommodation\": {\n \"travel\": 0\n },\n \"location:\" {\n \"timeZone\": \"GMT-5\",\n \"country\": \"Canada\",\n \"city\": \"Montreal\",\n }\n }\n}", "type": "object" } ] @@ -1610,7 +1610,7 @@ "examples": [ { "title": "Success-Response: ", - "content": "{\n \"message\": \"Successfully retrieved hacker information\", \n \"data\": {\n \"id\":\"5bff4d736f86be0a41badb91\",\n \"status\": \"Applied\",\n \"application\":{\n \"general\":{\n \"school\": \"McGill University\",\n \"degree\": \"Undergraduate\",\n \"fieldOfStudy\": \"Computer Science\",\n \"graduationYear\": \"2021\",\n \"jobInterest\":\"Internship\",\n \"URL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n },\n \"shortAnswer\": {\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"question1\": \"I love McHacks\",\n \"question2\":\"Pls accept me\",\n \"previousHackathons\": \"5\",\n \"comments\":\"hi!\",\n },\n \"other:\" {\n \"gender\": \"male\",\n \"ethnicity\": \"Asian or Pacific Islander\",\n \"privacyPolicy\": true,\n \"codeOfConduct\": true,\n }\n \"accomodation\": {\n \"travel\": 0\n },\n \"location:\" {\n \"timeZone\": \"GMT-5\",\n \"country\": \"Canada\",\n \"city\": \"Montreal\",\n }\n }\n }\n }", + "content": "{\n \"message\": \"Successfully retrieved hacker information\", \n \"data\": {\n \"id\":\"5bff4d736f86be0a41badb91\",\n \"status\": \"Applied\",\n \"application\":{\n \"general\":{\n \"school\": \"McGill University\",\n \"degree\": \"Undergraduate\",\n \"fieldOfStudy\": \"Computer Science\",\n \"graduationYear\": \"2021\",\n \"jobInterest\":\"Internship\",\n \"URL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n },\n \"shortAnswer\": {\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"question1\": \"I love McHacks\",\n \"question2\":\"Pls accept me\",\n \"previousHackathons\": \"5\",\n \"comments\":\"hi!\",\n },\n \"other:\" {\n \"gender\": \"male\",\n \"ethnicity\": \"Asian or Pacific Islander\",\n \"privacyPolicy\": true,\n \"codeOfConduct\": true,\n }\n \"accommodation\": {\n \"travel\": 0\n },\n \"location:\" {\n \"timeZone\": \"GMT-5\",\n \"country\": \"Canada\",\n \"city\": \"Montreal\",\n }\n }\n }\n }", "type": "object" } ] @@ -1692,7 +1692,7 @@ "examples": [ { "title": "Success-Response: ", - "content": "{\n \"message\": \"Successfully retrieved hacker information\", \n \"data\": {\n \"id\":\"5bff4d736f86be0a41badb91\",\n \"status\": \"Applied\",\n \"application\":{\n \"general\":{\n \"school\": \"McGill University\",\n \"degree\": \"Undergraduate\",\n \"fieldOfStudy\": \"Computer Science\",\n \"graduationYear\": \"2021\",\n \"jobInterest\":\"Internship\",\n \"URL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n },\n \"shortAnswer\": {\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"question1\": \"I love McHacks\",\n \"question2\":\"Pls accept me\",\n \"previousHackathons\": \"5\",\n \"comments\":\"hi!\",\n },\n \"other:\" {\n \"gender\": \"male\",\n \"ethnicity\": \"Asian or Pacific Islander\",\n \"privacyPolicy\": true,\n \"codeOfConduct\": true,\n }\n \"accomodation\": {\n \"travel\": 0\n },\n \"location:\" {\n \"timeZone\": \"GMT-5\",\n \"country\": \"Canada\",\n \"city\": \"Montreal\",\n }\n }\n }\n }", + "content": "{\n \"message\": \"Successfully retrieved hacker information\", \n \"data\": {\n \"id\":\"5bff4d736f86be0a41badb91\",\n \"status\": \"Applied\",\n \"application\":{\n \"general\":{\n \"school\": \"McGill University\",\n \"degree\": \"Undergraduate\",\n \"fieldOfStudy\": \"Computer Science\",\n \"graduationYear\": \"2021\",\n \"jobInterest\":\"Internship\",\n \"URL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n },\n \"shortAnswer\": {\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"question1\": \"I love McHacks\",\n \"question2\":\"Pls accept me\",\n \"previousHackathons\": \"5\",\n \"comments\":\"hi!\",\n },\n \"other:\" {\n \"gender\": \"male\",\n \"ethnicity\": \"Asian or Pacific Islander\",\n \"privacyPolicy\": true,\n \"codeOfConduct\": true,\n }\n \"accommodation\": {\n \"travel\": 0\n },\n \"location:\" {\n \"timeZone\": \"GMT-5\",\n \"country\": \"Canada\",\n \"city\": \"Montreal\",\n }\n }\n }\n }", "type": "object" } ] @@ -1927,7 +1927,7 @@ "examples": [ { "title": "application: ", - "content": "{\n \"application\":{\n \"general\":{\n \"school\": \"McGill University\",\n \"degree\": \"Undergraduate\",\n \"fieldOfStudy\": \"Computer Science\",\n \"graduationYear\": \"2021\",\n \"jobInterest\":\"Internship\",\n \"URL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n },\n \"shortAnswer\": {\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"question1\": \"I love McHacks\",\n \"question2\":\"Pls accept me\",\n \"previousHackathons\": \"5\",\n \"comments\":\"hi!\",\n },\n \"other:\" {\n \"gender\": \"male\",\n \"ethnicity\": \"Asian or Pacific Islander\",\n \"privacyPolicy\": true,\n \"codeOfConduct\": true,\n }\n \"accomodation\": {\n \"travel\": 0\n },\n \"location:\" {\n \"timeZone\": \"GMT-5\",\n \"country\": \"Canada\",\n \"city\": \"Montreal\",\n }\n }\n }", + "content": "{\n \"application\":{\n \"general\":{\n \"school\": \"McGill University\",\n \"degree\": \"Undergraduate\",\n \"fieldOfStudy\": \"Computer Science\",\n \"graduationYear\": \"2021\",\n \"jobInterest\":\"Internship\",\n \"URL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n },\n \"shortAnswer\": {\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"question1\": \"I love McHacks\",\n \"question2\":\"Pls accept me\",\n \"previousHackathons\": \"5\",\n \"comments\":\"hi!\",\n },\n \"other:\" {\n \"gender\": \"male\",\n \"ethnicity\": \"Asian or Pacific Islander\",\n \"privacyPolicy\": true,\n \"codeOfConduct\": true,\n }\n \"accommodation\": {\n \"travel\": 0\n },\n \"location:\" {\n \"timeZone\": \"GMT-5\",\n \"country\": \"Canada\",\n \"city\": \"Montreal\",\n }\n }\n }", "type": "Json" } ] @@ -1954,7 +1954,7 @@ "examples": [ { "title": "Success-Response: ", - "content": "{\n \"message\": \"Changed hacker information\", \n \"data\": {\n \"id\":\"5bff4d736f86be0a41badb91\",\n \"status\": \"Applied\",\n \"application\":{\n \"general\":{\n \"school\": \"McGill University\",\n \"degree\": \"Undergraduate\",\n \"fieldOfStudy\": \"Computer Science\",\n \"graduationYear\": \"2021\",\n \"jobInterest\":\"Internship\",\n \"URL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n },\n \"shortAnswer\": {\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"question1\": \"I love McHacks\",\n \"question2\":\"Pls accept me\",\n \"previousHackathons\": \"5\",\n \"comments\":\"hi!\",\n },\n \"other:\" {\n \"gender\": \"male\",\n \"ethnicity\": \"Asian or Pacific Islander\",\n \"privacyPolicy\": true,\n \"codeOfConduct\": true,\n }\n \"accomodation\": {\n \"travel\": 0\n },\n \"location:\" {\n \"timeZone\": \"GMT-5\",\n \"country\": \"Canada\",\n \"city\": \"Montreal\",\n }\n }\n }\n}", + "content": "{\n \"message\": \"Changed hacker information\", \n \"data\": {\n \"id\":\"5bff4d736f86be0a41badb91\",\n \"status\": \"Applied\",\n \"application\":{\n \"general\":{\n \"school\": \"McGill University\",\n \"degree\": \"Undergraduate\",\n \"fieldOfStudy\": \"Computer Science\",\n \"graduationYear\": \"2021\",\n \"jobInterest\":\"Internship\",\n \"URL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n },\n \"shortAnswer\": {\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"question1\": \"I love McHacks\",\n \"question2\":\"Pls accept me\",\n \"previousHackathons\": \"5\",\n \"comments\":\"hi!\",\n },\n \"other:\" {\n \"gender\": \"male\",\n \"ethnicity\": \"Asian or Pacific Islander\",\n \"privacyPolicy\": true,\n \"codeOfConduct\": true,\n }\n \"accommodation\": {\n \"travel\": 0\n },\n \"location:\" {\n \"timeZone\": \"GMT-5\",\n \"country\": \"Canada\",\n \"city\": \"Montreal\",\n }\n }\n }\n}", "type": "object" } ] diff --git a/middlewares/validators/hacker.validator.js b/middlewares/validators/hacker.validator.js index 4d9b3b81..37b1f705 100644 --- a/middlewares/validators/hacker.validator.js +++ b/middlewares/validators/hacker.validator.js @@ -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", diff --git a/models/hacker.model.js b/models/hacker.model.js index 678570c1..f59f8087 100644 --- a/models/hacker.model.js +++ b/models/hacker.model.js @@ -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, @@ -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; }; /** diff --git a/routes/api/hacker.js b/routes/api/hacker.js index 83412352..d3da1d65 100644 --- a/routes/api/hacker.js +++ b/routes/api/hacker.js @@ -125,7 +125,7 @@ module.exports = { "privacyPolicy": true, "codeOfConduct": true, } - "accomodation": { + "accommodation": { "travel": 0 }, "location": { @@ -173,7 +173,7 @@ module.exports = { "privacyPolicy": true, "codeOfConduct": true, } - "accomodation": { + "accommodation": { "travel": 0 }, "location": { @@ -469,7 +469,7 @@ module.exports = { "privacyPolicy": true, "codeOfConduct": true, } - "accomodation": { + "accommodation": { "travel": 0 }, "location": { @@ -517,7 +517,7 @@ module.exports = { "privacyPolicy": true, "codeOfConduct": true, } - "accomodation": { + "accommodation": { "travel": 0 }, "location": { @@ -594,7 +594,7 @@ module.exports = { "privacyPolicy": true, "codeOfConduct": true, } - "accomodation": { + "accommodation": { "travel": 0 }, "location": { @@ -667,7 +667,7 @@ module.exports = { "privacyPolicy": true, "codeOfConduct": true, } - "accomodation": { + "accommodation": { "travel": 0 }, "location": { diff --git a/tests/hacker.test.js b/tests/hacker.test.js index b6435750..f3defd9b 100644 --- a/tests/hacker.test.js +++ b/tests/hacker.test.js @@ -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]; @@ -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. + 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) => { @@ -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(); }); diff --git a/tests/util/hacker.test.util.js b/tests/util/hacker.test.util.js index 25287159..b0302db8 100644 --- a/tests/util/hacker.test.util.js +++ b/tests/util/hacker.test.util.js @@ -45,7 +45,8 @@ const TeamHacker0 = { accommodation: { dietaryRestrictions: ["Gluten-Free"], shirtSize: "L", - travel: 0 + travel: 0, + attendancePreference: "Remote" } }, teamId: Constants.MongoId.team1Id @@ -86,7 +87,8 @@ const TeamHacker1 = { accommodation: { dietaryRestrictions: ["Gluten-Free"], shirtSize: "L", - travel: 0 + travel: 0, + attendancePreference: "Remote" } }, teamId: Constants.MongoId.team3Id @@ -127,7 +129,8 @@ const TeamHacker2 = { accommodation: { dietaryRestrictions: ["Gluten-Free"], shirtSize: "L", - travel: 0 + travel: 0, + attendancePreference: "Remote" } }, teamId: Constants.MongoId.team3Id @@ -168,7 +171,8 @@ const TeamHacker3 = { accommodation: { dietaryRestrictions: ["Gluten-Free"], shirtSize: "L", - travel: 0 + travel: 0, + attendancePreference: "In Person" } }, teamId: Constants.MongoId.team3Id @@ -209,7 +213,8 @@ const TeamHacker4 = { accommodation: { dietaryRestrictions: ["Gluten-Free"], shirtSize: "L", - travel: 0 + travel: 0, + attendancePreference: "In Person" } }, teamId: Constants.MongoId.team3Id @@ -250,7 +255,8 @@ const NoTeamHacker0 = { accommodation: { dietaryRestrictions: ["Gluten-Free"], shirtSize: "L", - travel: 0 + travel: 0, + attendancePreference: "Remote" } } }; @@ -288,7 +294,8 @@ const newHacker0 = { accommodation: { dietaryRestrictions: ["Gluten-Free"], shirtSize: "L", - travel: 0 + travel: 0, + attendancePreference: "Remote" } } }; @@ -326,7 +333,8 @@ const newHacker1 = { accommodation: { dietaryRestrictions: ["Gluten-Free"], shirtSize: "L", - travel: 0 + travel: 0, + attendancePreference: "Remote" } } }; @@ -366,7 +374,8 @@ const invalidHacker0 = { accommodation: { dietaryRestrictions: ["Gluten-Free"], shirtSize: "L", - travel: 0 + travel: 0, + attendancePreference: "Remote" } } }; @@ -401,7 +410,8 @@ const invalidHacker1 = { accommodation: { dietaryRestrictions: ["Gluten-Free"], shirtSize: "L", - travel: "sfg" + travel: "sfg", + attendancePreference: "Remot" } } }; @@ -441,7 +451,90 @@ const invalidHacker2 = { dietaryRestrictions: ["Gluten-Free"], shirtSize: "L", // must be between [0,100] to be valid - travel: 101 + travel: 101, + attendancePreference: "Remote" + } + } +}; + +// duplicate of newHack0, but with invalid attendance preference. +const invalidHacker3 = { + accountId: Util.Account.hackerAccounts.new[0]._id, + application: { + general: { + school: "University of ASDF", + degree: "Masters", + fieldOfStudy: ["EE"], + graduationYear: 2019, + jobInterest: "Full Time", + URL: { + //gcloud bucket link + resume: "www.gcloud.com/myResume100", + github: "www.github.com/Person1", + dribbble: null, + personal: "www.person1.com", + linkedIn: "www.linkedin.com/in/Person1", + other: null + } + }, + shortAnswer: { + skills: ["CSS", "HTML", "JS"], + question1: "a", + question2: "a", + previousHackathons: 4 + }, + other: { + ethnicity: ["Caucasian"], + codeOfConduct: true, + privacyPolicy: true + }, + accommodation: { + dietaryRestrictions: ["Gluten-Free"], + shirtSize: "L", + travel: 0, + // Attendence Preference Must Be Remote or In Person + attendancePreference: "asdf" + } + } +}; + +// duplicate of newHack0, but with missing attendance preference. +const invalidHacker4 = { + accountId: Util.Account.hackerAccounts.new[0]._id, + application: { + general: { + school: "University of ASDF", + degree: "Masters", + fieldOfStudy: ["EE"], + graduationYear: 2019, + jobInterest: "Full Time", + URL: { + //gcloud bucket link + resume: "www.gcloud.com/myResume100", + github: "www.github.com/Person1", + dribbble: null, + personal: "www.person1.com", + linkedIn: "www.linkedin.com/in/Person1", + other: null + } + }, + shortAnswer: { + skills: ["CSS", "HTML", "JS"], + question1: "a", + question2: "a", + previousHackathons: 4 + }, + other: { + ethnicity: ["Caucasian"], + codeOfConduct: true, + privacyPolicy: true + }, + accommodation: { + dietaryRestrictions: ["Gluten-Free"], + shirtSize: "L", + travel: 0, + // Attendence Preference Must Be Remote or In Person + // attendancePreference: "asdf" } } }; @@ -481,7 +574,8 @@ const duplicateAccountLinkHacker0 = { accommodation: { dietaryRestrictions: ["Gluten-Free"], shirtSize: "L", - travel: 0 + travel: 0, + attendancePreference: "Remote" } } }; @@ -521,7 +615,8 @@ const waitlistedHacker0 = { accommodation: { dietaryRestrictions: ["Gluten-Free"], shirtSize: "L", - travel: 0 + travel: 0, + attendancePreference: "Remote" } }, teamId: Constants.MongoId.team2Id @@ -562,7 +657,8 @@ const unconfirmedAccountHacker0 = { accommodation: { dietaryRestrictions: ["Gluten-Free"], shirtSize: "L", - travel: 0 + travel: 0, + attendancePreference: "Remote" } } }; @@ -602,7 +698,8 @@ const unconfirmedAccountHacker1 = { accommodation: { dietaryRestrictions: ["Gluten-Free"], shirtSize: "L", - travel: 0 + travel: 0, + attendancePreference: "Remote" } } }; @@ -636,6 +733,8 @@ module.exports = { invalidHacker0: invalidHacker0, invalidHacker1: invalidHacker1, invalidHacker2: invalidHacker2, + invalidHacker3: invalidHacker3, + invalidHacker4: invalidHacker4, duplicateAccountLinkHacker0: duplicateAccountLinkHacker0, waitlistedHacker0: waitlistedHacker0,