Skip to content

Commit 5a34cd0

Browse files
authored
feat: add isRemote boolean variable to the SETTINGS schema, wire in validation, and add tests (#675)
* feat: add isRemote boolean variable to the SETTINGS schema, wire in validation, and add tests * feat: update API docs
1 parent f16bf7a commit 5a34cd0

File tree

10 files changed

+49
-8323
lines changed

10 files changed

+49
-8323
lines changed

docs/api/api_data.js

Lines changed: 1 addition & 4143 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/api_data.json

Lines changed: 1 addition & 4143 deletions
Large diffs are not rendered by default.

docs/api/api_project.js

Lines changed: 1 addition & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/api_project.json

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1 @@
1-
{
2-
"name": "hackerAPI",
3-
"version": "0.0.8",
4-
"description": "Documentation for the API used for mchacks",
5-
"defaultVersion": "0.0.8",
6-
"title": "hackerAPI documentation",
7-
"url": "https://api.mchacks.ca/api",
8-
"sampleUrl": "https://api.mchacks.ca/api",
9-
"apidoc": "0.3.0",
10-
"generator": {
11-
"name": "apidoc",
12-
"time": "2020-10-31T17:54:03.433Z",
13-
"url": "http://apidocjs.com",
14-
"version": "0.17.7"
15-
}
16-
}
1+
{ "name": "hackerAPI", "version": "0.0.8", "description": "Documentation for the API used for mchacks", "defaultVersion": "0.0.8", "title": "hackerAPI documentation", "url": "https://api.mchacks.ca/api", "sampleUrl": "https://api.mchacks.ca/api", "apidoc": "0.3.0", "generator": { "name": "apidoc", "time": "2020-11-01T22:01:33.009Z", "url": "http://apidocjs.com", "version": "0.17.7" }}

middlewares/settings.middleware.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async function updateSettings(req, res, next) {
5757

5858
/**
5959
* @function confirmValidPatch
60-
* @param {{body:{settingsDetails:{openTime:Date, closeTime:Date, confirmTime:Date}}}} req
60+
* @param {{body:{settingsDetails:{openTime:Date, closeTime:Date, confirmTime:Date, isRemote: Boolean}}}} req
6161
* @param {*} res
6262
* @param {*} next
6363
* @return {void}

middlewares/validators/settings.validator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
createSettingsValidator: [
66
VALIDATOR.dateValidator("body", "openTime", true),
77
VALIDATOR.dateValidator("body", "closeTime", true),
8-
VALIDATOR.dateValidator("body", "confirmTime", true)
8+
VALIDATOR.dateValidator("body", "confirmTime", true),
9+
VALIDATOR.booleanValidator("body", "isRemote", true)
910
]
1011
};

models/settings.model.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ const settings = new mongoose.Schema({
1313
confirmTime: {
1414
type: Date,
1515
default: Date.now() + 31104000000 + 2628000000 // 1 year and 1 month from now.
16+
},
17+
isRemote: {
18+
type: Boolean,
19+
default: false
1620
}
1721
});
1822

routes/api/settings.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ module.exports = {
3434
* "settings": {
3535
* openTime: "Wed Feb 06 2019 00:00:00 GMT-0500 (GMT-05:00)",
3636
* closeTime: "Sat Feb 01 2020 00:00:00 GMT-0500 (GMT-05:00)",
37-
* confirmTime: "Sat Feb 20 2020 00:00:00 GMT-0500 (GMT-05:00)"
37+
* confirmTime: "Sat Feb 20 2020 00:00:00 GMT-0500 (GMT-05:00)",
38+
* isRemote: false
3839
* }
3940
* }
4041
* }
@@ -55,6 +56,7 @@ module.exports = {
5556
* @apiParam (body) {Date} [openTime] The opening time for the hackathon.
5657
* @apiParam (body) {Date} [closeTime] The closing time for the hackathon.
5758
* @apiParam (body) {Date} [confirmTime] The deadline for confirmation for the hackathon.
59+
* @apiParam (body) {Boolean} [isRemote] Whether this hackathon is remote or not.
5860
*
5961
* @apiSuccess {string} message Success message
6062
* @apiSuccess {object} data Settings Object
@@ -65,7 +67,8 @@ module.exports = {
6567
* "settings": {
6668
* openTime: "Wed Feb 06 2019 00:00:00 GMT-0500 (GMT-05:00)",
6769
* closeTime: "Sat Feb 01 2020 00:00:00 GMT-0500 (GMT-05:00)",
68-
* confirmTime: "Sat Feb 20 2020 00:00:00 GMT-0500 (GMT-05:00)"
70+
* confirmTime: "Sat Feb 20 2020 00:00:00 GMT-0500 (GMT-05:00)",
71+
* isRemote: true
6972
* }
7073
* }
7174
* }

tests/settings.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,28 @@ describe("PATCH settings", function() {
9999
);
100100
});
101101
});
102+
it("should succeed to make the hackathon remote", function(done) {
103+
util.auth.login(agent, Admin, (error) => {
104+
if (error) {
105+
agent.close();
106+
return done(error);
107+
}
108+
return (
109+
agent
110+
.patch(`/api/settings/`)
111+
.type("application/json")
112+
.send(util.settings.settingRemoteHackathon)
113+
// does not have password because of to stripped json
114+
.end(function(err, res) {
115+
res.should.have.status(200);
116+
res.should.be.json;
117+
res.body.should.have.property("message");
118+
res.body.message.should.equal(
119+
Constants.Success.SETTINGS_PATCH
120+
);
121+
done();
122+
})
123+
);
124+
});
125+
});
102126
});

tests/util/settings.test.util.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ const settingConfirmClosed = {
2525
confirmTime: new Date(Date.now() - 100)
2626
};
2727

28+
const settingRemoteHackathon = {
29+
openTime: new Date(Date.now() - 100),
30+
closeTime: new Date(Date.now() + 10000000000),
31+
confirmTime: new Date(Date.now() + 100000000000000),
32+
isRemote: true
33+
};
34+
2835
async function storeAll() {
2936
const toStore = new Settings(settingApplicationOpen);
3037
Settings.collection.insertOne(toStore);
@@ -61,5 +68,6 @@ module.exports = {
6168
settingApplicationNotYetOpen: settingApplicationNotYetOpen,
6269
settingApplicationOpen: settingApplicationOpen,
6370
settingApplicationClosed: settingApplicationClosed,
64-
settingConfirmClosed: settingConfirmClosed
71+
settingConfirmClosed: settingConfirmClosed,
72+
settingRemoteHackathon: settingRemoteHackathon
6573
};

0 commit comments

Comments
 (0)