From 5da7a5818108bdf1d31d4e10d8b17d1577d0bba6 Mon Sep 17 00:00:00 2001 From: Anmol Brar Date: Fri, 29 Oct 2021 19:30:50 -0400 Subject: [PATCH 1/7] - 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. --- constants/general.constant.js | 2 ++ middlewares/validators/hacker.validator.js | 6 ++++++ models/hacker.model.js | 10 ++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) 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/middlewares/validators/hacker.validator.js b/middlewares/validators/hacker.validator.js index 4d9b3b81..1e9cc699 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.accomodation.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; }; /** From 84600b8ea64da5f00082189f58a116a08d06f07e Mon Sep 17 00:00:00 2001 From: Anmol Brar Date: Fri, 29 Oct 2021 20:02:04 -0400 Subject: [PATCH 2/7] 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. --- docs/api/api_data.json | 12 ++++++------ middlewares/validators/hacker.validator.js | 2 +- routes/api/hacker.js | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) 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 1e9cc699..37b1f705 100644 --- a/middlewares/validators/hacker.validator.js +++ b/middlewares/validators/hacker.validator.js @@ -40,7 +40,7 @@ module.exports = { ), VALIDATOR.enumValidator( "body", - "application.accomodation.attendancePreference", + "application.accommodation.attendancePreference", Constants.ATTENDANCE_PREFERENCES, false ), 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": { From 0be513c7ebd5dea5c84433d774c2cc6bffc391b7 Mon Sep 17 00:00:00 2001 From: Anmol Brar Date: Fri, 26 Nov 2021 19:02:09 -0500 Subject: [PATCH 3/7] 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. --- tests/hacker.test.js | 62 ++++++++++++++++- tests/util/hacker.test.util.js | 117 +++++++++++++++++++++++++++++---- 2 files changed, 166 insertions(+), 13 deletions(-) diff --git a/tests/hacker.test.js b/tests/hacker.test.js index b6435750..f5c5eace 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]; @@ -596,10 +598,10 @@ describe("POST create hacker", function() { res.body.message.should.equal("Validation failed"); res.body.should.have.property("data"); res.body.data.should.have.property( - "application.other.privacyPolicy" + "application.accomodation.privacyPolicy" ); res.body.data[ - "application.other.privacyPolicy" + "application.accomodation.privacyPolicy" ].msg.should.equal("Must be equal to true"); res.body.data.should.have.property( "application.other.codeOfConduct" @@ -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) => { diff --git a/tests/util/hacker.test.util.js b/tests/util/hacker.test.util.js index 25287159..a29bc392 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: "Remote" } } }; @@ -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" } } }; @@ -636,6 +729,8 @@ module.exports = { invalidHacker0: invalidHacker0, invalidHacker1: invalidHacker1, invalidHacker2: invalidHacker2, + invalidHacker3: invalidHacker3, + invalidHacker4: invalidHacker4, duplicateAccountLinkHacker0: duplicateAccountLinkHacker0, waitlistedHacker0: waitlistedHacker0, From 28ac4772ca430c9191acdc68cdfab03f5f21ad76 Mon Sep 17 00:00:00 2001 From: Anmol Brar Date: Fri, 26 Nov 2021 19:06:07 -0500 Subject: [PATCH 4/7] fix: remove accidental changes on valid test for code of conduct. --- tests/hacker.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/hacker.test.js b/tests/hacker.test.js index f5c5eace..0ecfda89 100644 --- a/tests/hacker.test.js +++ b/tests/hacker.test.js @@ -598,10 +598,10 @@ describe("POST create hacker", function() { res.body.message.should.equal("Validation failed"); res.body.should.have.property("data"); res.body.data.should.have.property( - "application.accomodation.privacyPolicy" + "application.other.privacyPolicy" ); res.body.data[ - "application.accomodation.privacyPolicy" + "application.other.privacyPolicy" ].msg.should.equal("Must be equal to true"); res.body.data.should.have.property( "application.other.codeOfConduct" From 34893be36f31ee06a7007fd5903fa8a8acd5e323 Mon Sep 17 00:00:00 2001 From: Anmol Brar Date: Sat, 27 Nov 2021 18:30:19 -0500 Subject: [PATCH 5/7] fix: add missing component on unit tests. --- tests/hacker.test.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/hacker.test.js b/tests/hacker.test.js index 0ecfda89..f3defd9b 100644 --- a/tests/hacker.test.js +++ b/tests/hacker.test.js @@ -769,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(); }); From b3b51d8c2a4765bfe968d8ca78e519ed0561e545 Mon Sep 17 00:00:00 2001 From: Anmol Brar Date: Sat, 27 Nov 2021 18:49:18 -0500 Subject: [PATCH 6/7] fix: add attendance preference field to remaining dummy hackers. --- tests/util/hacker.test.util.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/util/hacker.test.util.js b/tests/util/hacker.test.util.js index a29bc392..cde1fd77 100644 --- a/tests/util/hacker.test.util.js +++ b/tests/util/hacker.test.util.js @@ -574,7 +574,8 @@ const duplicateAccountLinkHacker0 = { accommodation: { dietaryRestrictions: ["Gluten-Free"], shirtSize: "L", - travel: 0 + travel: 0, + attendancePreference: "Remote" } } }; @@ -614,7 +615,8 @@ const waitlistedHacker0 = { accommodation: { dietaryRestrictions: ["Gluten-Free"], shirtSize: "L", - travel: 0 + travel: 0, + attendancePreference: "Remote" } }, teamId: Constants.MongoId.team2Id @@ -655,7 +657,8 @@ const unconfirmedAccountHacker0 = { accommodation: { dietaryRestrictions: ["Gluten-Free"], shirtSize: "L", - travel: 0 + travel: 0, + attendancePreference: "Remote" } } }; @@ -695,7 +698,8 @@ const unconfirmedAccountHacker1 = { accommodation: { dietaryRestrictions: ["Gluten-Free"], shirtSize: "L", - travel: 0 + travel: 0, + attendancePreference: "Remote" } } }; From b6a35f2de63ca89c83547f5479fa1006b6f96f1a Mon Sep 17 00:00:00 2001 From: Yun Kai Peng Date: Sat, 27 Nov 2021 21:35:55 -0500 Subject: [PATCH 7/7] Potential fix to invalid input test --- tests/util/hacker.test.util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/util/hacker.test.util.js b/tests/util/hacker.test.util.js index cde1fd77..b0302db8 100644 --- a/tests/util/hacker.test.util.js +++ b/tests/util/hacker.test.util.js @@ -411,7 +411,7 @@ const invalidHacker1 = { dietaryRestrictions: ["Gluten-Free"], shirtSize: "L", travel: "sfg", - attendancePreference: "Remote" + attendancePreference: "Remot" } } };