From bd94949b3c632671d8e14bfc38f35a21e7426272 Mon Sep 17 00:00:00 2001 From: Wasiur Rahman Date: Tue, 24 Mar 2015 00:31:12 -0400 Subject: [PATCH] Added jshintrc and reformatted all the existing code. They look uniform now :D --- .jshintrc | 84 +++ app/otherOperations.js | 4 +- app/questionOperations.js | 77 +-- app/userOperations.js | 4 +- config/database.js | 19 +- config/passport.js | 4 +- constants.js | 60 +-- index.html | 544 +++++++++++--------- models/answer.js | 4 +- models/question.js | 14 +- models/user.js | 2 +- test/Acceptance_Tests/answer_endpoints.js | 21 +- test/Acceptance_Tests/question_endpoints.js | 48 +- test/Acceptance_Tests/user_endpoints.js | 12 +- test/Unit_Tests/utils_test.js | 2 +- utils/databaseutils.js | 7 +- views/addanswer.ejs | 18 +- views/addquestion.ejs | 65 ++- views/errorpage.ejs | 4 +- views/index.ejs | 12 +- views/listcategory.ejs | 63 ++- views/listquestions.ejs | 95 ++-- views/login.ejs | 42 +- views/navbar-loggedin.ejs | 60 +-- views/navbar-notloggedin.ejs | 30 +- views/profile.ejs | 76 +-- views/signup.ejs | 64 +-- views/viewcategories.ejs | 83 ++- views/viewquestion.ejs | 93 ++-- 29 files changed, 911 insertions(+), 700 deletions(-) create mode 100644 .jshintrc diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..d759354 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,84 @@ +{ + "maxerr" : 50, // {int} Maximum error before stopping + + // Enforcing + "bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.) + "camelcase" : false, // true: Identifiers must be in camelCase + "curly" : true, // true: Require {} for every new block or scope + "eqeqeq" : true, // true: Require triple equals (===) for comparison + "forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty() + "freeze" : true, // true: prohibits overwriting prototypes of native objects such as Array, Date etc. + "immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());` + "indent" : 4, // {int} Number of spaces to use for indentation + "latedef" : false, // true: Require variables/functions to be defined before being used + "newcap" : false, // true: Require capitalization of all constructor functions e.g. `new F()` + "noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee` + "noempty" : true, // true: Prohibit use of empty blocks + "nonbsp" : true, // true: Prohibit "non-breaking whitespace" characters. + "nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment) + "plusplus" : false, // true: Prohibit use of `++` & `--` + "quotmark" : false, // Quotation mark consistency: + // false : do nothing (default) + // true : ensure whatever is used is consistent + // "single" : require single quotes + // "double" : require double quotes + "undef" : true, // true: Require all non-global variables to be declared (prevents global leaks) + "unused" : true, // true: Require all defined variables be used + "strict" : true, // true: Requires all functions run in ES5 Strict Mode + "maxparams" : false, // {int} Max number of formal params allowed per function + "maxdepth" : false, // {int} Max depth of nested blocks (within functions) + "maxstatements" : false, // {int} Max number statements per function + "maxcomplexity" : false, // {int} Max cyclomatic complexity per function + "maxlen" : false, // {int} Max number of characters per line + + // Relaxing + "asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons) + "boss" : false, // true: Tolerate assignments where comparisons would be expected + "debug" : false, // true: Allow debugger statements e.g. browser breakpoints. + "eqnull" : false, // true: Tolerate use of `== null` + "es5" : true, // true: Allow ES5 syntax (ex: getters and setters) + "esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`) + "moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features) + // (ex: `for each`, multiple try/catch, function expression…) + "evil" : false, // true: Tolerate use of `eval` and `new Function()` + "expr" : false, // true: Tolerate `ExpressionStatement` as Programs + "funcscope" : false, // true: Tolerate defining variables inside control statements + "globalstrict" : false, // true: Allow global "use strict" (also enables 'strict') + "iterator" : false, // true: Tolerate using the `__iterator__` property + "lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block + "laxbreak" : false, // true: Tolerate possibly unsafe line breakings + "laxcomma" : false, // true: Tolerate comma-first style coding + "loopfunc" : false, // true: Tolerate functions being defined in loops + "multistr" : false, // true: Tolerate multi-line strings + "noyield" : false, // true: Tolerate generator functions with no yield statement in them. + "notypeof" : false, // true: Tolerate invalid typeof operator values + "proto" : false, // true: Tolerate using the `__proto__` property + "scripturl" : false, // true: Tolerate script-targeted URLs + "shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;` + "sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation + "supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;` + "validthis" : false, // true: Tolerate using this in a non-constructor function + + // Environments + "browser" : false, // Web Browser (window, document, etc) + "browserify" : false, // Browserify (node.js code in the browser) + "couch" : false, // CouchDB + "devel" : true, // Development/debugging (alert, confirm, etc) + "dojo" : false, // Dojo Toolkit + "jasmine" : false, // Jasmine + "jquery" : false, // jQuery + "mocha" : true, // Mocha + "mootools" : false, // MooTools + "node" : true, // Node.js + "nonstandard" : false, // Widely adopted globals (escape, unescape, etc) + "prototypejs" : false, // Prototype and Scriptaculous + "qunit" : false, // QUnit + "rhino" : false, // Rhino + "shelljs" : false, // ShellJS + "worker" : false, // Web Workers + "wsh" : false, // Windows Scripting Host + "yui" : false, // Yahoo User Interface + + // Custom Globals + "globals" : {} // additional predefined global variables +} \ No newline at end of file diff --git a/app/otherOperations.js b/app/otherOperations.js index 6c4f233..b2dc250 100644 --- a/app/otherOperations.js +++ b/app/otherOperations.js @@ -6,5 +6,5 @@ module.exports = function () { } res.json(output); }; - return { getCategories: getCategories }; -}; + return {getCategories: getCategories}; +}; \ No newline at end of file diff --git a/app/questionOperations.js b/app/questionOperations.js index 96880c9..a132b26 100644 --- a/app/questionOperations.js +++ b/app/questionOperations.js @@ -31,10 +31,15 @@ module.exports = function () { sortObject.time = -1; } - Question.find(query).sort(sortObject).skip(skip).limit(questionsPerPage).populate('asker', 'firstName _id').exec(function (err, questions) { - var output = Question.formatQuestionsList(questions); - res.json(output); - }); + Question.find(query) + .sort(sortObject) + .skip(skip) + .limit(questionsPerPage) + .populate('asker', 'firstName _id') + .exec(function (err, questions) { + var output = Question.formatQuestionsList(questions); + res.json(output); + }); }; var getQuestionById = function (req, res) { @@ -42,35 +47,36 @@ module.exports = function () { if (_.isEmpty(id)) { return res.status(400).json({error: Constants.ERROR.MISSING.QUESTION_ID}); } - Question.findById(id).populate('answers').populate('asker').exec(function (err, item) { - if (err) { - return res.status(400).json({error: Constants.ERROR.QUESTION_BY_ID}); - } else { - var currentOutput = {}; - currentOutput.questionId = item._id; - currentOutput.name = item.name; - currentOutput.description = item.text; - currentOutput.askerName = item.asker.firstName; - currentOutput.askerId = item.asker._id; - currentOutput.askerEmail = item.asker.email; - currentOutput.category = item.category; - currentOutput.numAnswers = item.answers.length; - currentOutput.answers = []; - item.answers.forEach(function (answer) { - var currentAnswer = {}; - currentAnswer.answererId = answer.answerer._id; - currentAnswer.answererName = answer.answererName; - currentAnswer.text = answer.text; - currentAnswer.answerId = answer._id; - currentAnswer.timeAnswered = answer.time; - currentOutput.answers.push(currentAnswer); - }); - currentOutput.favourites = item.favourites; - currentOutput.numVotes = item.votes; - currentOutput.timeAsked = item.time; - res.json(currentOutput); - } - }); + Question.findById(id) + .populate('answers').populate('asker').exec(function (err, item) { + if (err) { + return res.status(400).json({error: Constants.ERROR.QUESTION_BY_ID}); + } else { + var currentOutput = {}; + currentOutput.questionId = item._id; + currentOutput.name = item.name; + currentOutput.description = item.text; + currentOutput.askerName = item.asker.firstName; + currentOutput.askerId = item.asker._id; + currentOutput.askerEmail = item.asker.email; + currentOutput.category = item.category; + currentOutput.numAnswers = item.answers.length; + currentOutput.answers = []; + item.answers.forEach(function (answer) { + var currentAnswer = {}; + currentAnswer.answererId = answer.answerer._id; + currentAnswer.answererName = answer.answererName; + currentAnswer.text = answer.text; + currentAnswer.answerId = answer._id; + currentAnswer.timeAnswered = answer.time; + currentOutput.answers.push(currentAnswer); + }); + currentOutput.favourites = item.favourites; + currentOutput.numVotes = item.votes; + currentOutput.timeAsked = item.time; + res.json(currentOutput); + } + }); }; var deleteQuestionById = function (req, res) { @@ -91,7 +97,7 @@ module.exports = function () { res.status(400).json({error: Constants.ERROR.QUESTION_BY_ID}); } else { async.each(doc.answers, function (answerId, done) { - Answer.remove({_id:answerId}, done); + Answer.remove({_id: answerId}, done); }, function (err) { doc.remove(); res.status(204).send(); @@ -145,5 +151,6 @@ module.exports = function () { getQuestionSet: getQuestionSet, getQuestionById: getQuestionById, deleteQuestionById: deleteQuestionById, - postQuestion: postQuestion }; + postQuestion: postQuestion + }; }; diff --git a/app/userOperations.js b/app/userOperations.js index 899dba3..4ae0231 100644 --- a/app/userOperations.js +++ b/app/userOperations.js @@ -49,7 +49,7 @@ module.exports = function (passport) { done(); } }); - }, function(err) { + }, function (err) { if (err) return serverError(res); return res.json(out); }); @@ -97,7 +97,7 @@ module.exports = function (passport) { done(); } }); - }, function(err) { + }, function (err) { if (err) return serverError(res); return res.json(out); }); diff --git a/config/database.js b/config/database.js index efb2636..ba9b3e4 100644 --- a/config/database.js +++ b/config/database.js @@ -1,15 +1,12 @@ var mongoose = require('mongoose'); -module.exports = function(connection_string){ - - mongoose.connect(connection_string); - var db = mongoose.connection; - db.on('error', function(){ - console.log("database could not open"); +module.exports = function (connection_string) { + mongoose.connect(connection_string); + var db = mongoose.connection; + db.on('error', function () { + console.log("database could not open"); + }); + db.once('open', function callback() { + console.log("database open"); }); - db.once('open', function callback () { - console.log("database open"); - }); - - }; \ No newline at end of file diff --git a/config/passport.js b/config/passport.js index 6d33577..7333387 100644 --- a/config/passport.js +++ b/config/passport.js @@ -45,7 +45,7 @@ module.exports = function (passport) { // find a user whose email is the same as the forms email // we are checking to see if the user trying to login already exists - User.findOne({ 'email': email }, function (err, user) { + User.findOne({'email': email}, function (err, user) { console.log("db query done"); // if there are any errors, return the error if (err) { @@ -90,7 +90,7 @@ module.exports = function (passport) { email = email.toLowerCase(); // find a user whose email is the same as the forms email // we are checking to see if the user trying to login already exists - User.findOne({ 'email': email }, function (err, user) { + User.findOne({'email': email}, function (err, user) { // if there are any errors, return the error before anything else if (err) return done(err); diff --git a/constants.js b/constants.js index 5f8dc9e..9ec6a87 100644 --- a/constants.js +++ b/constants.js @@ -1,38 +1,38 @@ exports.ERROR = { - MISSING: { - TOKEN: "Please provide a valid access token", - QUESTION_ID: "Please provide 'questionId' property.", - QUESTION_TITLE: "Please provide 'questionTitle' property.", - QUESTION_DESCRIPTION: "Please provide 'questionDescription' property.", - QUESTION_CATEGORY: "Please provide 'categoryIndex' property.", - ANSWER_BODY: "Please provide 'answerBody' property.", - EMAIL: "Please provide an email", - PASSWORD: "Please provide a password", - FIRST_NAME: "Please provide a firstName." - }, - INVALID: { - TOKEN: "Unauthorized. Invalid token.", - EMAIL_OR_PASSWORD: "Invalid email or password", - HTTP_METHOD: "Invalid HTTP method or path, please refer to the API Documentation." - }, - SAVE: { - ANSWER: "Could not save answer.", - QUESTION: "Could not save question.", - USER: "Could not save user." - }, - QUESTION_BY_ID: "Could not find question. Please form your requests like the following: api/question/QUESTION_ID", - EMAIL_IN_USE: "The provided email is already in use", - FEATURE_NOT_IMPLEMENTED: "This feature is not yet implemented." + MISSING: { + TOKEN: "Please provide a valid access token", + QUESTION_ID: "Please provide 'questionId' property.", + QUESTION_TITLE: "Please provide 'questionTitle' property.", + QUESTION_DESCRIPTION: "Please provide 'questionDescription' property.", + QUESTION_CATEGORY: "Please provide 'categoryIndex' property.", + ANSWER_BODY: "Please provide 'answerBody' property.", + EMAIL: "Please provide an email", + PASSWORD: "Please provide a password", + FIRST_NAME: "Please provide a firstName." + }, + INVALID: { + TOKEN: "Unauthorized. Invalid token.", + EMAIL_OR_PASSWORD: "Invalid email or password", + HTTP_METHOD: "Invalid HTTP method or path, please refer to the API Documentation." + }, + SAVE: { + ANSWER: "Could not save answer.", + QUESTION: "Could not save question.", + USER: "Could not save user." + }, + QUESTION_BY_ID: "Could not find question. Please form your requests like the following: api/question/QUESTION_ID", + EMAIL_IN_USE: "The provided email is already in use", + FEATURE_NOT_IMPLEMENTED: "This feature is not yet implemented." }; exports.SUCCESS = { - SAVE: { - ANSWER: "Successfully saved answer.", - QUESTION: "Successfully saved question.", - USER: "Successfully saved user." - } + SAVE: { + ANSWER: "Successfully saved answer.", + QUESTION: "Successfully saved question.", + USER: "Successfully saved user." + } }; exports.URLS = { - API_DOC: "http://docs.waterlooanswers.apiary.io/" + API_DOC: "http://docs.waterlooanswers.apiary.io/" } \ No newline at end of file diff --git a/index.html b/index.html index ae6727a..983db55 100644 --- a/index.html +++ b/index.html @@ -1,226 +1,268 @@ - - - Welcome to OpenShift - - + + + Welcome to OpenShift + +
-
-

Welcome to your Node.js application on OpenShift

-
+
+

Welcome to your Node.js application on OpenShift

+
-
-
+
+
-

Deploying code changes

-

OpenShift uses the Git version control system for your source code, and grants you access to it via the Secure Shell (SSH) protocol. In order to upload and download code to your application you need to give us your public SSH key. You can upload it within the web console or install the RHC command line tool and run rhc setup to generate and upload your key automatically.

- +

Deploying code changes

+ +

OpenShift uses the Git version control system for your source code, + and grants you access to it via the Secure Shell (SSH) protocol. In order to upload and download + code to your application you need to give us your public SSH key. You can upload + it within the web console or install the RHC command line + tool and run rhc setup to generate and upload your key automatically.

+

Working in your local Git repository

-

If you created your application from the command line and uploaded your SSH key, rhc will automatically download a copy of that source code repository (Git calls this 'cloning') to your local system.

-

If you created the application from the web console, you'll need to manually clone the repository to your local system. Copy the application's source code Git URL and then run:

+

If you created your application from the command line and uploaded your SSH key, rhc will + automatically download a copy of that source code repository (Git calls this 'cloning') to your + local system.

+ +

If you created the application from the web console, you'll need to manually clone the repository to + your local system. Copy the application's source code Git URL and then run:

$ git clone <git_url> <directory_to_create>
 
@@ -231,42 +273,52 @@ 

Working in your local Git repository

$ git push
- +
- - -
-
- -

Managing your application

- -

Web Console

-

You can use the OpenShift web console to enable additional capabilities via cartridges, add collaborator access authorizations, designate custom domain aliases, and manage domain memberships.

- -

Command Line Tools

-

Installing the OpenShift RHC client tools allows you complete control of your cloud environment. Read more on how to manage your application from the command line in our User Guide. -

- -

Development Resources

- - -
-
- - -
- -
+ + +
+
+ +

Managing your application

+ +

Web Console

+ +

You can use the OpenShift web console to enable additional capabilities via cartridges, add collaborator + access authorizations, designate custom domain aliases, and manage domain memberships.

+ +

Command Line Tools

+ +

Installing the OpenShift RHC + client tools allows you complete control of your cloud environment. Read more on how to manage your + application from the command line in our User Guide. +

+ +

Development Resources

+ + +
+
+ + +
+ +
diff --git a/models/answer.js b/models/answer.js index 0fe9530..9a3d014 100644 --- a/models/answer.js +++ b/models/answer.js @@ -11,10 +11,10 @@ var answerSchema = mongoose.Schema({ {type: mongoose.Schema.Types.ObjectId, ref: 'User'} ], text: String, - time: { type: Date, default: Date.now } + time: {type: Date, default: Date.now} }); -answerSchema.statics.format = function(answer, done) { +answerSchema.statics.format = function (answer, done) { var out = {}; Question.findOne({answers: answer._id}, function (err, questionAnswered) { if (err || !questionAnswered) { diff --git a/models/question.js b/models/question.js index 09d1a52..90d2fff 100644 --- a/models/question.js +++ b/models/question.js @@ -7,14 +7,14 @@ global.questionCategories = [ ]; var questionSchema = mongoose.Schema({ - asker: {type: mongoose.Schema.Types.ObjectId, ref: 'User'}, - name: String, - favourites: [{type: mongoose.Schema.Types.ObjectId, ref: 'User'}], - text: String, - time : { type : Date, default: Date.now }, - answers: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Answer' }], + asker: {type: mongoose.Schema.Types.ObjectId, ref: 'User'}, + name: String, + favourites: [{type: mongoose.Schema.Types.ObjectId, ref: 'User'}], + text: String, + time: {type: Date, default: Date.now}, + answers: [{type: mongoose.Schema.Types.ObjectId, ref: 'Answer'}], viewers: [ - { type: mongoose.Schema.Types.ObjectId, ref: 'User' } + {type: mongoose.Schema.Types.ObjectId, ref: 'User'} ], category: {type: String, enum: global.questionCategories} }); diff --git a/models/user.js b/models/user.js index 250a97e..5e7830e 100644 --- a/models/user.js +++ b/models/user.js @@ -9,7 +9,7 @@ var userSchema = mongoose.Schema({ password: String, graduationYear: Number, program: String, - dateCreated: { type: Date, default: Date.now } + dateCreated: {type: Date, default: Date.now} }); // generating a hash diff --git a/test/Acceptance_Tests/answer_endpoints.js b/test/Acceptance_Tests/answer_endpoints.js index b387b05..8227489 100644 --- a/test/Acceptance_Tests/answer_endpoints.js +++ b/test/Acceptance_Tests/answer_endpoints.js @@ -16,7 +16,7 @@ describe('Answer Endpoints', function () { var question; var user; before(function (done) { - Answer.remove({}, function(err) { + Answer.remove({}, function (err) { dbUtils.createTestUser("email", "password", "firstName", function (newUser) { user = newUser; dbUtils.createQuestion("title", "description", user._id, 1, function (doc) { @@ -28,7 +28,7 @@ describe('Answer Endpoints', function () { }); after(function (done) { dbUtils.clearUserCollection(function () { - dbUtils.clearQuestionCollection(function() { + dbUtils.clearQuestionCollection(function () { Answer.remove({}, done); }); }); @@ -46,13 +46,20 @@ describe('Answer Endpoints', function () { }); }); it("should not post if missing token", function (done) { - request(app).post('/api/answers').send({questionId: "someId", answerBody: "description"}).expect(400).end(function (err, res) { + request(app).post('/api/answers').send({ + questionId: "someId", + answerBody: "description" + }).expect(400).end(function (err, res) { res.body.error.should.equal(Constants.ERROR.MISSING.TOKEN); done(); }); }); it("should not post if invalid token", function (done) { - request(app).post('/api/answers').send({questionId: "someId", answerBody: "description", token: "blahblahblah"}).expect(401).end(function (err, res) { + request(app).post('/api/answers').send({ + questionId: "someId", + answerBody: "description", + token: "blahblahblah" + }).expect(401).end(function (err, res) { res.body.error.should.equal(Constants.ERROR.INVALID.TOKEN); done(); }); @@ -60,7 +67,11 @@ describe('Answer Endpoints', function () { it("should post answer if given valid info", function (done) { var token = jwt.encode({userId: user._id}, "testsecret"); token.should.not.be.empty; - request(app).post('/api/answers').send({questionId: question._id, answerBody: "description", token: token}).expect(200).end(function (err, res) { + request(app).post('/api/answers').send({ + questionId: question._id, + answerBody: "description", + token: token + }).expect(200).end(function (err, res) { console.log(res.body); res.body.question.should.exist; res.body.question.answers.should.not.be.empty; diff --git a/test/Acceptance_Tests/question_endpoints.js b/test/Acceptance_Tests/question_endpoints.js index 3b17d17..1261c77 100644 --- a/test/Acceptance_Tests/question_endpoints.js +++ b/test/Acceptance_Tests/question_endpoints.js @@ -16,7 +16,7 @@ describe('Question Endpoints', function () { describe("POST /questions", function () { var user; before(function (done) { - Question.remove({}, function() { + Question.remove({}, function () { dbUtils.createTestUser("email", "password", "firstName", function (newUser) { user = newUser; done(); @@ -41,19 +41,31 @@ describe('Question Endpoints', function () { }); }); it("should not post if missing categoryIndex", function (done) { - request(app).post('/api/questions').send({questionTitle: "title", questionDescription: "description"}).expect(400).end(function (err, res) { + request(app).post('/api/questions').send({ + questionTitle: "title", + questionDescription: "description" + }).expect(400).end(function (err, res) { res.body.error.should.equal(Constants.ERROR.MISSING.QUESTION_CATEGORY); done(); }); }); it("should not post if missing token", function (done) { - request(app).post('/api/questions').send({questionTitle: "title", questionDescription: "description", categoryIndex: 2}).expect(400).end(function (err, res) { + request(app).post('/api/questions').send({ + questionTitle: "title", + questionDescription: "description", + categoryIndex: 2 + }).expect(400).end(function (err, res) { res.body.error.should.equal(Constants.ERROR.MISSING.TOKEN); done(); }); }); it("should not post if invalid token", function (done) { - request(app).post('/api/questions').send({questionTitle: "title", questionDescription: "description", categoryIndex: 2, token: "blahblahblah"}).expect(400).end(function (err, res) { + request(app).post('/api/questions').send({ + questionTitle: "title", + questionDescription: "description", + categoryIndex: 2, + token: "blahblahblah" + }).expect(400).end(function (err, res) { res.body.error.should.equal(Constants.ERROR.INVALID.TOKEN); done(); }); @@ -61,7 +73,12 @@ describe('Question Endpoints', function () { it("should post question if given valid info", function (done) { var token = jwt.encode({userId: user._id}, "testsecret"); token.should.not.be.empty; - request(app).post('/api/questions').send({questionTitle: "title", questionDescription: "description", categoryIndex: 2, token: token}).expect(200).end(function (err, res) { + request(app).post('/api/questions').send({ + questionTitle: "title", + questionDescription: "description", + categoryIndex: 2, + token: token + }).expect(200).end(function (err, res) { res.body.result.should.equal(Constants.SUCCESS.SAVE.QUESTION); Question.find({}, function (err, docs) { should.not.exist(err); @@ -121,8 +138,8 @@ describe('Question Endpoints', function () { var user; var answer; before(function (done) { - Answer.remove({}, function() { - dbUtils.createTestUser("email", "password", "firstName", function (newUser) { + Answer.remove({}, function () { + dbUtils.createTestUser("email", "password", "firstName", function (newUser) { user = newUser; dbUtils.createQuestion("title", "description", user._id, 1, function (doc) { question = doc; @@ -142,7 +159,7 @@ describe('Question Endpoints', function () { }); after(function (done) { dbUtils.clearUserCollection(function () { - dbUtils.clearQuestionCollection(function() { + dbUtils.clearQuestionCollection(function () { Answer.remove({}, done); }); }); @@ -158,7 +175,10 @@ describe('Question Endpoints', function () { }); }); it("should not delete if invalid token", function (done) { - request(app).delete('/api/questions').send({id: "blah", token: "blahblahblah"}).expect(401).end(function (err, res) { + request(app).delete('/api/questions').send({ + id: "blah", + token: "blahblahblah" + }).expect(401).end(function (err, res) { res.body.error.should.equal(Constants.ERROR.INVALID.TOKEN); Question.find({}, function (err, docs) { should.not.exist(err); @@ -168,7 +188,10 @@ describe('Question Endpoints', function () { }); }); it("should not delete if invalid id", function (done) { - request(app).delete('/api/questions').send({id: "blah", token: jwt.encode({userId: user._id}, "testsecret")}).expect(400).end(function (err, res) { + request(app).delete('/api/questions').send({ + id: "blah", + token: jwt.encode({userId: user._id}, "testsecret") + }).expect(400).end(function (err, res) { res.body.error.should.equal(Constants.ERROR.QUESTION_BY_ID); Question.find({}, function (err, docs) { should.not.exist(err); @@ -184,7 +207,10 @@ describe('Question Endpoints', function () { Answer.find({}, function (err, answers) { should.not.exist(err); answers.length.should.equal(1); - request(app).delete('/api/questions').send({id: question._id, token: jwt.encode({userId: user._id}, "testsecret")}).expect(204).end(function (err, res) { + request(app).delete('/api/questions').send({ + id: question._id, + token: jwt.encode({userId: user._id}, "testsecret") + }).expect(204).end(function (err, res) { Question.find({}, function (err, docs) { should.not.exist(err); docs.length.should.equal(0); diff --git a/test/Acceptance_Tests/user_endpoints.js b/test/Acceptance_Tests/user_endpoints.js index db0c09d..9487ba8 100644 --- a/test/Acceptance_Tests/user_endpoints.js +++ b/test/Acceptance_Tests/user_endpoints.js @@ -115,19 +115,19 @@ describe('User Endpoints', function () { }); }); }); - it ('should give missing token error if missing token', function (done) { + it('should give missing token error if missing token', function (done) { request(app).get('/api/user').expect(400).end(function (err, res) { res.body.error.should.equal(Constants.ERROR.MISSING.TOKEN); done(); }); }); - it ('should give invalid token error if token is invalid', function (done) { + it('should give invalid token error if token is invalid', function (done) { request(app).get('/api/user?token=blahoo').expect(400).end(function (err, res) { res.body.error.should.equal(Constants.ERROR.INVALID.TOKEN); done(); }); }); - it ('should give user if valid token', function (done) { + it('should give user if valid token', function (done) { request(app).get('/api/user?token=' + token).expect(400).end(function (err, res) { Date.parse(res.body.dateJoined).should.equal(user.dateCreated.getTime()); res.body.email.should.equal("testemail"); @@ -182,19 +182,19 @@ describe('User Endpoints', function () { }); }); }); - it ('should give missing token error if missing token', function (done) { + it('should give missing token error if missing token', function (done) { request(app).get('/api/user/' + user._id).expect(400).end(function (err, res) { res.body.error.should.equal(Constants.ERROR.MISSING.TOKEN); done(); }); }); - it ('should give invalid token error if token is invalid', function (done) { + it('should give invalid token error if token is invalid', function (done) { request(app).get('/api/user?token=blahoo').expect(400).end(function (err, res) { res.body.error.should.equal(Constants.ERROR.INVALID.TOKEN); done(); }); }); - it ('should give user if valid id and token', function (done) { + it('should give user if valid id and token', function (done) { request(app).get('/api/user/' + user._id + '?token=' + token).expect(400).end(function (err, res) { Date.parse(res.body.dateJoined).should.equal(user.dateCreated.getTime()); res.body.email.should.equal("testemail"); diff --git a/test/Unit_Tests/utils_test.js b/test/Unit_Tests/utils_test.js index 4ae9749..0cc0bc4 100644 --- a/test/Unit_Tests/utils_test.js +++ b/test/Unit_Tests/utils_test.js @@ -27,7 +27,7 @@ describe('lodash', function () { describe('tokenutils', function () { describe('generateTokenFromUser', function () { - it('should encode user id in token', function() { + it('should encode user id in token', function () { var user = new User({firstName: "John", email: "john@uwaterloo.ca", password: "password"}); var token = tokenUtils.generateTokenFromUser(user); var claims = jwt.decode(token, "testsecret"); diff --git a/utils/databaseutils.js b/utils/databaseutils.js index 78afc5b..0601c5f 100644 --- a/utils/databaseutils.js +++ b/utils/databaseutils.js @@ -19,7 +19,12 @@ exports.createTestUser = function (email, password, firstName, done) { }; exports.createQuestion = function (questionTitle, text, askerId, categoryIndex, done) { - var q1 = new Question({name: questionTitle, text: text, asker: askerId, category: global.questionCategories[categoryIndex]}); + var q1 = new Question({ + name: questionTitle, + text: text, + asker: askerId, + category: global.questionCategories[categoryIndex] + }); q1.save(function (err, question) { if (err) { console.log(err); diff --git a/views/addanswer.ejs b/views/addanswer.ejs index 061e82f..8a62230 100644 --- a/views/addanswer.ejs +++ b/views/addanswer.ejs @@ -9,18 +9,18 @@ <% include navbar-loggedin %>
- -

<%=question.text%>

+ +

<%= question.text %>

-

Your Answer:

-
- "> -
- -
+

Your Answer:

-
+
+ "> +
+ +
+ diff --git a/views/addquestion.ejs b/views/addquestion.ejs index 05d6658..8e30844 100644 --- a/views/addquestion.ejs +++ b/views/addquestion.ejs @@ -6,55 +6,52 @@ - <% include navbar-loggedin %> - -
+<% include navbar-loggedin %> +
-
- -
-
- - + <% cats.forEach(function(entry){ %> - <% });%> - -
- - - - -
-
+ <% }); %> + +
+ + + + + +
- - - diff --git a/views/errorpage.ejs b/views/errorpage.ejs index 826e6d2..5e96b26 100644 --- a/views/errorpage.ejs +++ b/views/errorpage.ejs @@ -13,8 +13,10 @@

I couldn't find your page! Go blame Sahil...



+

- Go Back

+ Go Back

\ No newline at end of file diff --git a/views/index.ejs b/views/index.ejs index 9b34148..932905b 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -5,13 +5,13 @@ - <% include navbar-loggedin %> +<% include navbar-loggedin %> -
-

ask

-

answer

- -
+
+

ask

+

answer

+ +
diff --git a/views/listcategory.ejs b/views/listcategory.ejs index 7e1f291..2a3787e 100644 --- a/views/listcategory.ejs +++ b/views/listcategory.ejs @@ -3,11 +3,11 @@ Hey - + @@ -15,27 +15,40 @@ <% include navbar-loggedin %>
- -
-
- -
-
-
+ +
+
+
    + <% questions.forEach(function(entry){ %> +
  • + + <% if(entry.answers[0]){ %> + <%= entry.answers.length %> + <% }else{ %> + 0 + <% } %> + +

    <%= entry["name"] %>

    +

    <%= entry.text %>

    - - - + +
  • + <% }); %> +
+
+
+ + + + + + \ No newline at end of file diff --git a/views/listquestions.ejs b/views/listquestions.ejs index c814040..babff1a 100644 --- a/views/listquestions.ejs +++ b/views/listquestions.ejs @@ -3,47 +3,62 @@ Questions - + - <% include navbar-loggedin %> - -
- - -
-
- -
- -
-
-
- - - - - - - \ No newline at end of file +<% include navbar-loggedin %> + +
+ + +
+
+ +
+ +
+
+
+ + + + + + + \ No newline at end of file diff --git a/views/login.ejs b/views/login.ejs index b7f9bfd..21f37eb 100644 --- a/views/login.ejs +++ b/views/login.ejs @@ -11,35 +11,35 @@
-
+
-

Login

+

Login

- - <% if (message.length > 0) { %> + + <% if (message.length > 0) { %>
<%= message %>
- <% } %> + <% } %> - -
-
- - -
-
- - -
+ + +
+ + +
+
+ + +
- -
+ + -
+
-

Need an account? Signup

- +

Need an account? Signup

-
+ +
diff --git a/views/navbar-loggedin.ejs b/views/navbar-loggedin.ejs index b66777c..bbcc726 100644 --- a/views/navbar-loggedin.ejs +++ b/views/navbar-loggedin.ejs @@ -1,31 +1,31 @@ - \ No newline at end of file diff --git a/views/navbar-notloggedin.ejs b/views/navbar-notloggedin.ejs index a105d09..1b43b90 100644 --- a/views/navbar-notloggedin.ejs +++ b/views/navbar-notloggedin.ejs @@ -1,17 +1,17 @@ \ No newline at end of file diff --git a/views/profile.ejs b/views/profile.ejs index 16095fb..396b8b4 100644 --- a/views/profile.ejs +++ b/views/profile.ejs @@ -10,47 +10,49 @@
-
-

<%= user.firstName %>

-
- -
-
    Email: <%= user.email %> -
-
    Joined: -
- <% if (questions.length != 0) {%> -
    Questions asked:
    -
    - <% questions.forEach(function(entry){ %> - <%= entry.name %>
    - <%});%> -
    -
- <% } %> - <% if (answers.length != 0){ %> - - <%}%> -
- -
-
+
+

<%= user.firstName %>

+
+ +
+
    Email: <%= user.email %> +
+
    Joined: +
+ <% if (questions.length != 0) { %> +
    Questions asked:
    + +
    + <% questions.forEach(function(entry){ %> + <%= entry.name %>
    + <% }); %> +
    +
+ <% } %> + <% if (answers.length != 0){ %> + + <% } %> +
+ +
+
- + \ No newline at end of file diff --git a/views/signup.ejs b/views/signup.ejs index b1d9cbd..f38db3f 100644 --- a/views/signup.ejs +++ b/views/signup.ejs @@ -3,8 +3,10 @@ Sign Up - - + + + + @@ -13,38 +15,38 @@
-
+
-

Signup

+

Signup

- - <% if (message.length > 0) { %> + + <% if (message.length > 0) { %>
<%= message %>
- <% } %> - - -
-
- - -
-
- - -
-
- - -
- - -
- -
- -

Already have an account? Login

- -
+ <% } %> + + +
+
+ + +
+
+ + +
+
+ + +
+ + +
+ +
+ +

Already have an account? Login

+ +
diff --git a/views/viewcategories.ejs b/views/viewcategories.ejs index 58293a5..791e97d 100644 --- a/views/viewcategories.ejs +++ b/views/viewcategories.ejs @@ -1,52 +1,49 @@ - - - - Questions - - + Questions + + - <% include navbar-loggedin %> - -
- - -
-
- -
- -
    - <% categories.forEach(function(entry){ %> -
  • -

    <%= entry%>

    -
  • - <%}); %> -
-
-
-
- - - - - +<% include navbar-loggedin %> + +
+ + +
+
+ +
+ +
    + <% categories.forEach(function(entry){ %> +
  • +

    <%= entry %>

    +
  • + <% }); %> +
+
+
+
+ + + + + \ No newline at end of file diff --git a/views/viewquestion.ejs b/views/viewquestion.ejs index e6df9bb..b2f16ef 100644 --- a/views/viewquestion.ejs +++ b/views/viewquestion.ejs @@ -3,75 +3,76 @@ Hey - + <% include navbar-loggedin %>
-<% if (message.length > 0) { %> + <% if (message.length > 0) { %>
<%= message %>
-<% } %> + <% } %> -
-
-

<%=question.name%>

-
-
- <%=question.text%> -
- -
-
+
+
+

<%= question.name %>

+
+
+ <%= question.text %> +
+ +
+
- -<% if(question.answers[0]){ - question.answers.forEach(function(entry){%> -
-
- <%= entry.text%> -
- -
- <%});%> -<% }else{ %> - No answers yet. -<% } %> - + <% if(question.answers[0]){ + question.answers.forEach(function(entry){ %> +
+
+ <%= entry.text %> +
+ +
+ <% }); %> + <% }else{ %> + No answers yet. + <% } %> -

Your Answer:

+

Your Answer:

-
- "> -
- -
+
+ "> +
+ +
- - + \ No newline at end of file