diff --git a/README.md b/README.md index 1ed30901..7e873a2c 100755 --- a/README.md +++ b/README.md @@ -14,4 +14,4 @@ API for registration, live-site ## How to use and contribute -See documentation here: +See documentation here: diff --git a/VERSION b/VERSION index e4c0d46e..8cfbc905 100755 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.3 \ No newline at end of file +1.1.1 \ No newline at end of file diff --git a/app.js b/app.js index 842e6e37..7167e691 100755 --- a/app.js +++ b/app.js @@ -42,7 +42,7 @@ if (!Services.env.isProduction()) { } else { // TODO: change this when necessary corsOptions = { - origin: [`https://${process.env.FRONTEND_ADDRESS_DEPLOY}`, `https://hackerapi.mchacks.ca`], + origin: [`https://${process.env.FRONTEND_ADDRESS_DEPLOY}`, `https://docs.mchacks.ca`], credentials: true }; } diff --git a/constants/success.constant.js b/constants/success.constant.js new file mode 100644 index 00000000..0e9a335b --- /dev/null +++ b/constants/success.constant.js @@ -0,0 +1,72 @@ +"use strict"; + +const ACCOUNT_GET_BY_EMAIL = "Account found by user email."; +const ACCOUNT_GET_BY_ID = "Account found by user id."; +const ACCOUNT_CREATE = "Account creation successful."; +const ACCOUNT_UPDATE = "Account update successful."; +const ACCOUNT_INVITE = "Account invitation successful."; + +const AUTH_LOGIN = "Login successful."; +const AUTH_LOGOUT = "Logout successful."; +const AUTH_SEND_RESET_EMAIL = "Send reset email successful."; +const AUTH_RESET_PASSWORD = "Reset password successful."; +const AUTH_CONFIRM_ACCOUNT = "Confirm account successful."; +const AUTH_GET_ROLE_BINDINGS = "Get role bindings successful."; +const AUTH_GET_ROLES = "Get roles successful."; +const AUTH_SEND_CONFIRMATION_EMAIL = "Send confirmation email successful."; + +const HACKER_GET_BY_ID = "Hacker found by id."; +const HACKER_READ = "Hacker retrieval successful."; +const HACKER_CREATE = "Hacker creation successful."; +const HACKER_UPDATE = "Hacker update successful."; + +const RESUME_UPLOAD = "Resume upload successful."; +const RESUME_DOWNLOAD = "Resume download successful."; + +const SEARCH_QUERY = "Query search successful. Returning results."; +const SEARCH_NO_RESULTS = "Query search successful. No results found."; + + +const SPONSOR_GET_BY_ID = "Sponsor found by id."; +const SPONSOR_CREATE = "Sponsor creation successful."; + +const TEAM_GET_BY_ID = "Team found by id."; +const TEAM_CREATE = "Team creation successful."; + +const VOLUNTEER_CREATE = "Volunteer creation successful."; + +module.exports = { + ACCOUNT_GET_BY_EMAIL: ACCOUNT_GET_BY_EMAIL, + ACCOUNT_GET_BY_ID: ACCOUNT_GET_BY_ID, + ACCOUNT_CREATE: ACCOUNT_CREATE, + ACCOUNT_UPDATE: ACCOUNT_UPDATE, + ACCOUNT_INVITE: ACCOUNT_INVITE, + + AUTH_LOGIN: AUTH_LOGIN, + AUTH_LOGOUT: AUTH_LOGOUT, + AUTH_SEND_RESET_EMAIL: AUTH_SEND_RESET_EMAIL, + AUTH_RESET_PASSWORD: AUTH_RESET_PASSWORD, + AUTH_CONFIRM_ACCOUNT: AUTH_CONFIRM_ACCOUNT, + AUTH_GET_ROLE_BINDINGS: AUTH_GET_ROLE_BINDINGS, + AUTH_SEND_CONFIRMATION_EMAIL: AUTH_SEND_CONFIRMATION_EMAIL, + AUTH_GET_ROLES: AUTH_GET_ROLES, + + HACKER_GET_BY_ID: HACKER_GET_BY_ID, + HACKER_READ: HACKER_READ, + HACKER_CREATE: HACKER_CREATE, + HACKER_UPDATE: HACKER_UPDATE, + + RESUME_UPLOAD: RESUME_UPLOAD, + RESUME_DOWNLOAD: RESUME_DOWNLOAD, + + SEARCH_QUERY: SEARCH_QUERY, + SEARCH_NO_RESULTS: SEARCH_NO_RESULTS, + + SPONSOR_GET_BY_ID: SPONSOR_GET_BY_ID, + SPONSOR_CREATE: SPONSOR_CREATE, + + TEAM_GET_BY_ID: TEAM_GET_BY_ID, + TEAM_CREATE: TEAM_CREATE, + + VOLUNTEER_CREATE: VOLUNTEER_CREATE, +}; \ No newline at end of file diff --git a/controllers/account.controller.js b/controllers/account.controller.js index ec82f020..5f6f8310 100644 --- a/controllers/account.controller.js +++ b/controllers/account.controller.js @@ -6,6 +6,7 @@ const Services = { const Util = require("../middlewares/util.middleware"); const Constants = { Error: require("../constants/error.constant"), + Success: require("../constants/success.constant"), }; @@ -22,7 +23,7 @@ async function getUserByEmail(req, res) { if (acc) { return res.status(200).json({ - message: "Account found by user email", + message: Constants.Success.ACCOUNT_GET_BY_EMAIL, data: acc.toStrippedJSON() }); } else { @@ -47,7 +48,7 @@ async function getUserById(req, res) { if (acc) { return res.status(200).json({ - message: "Account found by user id", + message: Constants.Success.ACCOUNT_GET_BY_ID, data: acc.toStrippedJSON() }); } else { @@ -69,7 +70,7 @@ async function getUserById(req, res) { async function addUser(req, res) { const acc = req.body.account; return res.status(200).json({ - message: "Account creation successful", + message: Constants.Success.ACCOUNT_CREATE, data: acc.toStrippedJSON() }); } @@ -87,14 +88,14 @@ async function addUser(req, res) { */ function updatedAccount(req, res) { return res.status(200).json({ - message: "Changed account information", + message: Constants.Success.ACCOUNT_UPDATE, data: req.body }); } function invitedAccount(req, res) { return res.status(200).json({ - message: "Successfully invited user", + message: Constants.Success.ACCOUNT_INVITE, data: {} }); } diff --git a/controllers/auth.controller.js b/controllers/auth.controller.js index c4687a88..bfefef30 100644 --- a/controllers/auth.controller.js +++ b/controllers/auth.controller.js @@ -1,52 +1,54 @@ "use strict"; +const Success = require("../constants/success.constant"); + module.exports = { onSuccessfulLogin: function (req, res) { return res.status(200).json({ - message: "Successfully logged in", + message: Success.LOGIN, data: {} }); }, logout: function (req, res) { req.logout(); return res.status(200).json({ - message: "Successfully logged out", + message: Success.LOGOUT, data: {} }); }, sentResetEmail: function (req, res) { return res.status(200).json({ - message: "Sent reset email", + message: Success.AUTH_SEND_RESET_EMAIL, data: {} }); }, resetPassword: function (req, res) { return res.status(200).json({ - message: "Successfully reset password", + message: Success.AUTH_RESET_PASSWORD, data: {} }); }, confirmAccount: function (req, res) { return res.status(200).json({ - message: "Successfully confirmed account", + message: Success.AUTH_CONFIRM_ACCOUNT, data: {} }); }, retrieveRoleBindings: function (req, res) { return res.status(200).json({ - message: "Successfully retrieved role bindings", + message: Success.AUTH_GET_ROLE_BINDINGS, data: req.roleBindings.toJSON() }); }, sentConfirmationEmail: function (req, res) { return res.status(200).json({ - message: "Successfully resent account email", + message: Success.AUTH_SEND_CONFIRMATION_EMAIL, data: {} }) }, retrievedRoles: function (req, res) { return res.status(200).json({ - message: "Successfully retrieved all roles", + message: Success.AUTH_GET_ROLES, data: req.roles }) } diff --git a/controllers/hacker.controller.js b/controllers/hacker.controller.js index 3c292a65..8424e66b 100644 --- a/controllers/hacker.controller.js +++ b/controllers/hacker.controller.js @@ -5,6 +5,7 @@ const Services = { }; const Util = require("../middlewares/util.middleware"); const Constants = { + Success: require("../constants/success.constant"), Error: require("../constants/error.constant"), }; @@ -21,7 +22,7 @@ async function findById(req, res) { if (hacker) { return res.status(200).json({ - message: "Successfully retrieved hacker information", + message: Constants.Success.HACKER_GET_BY_ID, data: hacker.toJSON() }); } else { @@ -41,7 +42,7 @@ async function findById(req, res) { */ function showHacker(req, res) { return res.status(200).json({ - message: "Hacker retrieval successful", + message: Constants.Success.HACKER_READ, data: req.body.hacker.toJSON() }); } @@ -55,7 +56,7 @@ function showHacker(req, res) { */ function createdHacker(req, res) { return res.status(200).json({ - message: "Hacker creation successful", + message: Constants.Success.HACKER_CREATE, data: req.body.hacker.toJSON() }); } @@ -73,14 +74,14 @@ function createdHacker(req, res) { */ function updatedHacker(req, res) { return res.status(200).json({ - message: "Changed hacker information", + message: Constants.Success.HACKER_UPDATE, data: req.body }); } function uploadedResume(req, res) { return res.status(200).json({ - message: "Uploaded resume", + message: Constants.Success.RESUME_UPLOAD, data: { filename: req.body.gcfilename } @@ -89,7 +90,7 @@ function uploadedResume(req, res) { function downloadedResume(req, res) { return res.status(200).json({ - message: "Downloaded resume", + message: Constants.Success.RESUME_DOWNLOAD, data: { id: req.body.id, resume: req.body.resume diff --git a/controllers/search.controller.js b/controllers/search.controller.js index 4faacc06..52ca25de 100644 --- a/controllers/search.controller.js +++ b/controllers/search.controller.js @@ -4,16 +4,16 @@ const Services = { Logger: require("../services/logger.service") }; const Util = require("../middlewares/util.middleware"); +const Success = require("../constants/success.constant"); async function searchResults(req, res) { let results = req.body.results; let message; - if(results.length < 1){ - message = "No results found." - results = {} - } - else{ - message = "Successfully executed query, returning all results" + if (results.length < 1) { + message = Success.SEARCH_NO_RESULTS; + results = {}; + } else { + message = Success.SEARCH_QUERY; } return res.status(200).json({ message: message, @@ -23,4 +23,4 @@ async function searchResults(req, res) { module.exports = { searchResults: Util.asyncMiddleware(searchResults) -} \ No newline at end of file +}; \ No newline at end of file diff --git a/controllers/sponsor.controller.js b/controllers/sponsor.controller.js index 496e6421..8c571797 100644 --- a/controllers/sponsor.controller.js +++ b/controllers/sponsor.controller.js @@ -5,8 +5,9 @@ const Services = { }; const Util = require("../middlewares/util.middleware"); const Constants = { + Success: require("../constants/success.constant"), Error: require("../constants/error.constant"), -} +}; /** * @async @@ -22,7 +23,7 @@ async function findById(req, res) { if (sponsor) { return res.status(200).json({ - message: "Successfully retrieved sponsor information", + message: Constants.Success.SPONSOR_GET_BY_ID, data: sponsor.toJSON() }); } else { @@ -48,7 +49,7 @@ async function createSponsor(req, res) { if (success) { return res.status(200).json({ - message: "Sponsor creation successful", + message: Constants.Success.SPONSOR_CREATE, data: sponsorDetails }); } else { diff --git a/controllers/team.controller.js b/controllers/team.controller.js index 016dabbe..d39b5239 100644 --- a/controllers/team.controller.js +++ b/controllers/team.controller.js @@ -7,6 +7,7 @@ const Services = { }; const Util = require("../middlewares/util.middleware"); const Constants = { + Success: require("../constants/success.constant"), Error: require("../constants/error.constant"), }; @@ -23,7 +24,7 @@ async function findById(req, res) { if (team) { return res.status(200).json({ - message: "Successfully retrieved team information", + message: Constants.Success.TEAM_GET_BY_ID, data: team.toJSON() }); } else { @@ -49,7 +50,7 @@ async function createTeam(req, res) { if (success) { return res.status(200).json({ - message: "Team creation successful", + message: Constants.Success.TEAM_CREATE, data: teamDetails }); } else { diff --git a/controllers/volunteer.controller.js b/controllers/volunteer.controller.js index 6f9574a4..d3909e4e 100644 --- a/controllers/volunteer.controller.js +++ b/controllers/volunteer.controller.js @@ -5,6 +5,7 @@ const Services = { }; const Util = require("../middlewares/util.middleware"); const Constants = { + Success: require("../constants/success.constant"), Error: require("../constants/error.constant"), } @@ -23,7 +24,7 @@ async function createVolunteer(req, res) { if (success) { return res.status(200).json({ - message: "Volunteer creation successful", + message: Constants.Success.VOLUNTEER_CREATE, data: volunteerDetails }); } else { diff --git a/deployment.yaml b/deployment.yaml index dbb0bdb9..d9adb40b 100644 --- a/deployment.yaml +++ b/deployment.yaml @@ -18,7 +18,7 @@ spec: secretName: hackboard-secret containers: - name: hackboard - image: gcr.io/mchacks-api/hackboard:1.0.2 + image: gcr.io/mchacks-api/hackboard:latest ports: # - containerPort: 443 - containerPort: 8080 \ No newline at end of file diff --git a/middlewares/validators/hacker.validator.js b/middlewares/validators/hacker.validator.js index cbe2b984..bf90c54f 100644 --- a/middlewares/validators/hacker.validator.js +++ b/middlewares/validators/hacker.validator.js @@ -13,7 +13,7 @@ module.exports = { VALIDATOR.alphaArrayValidator("body", "ethnicity", false), VALIDATOR.nameValidator("body", "major", false), VALIDATOR.integerValidator("body", "graduationYear", false, 2019, 2030), - VALIDATOR.booleanValidator("body", "codeOfConduct", false), + VALIDATOR.booleanValidator("body", "codeOfConduct", false, true), ], updateConfirmationValidator: [ diff --git a/middlewares/validators/validator.helper.js b/middlewares/validators/validator.helper.js index 1d5dcbfa..4237d645 100644 --- a/middlewares/validators/validator.helper.js +++ b/middlewares/validators/validator.helper.js @@ -103,19 +103,29 @@ function mongoIdArrayValidator(fieldLocation, fieldname, optional = true) { } /** - * Validates that field must be boolean. + * Validates that field must be boolean. Optionally checks for desired boolean * @param {"query" | "body" | "header" | "param"} fieldLocation the location where the field should be found * @param {string} fieldname name of the field that needs to be validated. * @param {boolean} optional whether the field is optional or not. */ -function booleanValidator(fieldLocation, fieldname, optional = true) { +function booleanValidator(fieldLocation, fieldname, optional = true, desire = null) { const booleanField = setProperValidationChainBuilder(fieldLocation, fieldname, "invalid boolean"); if (optional) { // do not use check falsy option as a 'false' boolean will be skipped - return booleanField.optional().isBoolean().withMessage("must be boolean"); + return booleanField.optional().isBoolean().withMessage("must be boolean").custom((val) => { + if (desire !== null) { + return desire === val; + } + return true; + }).withMessage(`Must be equal to ${desire}`); } else { - return booleanField.exists().isBoolean().withMessage("must be boolean"); + return booleanField.exists().isBoolean().withMessage("must be boolean").custom((val) => { + if (desire !== null) { + return desire === val; + } + return true; + }).withMessage(`Must be equal to ${desire}`); } } diff --git a/tests/account.test.js b/tests/account.test.js index 72d3bafb..d36cdde2 100644 --- a/tests/account.test.js +++ b/tests/account.test.js @@ -8,7 +8,8 @@ const Account = require("../models/account.model"); const should = chai.should(); const Constants = { Error: require("../constants/error.constant"), - General: require("../constants/general.constant") + General: require("../constants/general.constant"), + Success: require("../constants/success.constant"), }; @@ -76,7 +77,7 @@ describe("GET user account", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Account found by user email"); + res.body.message.should.equal(Constants.Success.ACCOUNT_GET_BY_EMAIL); res.body.should.have.property("data"); res.body.data.should.be.a("object"); res.body.data.should.have.property("firstName"); @@ -106,7 +107,7 @@ describe("GET user account", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Account found by user id"); + res.body.message.should.equal(Constants.Success.ACCOUNT_GET_BY_ID); res.body.should.have.property("data"); // use acc.toStrippedJSON to deal with hidden passwords and convert _id to id @@ -133,7 +134,7 @@ describe("GET user account", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Account found by user id"); + res.body.message.should.equal(Constants.Success.ACCOUNT_GET_BY_ID); res.body.should.have.property("data"); // use acc.toStrippedJSON to deal with hidden passwords and convert _id to id @@ -180,7 +181,7 @@ describe("POST create account", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Account creation successful"); + res.body.message.should.equal(Constants.Success.ACCOUNT_CREATE); // use acc.toStrippedJSON to deal with hidden passwords and convert _id to id const acc = (new Account(newAccount1)).toStrippedJSON(); @@ -212,7 +213,7 @@ describe("POST confirm account", function () { .end(function (err, res) { res.should.have.status(200); res.body.should.have.property("message"); - res.body.message.should.equal("Successfully confirmed account"); + res.body.message.should.equal(Constants.Success.AUTH_CONFIRM_ACCOUNT); done(); }); }); @@ -281,7 +282,7 @@ describe("PATCH update account", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Changed account information"); + res.body.message.should.equal(Constants.Success.ACCOUNT_UPDATE); res.body.should.have.property("data"); // Is this correct matching of data? res.body.data.firstName.should.equal(updatedInfo.firstName); @@ -306,7 +307,7 @@ describe("PATCH update account", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Changed account information"); + res.body.message.should.equal(Constants.Success.ACCOUNT_UPDATE); res.body.should.have.property("data"); // Is this correct matching of data? res.body.data.firstName.should.equal(updatedInfo.firstName); @@ -353,7 +354,7 @@ describe("POST reset password", function () { .end(function (err, res) { res.should.have.status(200); res.body.should.have.property("message"); - res.body.message.should.equal("Successfully reset password"); + res.body.message.should.equal(Constants.Success.AUTH_RESET_PASSWORD); done(); }); }); @@ -397,7 +398,7 @@ describe("PATCH change password for logged in user", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Successfully reset password"); + res.body.message.should.equal(Constants.Success.AUTH_RESET_PASSWORD); done(); }); }); @@ -437,7 +438,7 @@ describe("GET retrieve permissions", function () { .end(function (err, res) { res.should.have.status(200); res.body.should.have.property("message"); - res.body.message.should.equal("Successfully retrieved role bindings"); + res.body.message.should.equal(Constants.Success.AUTH_GET_ROLE_BINDINGS); res.body.should.have.property("data"); res.body.data.should.be.a("object"); res.body.data.should.have.property("roles"); @@ -474,7 +475,7 @@ describe("GET resend confirmation email", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Successfully resent account email"); + res.body.message.should.equal(Constants.Success.AUTH_SEND_CONFIRMATION_EMAIL); done(); }); }); @@ -538,7 +539,7 @@ describe("POST invite account", function () { } res.should.have.status(200); res.body.should.have.property("message"); - res.body.message.should.equal("Successfully invited user"); + res.body.message.should.equal(Constants.Success.ACCOUNT_INVITE); done(); }); }); diff --git a/tests/auth.test.js b/tests/auth.test.js index 65452f31..d0a428bc 100644 --- a/tests/auth.test.js +++ b/tests/auth.test.js @@ -17,6 +17,10 @@ const util = { role: require("./util/role.test.util") }; +const constants = { + success: require("../constants/success.constant"), +} + const roles = require("../constants/role.constant"); // hacker role binding @@ -38,7 +42,7 @@ describe("GET roles", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Successfully retrieved all roles"); + res.body.message.should.equal(constants.success.AUTH_GET_ROLES); res.body.should.have.property("data"); res.body.data.should.be.a("Array"); diff --git a/tests/hacker.test.js b/tests/hacker.test.js index 8b18025d..15174ee2 100644 --- a/tests/hacker.test.js +++ b/tests/hacker.test.js @@ -9,6 +9,7 @@ const Hacker = require("../models/hacker.model"); const fs = require("fs"); const path = require("path"); const Constants = { + Success: require("../constants/success.constant"), General: require("../constants/general.constant"), Error: require("../constants/error.constant"), }; @@ -36,6 +37,9 @@ const storedAccount2 = util.account.Account2; const storedHacker2 = util.hacker.HackerB; const newHacker1 = util.hacker.newHacker1; +// badConductHacker1 is the same as newHacker1, even linking to the same account +// the difference is that badConductHacker1 does not accept the code of conducts +const badConductHacker1 = util.hacker.badCodeOfConductHacker1; const newHackerAccount1 = util.account.allAccounts[13]; const newHacker2 = util.hacker.newHacker2; @@ -71,7 +75,7 @@ describe("GET hacker", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Hacker retrieval successful"); + res.body.message.should.equal(Constants.Success.HACKER_READ); res.body.should.have.property("data"); let hacker = new Hacker(storedHacker1); @@ -117,7 +121,7 @@ describe("GET hacker", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Successfully retrieved hacker information"); + res.body.message.should.equal(Constants.Success.HACKER_GET_BY_ID); res.body.should.have.property("data"); let hacker = new Hacker(storedHacker1); @@ -145,7 +149,7 @@ describe("GET hacker", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Successfully retrieved hacker information"); + res.body.message.should.equal(Constants.Success.HACKER_GET_BY_ID); res.body.should.have.property("data"); let hacker = new Hacker(storedHacker1); @@ -240,7 +244,7 @@ describe("POST create hacker", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Hacker creation successful"); + res.body.message.should.equal(Constants.Success.HACKER_CREATE); res.body.should.have.property("data"); // create JSON version of model @@ -272,7 +276,7 @@ describe("POST create hacker", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Hacker creation successful"); + res.body.message.should.equal(Constants.Success.HACKER_CREATE); res.body.should.have.property("data"); // create JSON version of model @@ -288,6 +292,30 @@ describe("POST create hacker", function () { }); }); + // should fail due to 'false' on code of conduct + it("should FAIL if the new hacker does not accept code of conduct", function (done) { + util.auth.login(agent, newHackerAccount1, (error) => { + if (error) { + agent.close(); + return done(error); + } + return agent + .post(`/api/hacker/`) + .type("application/json") + .send(badConductHacker1) + .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("codeOfConduct"); + res.body.data.codeOfConduct.msg.should.equal("Must be equal to true"); + 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, Admin1, (error) => { @@ -385,7 +413,7 @@ describe("PATCH update one hacker", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Changed hacker information"); + res.body.message.should.equal(Constants.Success.HACKER_UPDATE); res.body.should.have.property("data"); chai.assert.equal(JSON.stringify(res.body.data), JSON.stringify({ gender: "Other" @@ -411,7 +439,7 @@ describe("PATCH update one hacker", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Changed hacker information"); + res.body.message.should.equal(Constants.Success.HACKER_UPDATE); res.body.should.have.property("data"); chai.assert.equal(JSON.stringify(res.body.data), JSON.stringify({ status: "Accepted" @@ -461,7 +489,7 @@ describe("PATCH update one hacker", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Changed hacker information"); + res.body.message.should.equal(Constants.Success.HACKER_UPDATE); res.body.should.have.property("data"); chai.assert.equal(JSON.stringify(res.body.data), JSON.stringify({ status: "Checked-in" @@ -512,7 +540,7 @@ describe("PATCH update one hacker", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Changed hacker information"); + res.body.message.should.equal(Constants.Success.HACKER_UPDATE); res.body.should.have.property("data"); chai.assert.equal(JSON.stringify(res.body.data), JSON.stringify({ gender: "Other" @@ -591,7 +619,7 @@ describe("PATCH update one hacker", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Changed hacker information"); + res.body.message.should.equal(Constants.Success.HACKER_UPDATE); res.body.should.have.property("data"); chai.assert.equal(JSON.stringify(res.body.data), JSON.stringify({ status: Constants.General.HACKER_STATUS_CONFIRMED @@ -622,7 +650,7 @@ describe("PATCH update one hacker", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Changed hacker information"); + res.body.message.should.equal(Constants.Success.HACKER_UPDATE); res.body.should.have.property("data"); chai.assert.equal(JSON.stringify(res.body.data), JSON.stringify({ status: Constants.General.HACKER_STATUS_ACCEPTED @@ -706,7 +734,7 @@ describe("POST add a hacker resume", function () { res.should.have.status(200); res.should.have.property("body"); res.body.should.have.property("message"); - res.body.message.should.equal("Uploaded resume"); + res.body.message.should.equal(Constants.Success.RESUME_UPLOAD); res.body.should.have.property("data"); res.body.data.should.have.property("filename"); StorageService.download(res.body.data.filename).then((value) => { diff --git a/tests/sponsor.test.js b/tests/sponsor.test.js index f577a6fe..dd6b9f5a 100644 --- a/tests/sponsor.test.js +++ b/tests/sponsor.test.js @@ -8,6 +8,7 @@ const Sponsor = require("../models/sponsor.model"); const should = chai.should(); const mongoose = require("mongoose"); const Constants = { + Success: require("../constants/success.constant"), Error: require("../constants/error.constant"), }; @@ -67,7 +68,7 @@ describe("GET user sponsor", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Successfully retrieved sponsor information"); + res.body.message.should.equal(Constants.Success.SPONSOR_GET_BY_ID); res.body.should.have.property("data"); res.body.data.should.be.a("object"); @@ -93,7 +94,7 @@ describe("GET user sponsor", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Successfully retrieved sponsor information"); + res.body.message.should.equal(Constants.Success.SPONSOR_GET_BY_ID); res.body.should.have.property("data"); res.body.data.should.be.a("object"); @@ -180,10 +181,10 @@ describe("POST create sponsor", function () { .type("application/json") .send(newSponsor) .end(function (err, res) { - // res.should.have.status(200); + res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Sponsor creation successful"); + res.body.message.should.equal(Constants.Success.SPONSOR_CREATE); res.body.should.have.property("data"); // deleting _id because that was generated, and not part of original data diff --git a/tests/team.test.js b/tests/team.test.js index 723a3e9e..bbb4473f 100644 --- a/tests/team.test.js +++ b/tests/team.test.js @@ -9,6 +9,10 @@ const util = { team: require("./util/team.test.util"), }; +const Constants = { + Success: require("../constants/success.constant"), +} + describe("GET team", function () { it("should SUCCEED and list a team's information from /api/team/:id GET", function (done) { chai.request(server.app) @@ -17,7 +21,7 @@ describe("GET team", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Successfully retrieved team information"); + res.body.message.should.equal(Constants.Success.TEAM_GET_BY_ID); res.body.should.have.property("data"); let team = new Team(util.team.Team1); @@ -37,7 +41,7 @@ describe("POST create team", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Team creation successful"); + res.body.message.should.equal(Constants.Success.TEAM_CREATE); res.body.should.have.property("data"); // deleting _id because that was generated, and not part of original data diff --git a/tests/util/hacker.test.util.js b/tests/util/hacker.test.util.js index 8f32ff44..360a80e2 100644 --- a/tests/util/hacker.test.util.js +++ b/tests/util/hacker.test.util.js @@ -27,6 +27,32 @@ const invalidHacker1 = { "codeOfConduct": true, }; +// duplicate of newHack1, but with false for code of conduct +const badCodeOfConductHacker1 = { + "accountId": Util.Account.generatedAccounts[6]._id, + "school": "University of ASDF", + "degree": "Masters", + "gender": "Female", + "needsBus": true, + "application": { + "portfolioURL": { + //gcloud bucket link + "resume": "www.gcloud.com/myResume100", + "github": "www.github.com/Person1", + "dropler": undefined, + "personal": "www.person1.com", + "linkedIn": "www.linkedin.com/in/Person1", + "other": undefined + }, + "jobInterest": "Full-time", + "skills": ["CSS", "HTML", "JS"], + }, + "ethnicity": ["Caucasian"], + "major": "EE", + "graduationYear": 2019, + "codeOfConduct": false, +}; + const duplicateAccountLinkHacker1 = { "_id": mongoose.Types.ObjectId(), "accountId": Util.Account.Account1._id, @@ -195,6 +221,7 @@ module.exports = { invalidHacker1: invalidHacker1, newHacker1: newHacker1, newHacker2: newHacker2, + badCodeOfConductHacker1: badCodeOfConductHacker1, HackerA: HackerA, HackerB: HackerB, HackerC: HackerC, diff --git a/tests/volunteer.test.js b/tests/volunteer.test.js index 6e5d56ae..e527bd56 100644 --- a/tests/volunteer.test.js +++ b/tests/volunteer.test.js @@ -7,6 +7,7 @@ const agent = chai.request.agent(server.app); const should = chai.should(); const Volunteer = require("../models/volunteer.model"); const Constants = { + Success: require("../constants/success.constant"), Error: require("../constants/error.constant"), }; @@ -79,7 +80,7 @@ describe("POST create volunteer", function () { res.should.have.status(200); res.should.be.json; res.body.should.have.property("message"); - res.body.message.should.equal("Volunteer creation successful"); + res.body.message.should.equal(Constants.Success.VOLUNTEER_CREATE); res.body.should.have.property("data"); // deleting _id because that was generated, and not part of original data