Skip to content

Commit 79697fe

Browse files
authored
feat: make phone numbers optional (#673)
* feat: make phone numbers optional * docs: make phone number optional * docs: rebuild doc changes
1 parent 3cfc560 commit 79697fe

File tree

9 files changed

+4246
-4173
lines changed

9 files changed

+4246
-4173
lines changed

docs/api/api_data.js

Lines changed: 24 additions & 24 deletions
Large diffs are not rendered by default.

docs/api/api_data.json

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

docs/api/api_project.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
define({ "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-07-31T04:35:04.323Z", "url": "http://apidocjs.com", "version": "0.17.7" }});
1+
define({
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+
});

docs/api/api_project.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,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-07-31T04:35:04.323Z", "url": "http://apidocjs.com", "version": "0.17.7" }}
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+
}

middlewares/validators/account.validator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = {
1919
true
2020
),
2121
VALIDATOR.dateValidator("body", "birthDate", false),
22-
VALIDATOR.phoneNumberValidator("body", "phoneNumber", false)
22+
VALIDATOR.phoneNumberValidator("body", "phoneNumber", true)
2323
],
2424
updateAccountValidator: [
2525
VALIDATOR.stringValidator("body", "firstName", true),

models/account.model.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ const AccountSchema = new mongoose.Schema({
5151
required: true
5252
},
5353
phoneNumber: {
54-
type: Number,
55-
required: true
54+
type: Number
5655
}
5756
});
5857

routes/api/account.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ module.exports = {
7373
* @apiParam (body) {String[]} dietaryRestrictions Any dietary restrictions for the user. 'None' if there are no restrictions
7474
* @apiParam (body) {String} password The password of the account.
7575
* @apiParam (body) {String} birthDate a Date parsable string.
76-
* @apiParam (body) {Number} phoneNumber the user's phone number, represented as a string.
76+
* @apiParam (body) {Number} [phoneNumber] the user's phone number, represented as a string.
7777
* @apiParam (header) {JWT} [token] the user's invite token.
7878
*
7979
* @apiParamExample {json} Request-Example:

tests/account.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ const storedAccount3 = util.account.NonConfirmedAccount3;
3838

3939
const newAccount0 = util.account.unlinkedAccounts.new[0];
4040

41+
//This account should NOT have a phone number
42+
const noPhoneAccount = util.account.NoPhoneHackerAccount0;
43+
4144
describe("GET user account", function() {
4245
// fail on authentication
4346
it("should FAIL to list the user's account on /api/account/self GET due to authentication", function(done) {
@@ -239,6 +242,31 @@ describe("POST create account", function() {
239242
done();
240243
});
241244
});
245+
246+
it("should SUCCEED and create a new account without a phone number", function(done) {
247+
chai.request(server.app)
248+
.post('/api/account')
249+
.type('application/json')
250+
.send(noPhoneAccount)
251+
.end(function(err, res) {
252+
res.should.have.status(200);
253+
res.should.be.json;
254+
res.body.should.have.property("message");
255+
res.body.message.should.equal(Constants.Success.ACCOUNT_CREATE);
256+
257+
// use acc.toStrippedJSON to deal with hidden passwords and convert _id to id
258+
const acc = new Account(noPhoneAccount).toStrippedJSON();
259+
// delete id as those are generated
260+
delete acc.id;
261+
delete res.body.data.id;
262+
263+
chai.assert.equal(
264+
JSON.stringify(res.body.data),
265+
JSON.stringify(acc)
266+
);
267+
done();
268+
})
269+
})
242270
});
243271

244272
describe("POST confirm account", function() {

tests/util/account.test.util.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,21 @@ const NonConfirmedAccount3 = createAccount({
304304
email: "notconfirmed3@blahblah.com"
305305
});
306306

307+
const NoPhoneHackerAccount0 = {
308+
_id: mongoose.Types.ObjectId(),
309+
firstName: "LMAO",
310+
lastName: "ROFL",
311+
pronoun: "Ey/Em",
312+
gender: "Female",
313+
email: "noPhone0@blahblah.com",
314+
password: "probsShouldBeHashed5",
315+
dietaryRestrictions: ["something1", "something2"],
316+
gender: "Male",
317+
confirmed: false,
318+
birthDate: "1980-07-30",
319+
accountType: Constants.HACKER
320+
}
321+
307322
const extraAccounts = [
308323
waitlistedHacker0,
309324
NonConfirmedAccount1,
@@ -326,6 +341,7 @@ module.exports = {
326341
NonConfirmedAccount1: NonConfirmedAccount1,
327342
NonConfirmedAccount2: NonConfirmedAccount2,
328343
NonConfirmedAccount3: NonConfirmedAccount3,
344+
NoPhoneHackerAccount0: NoPhoneHackerAccount0,
329345

330346
extraAccounts: extraAccounts,
331347

0 commit comments

Comments
 (0)