Skip to content

Commit af22b9a

Browse files
committed
Add degree type field and tests
1 parent e082175 commit af22b9a

4 files changed

Lines changed: 17 additions & 2 deletions

File tree

middlewares/hacker.middleware.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,20 @@ function parsePatch(req, res, next) {
3131

3232
/**
3333
* @function parseHacker
34-
* @param {{body: {accountId: ObjectId, school: string, gender: string, needsBus: string, application: Object, authorization: string}}} req
34+
* @param {{body: {accountId: ObjectId, school: string, degree: string, gender: string, needsBus: string, application: Object, authorization: string}}} req
3535
* @param {*} res
3636
* @param {(err?)=>void} next
3737
* @return {void}
3838
* @description
39-
* Moves accountId, school, gender, needsBus, application from req.body to req.body.hackerDetails.
39+
* Moves accountId, school, degree, gender, needsBus, application from req.body to req.body.hackerDetails.
4040
* Adds _id to hackerDetails.
4141
*/
4242
function parseHacker(req, res, next) {
4343
const hackerDetails = {
4444
_id: mongoose.Types.ObjectId(),
4545
accountId: req.body.accountId,
4646
school: req.body.school,
47+
degree: req.body.degree,
4748
gender: req.body.gender,
4849
needsBus: req.body.needsBus,
4950
application: req.body.application,
@@ -57,6 +58,7 @@ function parseHacker(req, res, next) {
5758

5859
delete req.body.accountId;
5960
delete req.body.school;
61+
delete req.body.degree;
6062
delete req.body.gender;
6163
delete req.body.needsBus;
6264
delete req.body.application;

middlewares/validators/hacker.validator.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = {
66
// status will be added automatically
77
VALIDATOR.mongoIdValidator("body", "accountId", false),
88
VALIDATOR.nameValidator("body", "school", false),
9+
VALIDATOR.nameValidator("body", "degree", false),
910
VALIDATOR.nameValidator("body", "gender", false),
1011
VALIDATOR.booleanValidator("body", "needsBus", false),
1112
VALIDATOR.applicationValidator("body", "application", false),
@@ -22,6 +23,7 @@ module.exports = {
2223
// untested
2324
updateHackerValidator: [
2425
VALIDATOR.nameValidator("body", "school", true),
26+
VALIDATOR.nameValidator("body", "degree", true),
2527
VALIDATOR.nameValidator("body", "gender", true),
2628
VALIDATOR.applicationValidator("body", "application", true),
2729
VALIDATOR.booleanValidator("body", "needsBus", true)

models/hacker.model.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const HackerSchema = new mongoose.Schema({
2020
type: String,
2121
required: true
2222
},
23+
degree: {
24+
type: String,
25+
required: true
26+
},
2327
//no enum for this
2428
gender: {
2529
type: String

tests/util/hacker.test.util.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const invalidHacker1 = {
1212
// invalid mongoID
1313
"accountId": "UtilAccountAccount1_id",
1414
// invalid missing school attribute
15+
"degree": "Undersaduate",
1516
"gender": "Female",
1617
"needsBus": true,
1718
"application": {
@@ -31,6 +32,7 @@ const duplicateAccountLinkHacker1 = {
3132
"accountId": Util.Account.Account1._id,
3233
"status": "Applied",
3334
"school": "University of Blah",
35+
"degree": "Undergraduate",
3436
"gender": "Male",
3537
"needsBus": true,
3638
"application": {
@@ -55,6 +57,7 @@ const duplicateAccountLinkHacker1 = {
5557
const newHacker1 = {
5658
"accountId": Util.Account.generatedAccounts[6]._id,
5759
"school": "University of ASDF",
60+
"degree": "Masters",
5861
"gender": "Female",
5962
"needsBus": true,
6063
"application": {
@@ -79,6 +82,7 @@ const newHacker1 = {
7982
const newHacker2 = {
8083
"accountId": Util.Account.NonConfirmedAccount1._id,
8184
"school": "University of YIKES",
85+
"degree": "PhD",
8286
"gender": "Female",
8387
"needsBus": true,
8488
"application": {
@@ -105,6 +109,7 @@ const HackerA = {
105109
"accountId": Util.Account.Account1._id,
106110
"status": "Confirmed",
107111
"school": "University of Blah",
112+
"degree": "Masters",
108113
"gender": "Male",
109114
"needsBus": true,
110115
"application": {
@@ -130,6 +135,7 @@ const HackerB = {
130135
"accountId": Util.Account.Account2._id,
131136
"status": "Accepted",
132137
"school": "University of Blah1",
138+
"degree": "Masters",
133139
"gender": "Female",
134140
"needsBus": false,
135141
"application": {
@@ -156,6 +162,7 @@ const HackerC = {
156162
"accountId": Util.Account.Hacker3._id,
157163
"status": "Waitlisted",
158164
"school": "University of Blah1",
165+
"degree": "Masters",
159166
"gender": "Female",
160167
"needsBus": false,
161168
"application": {

0 commit comments

Comments
 (0)