From cf8153fd938b45e82277308a8705dcd1fb5689b9 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 26 Mar 2016 09:20:47 -0500 Subject: [PATCH] chore: Update res.send(code) to res.sendStatus(code) --- test/server_side/controllers/groups.test.js | 12 ++++++------ test/server_side/controllers/user.test.js | 8 ++++---- website/src/controllers/api-v2/auth.js | 10 +++++----- website/src/controllers/api-v2/challenges.js | 6 +++--- website/src/controllers/api-v2/coupon.js | 2 +- website/src/controllers/api-v2/groups.js | 18 +++++++++--------- website/src/controllers/api-v2/members.js | 4 ++-- website/src/controllers/api-v2/user.js | 6 +++--- website/src/controllers/payments/amazon.js | 14 +++++++------- website/src/controllers/payments/index.js | 2 +- website/src/controllers/payments/paypal.js | 2 +- website/src/controllers/payments/stripe.js | 6 +++--- website/src/middlewares/cors.js | 2 +- 13 files changed, 46 insertions(+), 46 deletions(-) diff --git a/test/server_side/controllers/groups.test.js b/test/server_side/controllers/groups.test.js index 2dd69c2a87..353fb581fe 100644 --- a/test/server_side/controllers/groups.test.js +++ b/test/server_side/controllers/groups.test.js @@ -40,7 +40,7 @@ describe('Groups Controller', function() { user: user }, json: sinon.stub(), - send: sinon.stub() + sendStatus: sinon.stub() }; req = { @@ -166,7 +166,7 @@ describe('Groups Controller', function() { user: user }, json: sinon.stub(), - send: sinon.stub() + sendStatus: sinon.stub() }; req = { @@ -294,7 +294,7 @@ describe('Groups Controller', function() { user: user }, json: sinon.stub(), - send: sinon.stub() + sendStatus: sinon.stub() }; req = { }; @@ -387,8 +387,8 @@ describe('Groups Controller', function() { it('sends back 204 on success', function() { groupsController.questLeave(req, res); - expect(res.send).to.be.calledOnce; - expect(res.send).to.be.calledWith(204); + expect(res.sendStatus).to.be.calledOnce; + expect(res.sendStatus).to.be.calledWith(204); }); }); }); @@ -408,7 +408,7 @@ describe('Groups Controller', function() { user: user, group: group }, - send: sinon.stub() + sendStatus: sinon.stub() }; req = { query: { diff --git a/test/server_side/controllers/user.test.js b/test/server_side/controllers/user.test.js index a000c0cde1..2be7f7215a 100644 --- a/test/server_side/controllers/user.test.js +++ b/test/server_side/controllers/user.test.js @@ -579,8 +579,8 @@ describe('User Controller', function() { it('sends back 204', function() { userController.addTenGems(req, res); - expect(res.send).to.be.calledOnce; - expect(res.send).to.be.calledWith(204); + expect(res.sendStatus).to.be.calledOnce; + expect(res.sendStatus).to.be.calledWith(204); }); }); @@ -610,8 +610,8 @@ describe('User Controller', function() { it('sends back 204', function() { userController.addHourglass(req, res); - expect(res.send).to.be.calledOnce; - expect(res.send).to.be.calledWith(204); + expect(res.sendStatus).to.be.calledOnce; + expect(res.sendStatus).to.be.calledWith(204); }); }); }); diff --git a/website/src/controllers/api-v2/auth.js b/website/src/controllers/api-v2/auth.js index 7e838097b5..0cad77e122 100644 --- a/website/src/controllers/api-v2/auth.js +++ b/website/src/controllers/api-v2/auth.js @@ -241,7 +241,7 @@ api.deleteSocial = function(req,res,next){ //res.locals.user.auth.save(function(err, saved){ User.update({_id:res.locals.user._id}, {$unset:{'auth.facebook':1}}, function(err){ if (err) return next(err); - res.send(200); + res.sendStatus(200); }) } @@ -255,7 +255,7 @@ api.resetPassword = function(req, res, next){ User.findOne({'auth.local.email': email}, function(err, user){ if (err) return next(err); - if (!user) return res.send(401, {err:"Sorry, we can't find a user registered with email " + email + "\n- Make sure your email address is typed correctly.\n- You may have signed up with Facebook, not email. Double-check by trying Facebook login."}); + if (!user) return res.status(401).json({err:"Sorry, we can't find a user registered with email " + email + "\n- Make sure your email address is typed correctly.\n- You may have signed up with Facebook, not email. Double-check by trying Facebook login."}); user.auth.local.salt = salt; user.auth.local.hashed_password = hashed_password; utils.sendEmail({ @@ -300,7 +300,7 @@ api.changeUsername = function(req, res, next) { } ], function(err){ if (err) return err.code ? res.json(err.code, err) : next(err); - res.send(200); + res.sendStatus(200); }) } @@ -320,7 +320,7 @@ api.changeEmail = function(req, res, next){ } ], function(err){ if (err) return err.code ? res.json(err.code,err) : next(err); - res.send(200); + res.sendStatus(200); }) } @@ -343,7 +343,7 @@ api.changePassword = function(req, res, next) { user.auth.local.hashed_password = hashed_new_password; user.save(function(err, saved){ if (err) next(err); - res.send(200); + res.sendStatus(200); }) }; diff --git a/website/src/controllers/api-v2/challenges.js b/website/src/controllers/api-v2/challenges.js index 72f28d9f3d..c80865799c 100644 --- a/website/src/controllers/api-v2/challenges.js +++ b/website/src/controllers/api-v2/challenges.js @@ -316,7 +316,7 @@ api.delete = function(req, res, next){ } ], function(err){ if (err) return next(err); - res.send(200); + res.sendStatus(200); user = cid = null; }); } @@ -359,7 +359,7 @@ api.selectWinner = function(req, res, next) { } ], function(err){ if (err) return next(err); - res.send(200); + res.sendStatus(200); user = cid = chal = null; }) } @@ -439,7 +439,7 @@ api.unlink = function(req, res, next) { return res.json(400, {err: 'Provide unlink method as ?keep=keep-all (keep, keep-all, remove, remove-all)'}); user.unlink({cid:cid, keep:req.query.keep, tid:tid}, function(err, saved){ if (err) return next(err); - res.send(200); + res.sendStatus(200); user = tid = cid = null; }); } diff --git a/website/src/controllers/api-v2/coupon.js b/website/src/controllers/api-v2/coupon.js index c6811037e5..fa8c9365b0 100644 --- a/website/src/controllers/api-v2/coupon.js +++ b/website/src/controllers/api-v2/coupon.js @@ -12,7 +12,7 @@ api.ensureAdmin = function(req, res, next) { api.generateCoupons = function(req,res,next) { Coupon.generate(req.params.event, req.query.count, function(err){ if(err) return next(err); - res.send(200); + res.sendStatus(200); }); } diff --git a/website/src/controllers/api-v2/groups.js b/website/src/controllers/api-v2/groups.js index b4162558cf..b446a8481a 100644 --- a/website/src/controllers/api-v2/groups.js +++ b/website/src/controllers/api-v2/groups.js @@ -246,7 +246,7 @@ api.update = function(req, res, next) { if (err) return next(err); firebase.updateGroupData(saved); - res.send(204); + res.sendStatus(204); }); } @@ -331,7 +331,7 @@ api.deleteChatMessage = function(req, res, next){ Group.update({_id:group._id}, {$pull:{chat:{id: req.params.messageId}}}, function(err){ if(err) return next(err); - chatUpdated ? res.json({chat: group.chat}) : res.send(204); + chatUpdated ? res.json({chat: group.chat}) : res.sendStatus(204); group = chatUpdated = null; }); } @@ -397,7 +397,7 @@ api.flagChatMessage = function(req, res, next){ {name: "GROUP_URL", content: group._id == 'habitrpg' ? '/#/options/groups/tavern' : (group.type === 'guild' ? ('/#/options/groups/guilds/' + group._id) : 'party')}, ]); - return res.send(204); + return res.sendStatus(204); }); }); } @@ -416,7 +416,7 @@ api.clearFlagCount = function(req, res, next){ 'chat.$.flagCount': message.flagCount, }}, function(err) { if(err) return next(err); - return res.send(204); + return res.sendStatus(204); }); } else { return res.json(401, {err: shared.i18n.t('messageGroupChatAdminClearFlagCount')}) @@ -431,7 +431,7 @@ api.seenMessage = function(req,res,next){ update['$unset']['newMessages.'+req.params.gid] = ''; User.update({_id:req.headers['x-api-user'], apiToken:req.headers['x-api-key']},update).exec(); } - res.send(200); + res.sendStatus(200); } api.likeChatMessage = function(req, res, next) { @@ -535,7 +535,7 @@ api.leave = function(req, res, next) { if (err) return next(err); user = group = keep = null; - return res.send(204); + return res.sendStatus(204); }); }; @@ -760,7 +760,7 @@ api.removeMember = function(req, res, next){ // Sending an empty 204 because Group.update doesn't return the group // see http://mongoosejs.com/docs/api.html#model_Model.update group = uuid = null; - return res.send(204); + return res.sendStatus(204); }); }); }else if(_.contains(group.invites, uuid)){ @@ -788,7 +788,7 @@ api.removeMember = function(req, res, next){ // see http://mongoosejs.com/docs/api.html#model_Model.update sendMessage(invited); group = uuid = null; - return res.send(204); + return res.sendStatus(204); }); }); @@ -1095,7 +1095,7 @@ api.questLeave = function(req, res, next) { Q.all([groupSavePromise(), userSavePromise()]) .done(function(values) { - return res.send(204); + return res.sendStatus(204); }, function(error) { return next(error); }); diff --git a/website/src/controllers/api-v2/members.js b/website/src/controllers/api-v2/members.js index a511634ff7..76b686dd95 100644 --- a/website/src/controllers/api-v2/members.js +++ b/website/src/controllers/api-v2/members.js @@ -85,7 +85,7 @@ api.sendPrivateMessage = function(req, res, next){ ]); } - res.send(200); + res.sendStatus(200); }) } @@ -129,6 +129,6 @@ api.sendGift = function(req, res, next){ } ], function(err) { if (err) return sendErr(err, res, next); - res.send(200); + res.sendStatus(200); }); } diff --git a/website/src/controllers/api-v2/user.js b/website/src/controllers/api-v2/user.js index d06bb96288..97f1a22776 100644 --- a/website/src/controllers/api-v2/user.js +++ b/website/src/controllers/api-v2/user.js @@ -430,7 +430,7 @@ api.delete = function(req, res, next) { if(err) return next(err); firebase.deleteUser(user._id); - res.send(200); + res.sendStatus(200); }); }); }); @@ -450,7 +450,7 @@ if (nconf.get('NODE_ENV') === 'development') { user.save(function(err){ if (err) return next(err); - res.send(204); + res.sendStatus(204); }); }; @@ -461,7 +461,7 @@ if (nconf.get('NODE_ENV') === 'development') { user.save(function(err){ if (err) return next(err); - res.send(204); + res.sendStatus(204); }); }; } diff --git a/website/src/controllers/payments/amazon.js b/website/src/controllers/payments/amazon.js index dcbe9e9e2a..04de88cec5 100644 --- a/website/src/controllers/payments/amazon.js +++ b/website/src/controllers/payments/amazon.js @@ -24,8 +24,8 @@ exports.verifyAccessToken = function(req, res, next){ amzPayment.api.getTokenInfo(req.body['access_token'], function(err, tokenInfo){ if(err) return res.json(400, {err:err}); - - res.send(200); + + res.sendStatus(200); }); }; @@ -141,7 +141,7 @@ exports.checkout = function(req, res, next){ }, function(err, results){ if(err) return next(err); - res.send(200); + res.sendStatus(200); }); }; @@ -229,7 +229,7 @@ exports.subscribe = function(req, res, next){ }, function(err, results){ if(err) return next(err); - res.send(200); + res.sendStatus(200); }); }; @@ -259,13 +259,13 @@ exports.subscribeCancel = function(req, res, next){ } }, function(err, results){ if (err) return next(err); // don't json this, let toString() handle errors - + if(req.query.noRedirect){ - res.send(200); + res.sendStatus(200); }else{ res.redirect('/'); } user = null; }); -}; \ No newline at end of file +}; diff --git a/website/src/controllers/payments/index.js b/website/src/controllers/payments/index.js index 866c33381b..5005835c07 100644 --- a/website/src/controllers/payments/index.js +++ b/website/src/controllers/payments/index.js @@ -182,7 +182,7 @@ exports.validCoupon = function(req, res, next){ mongoose.model('Coupon').findOne({_id:cc.validate(req.params.code), event:'google_6mo'}, function(err, coupon){ if (err) return next(err); if (!coupon) return res.json(401, {err:"Invalid coupon code"}); - return res.send(200); + return res.sendStatus(200); }); } diff --git a/website/src/controllers/payments/paypal.js b/website/src/controllers/payments/paypal.js index 30970f72cf..2671946dc7 100644 --- a/website/src/controllers/payments/paypal.js +++ b/website/src/controllers/payments/paypal.js @@ -197,7 +197,7 @@ exports.cancelSubscription = function(req, res, next){ */ exports.ipn = function(req, res, next) { console.log('IPN Called'); - res.send(200); // Must respond to PayPal IPN request with an empty 200 first + res.sendStatus(200); // Must respond to PayPal IPN request with an empty 200 first ipn.verify(req.body, function(err, msg) { if (err) return logger.error(msg); switch (req.body.txn_type) { diff --git a/website/src/controllers/payments/stripe.js b/website/src/controllers/payments/stripe.js index 354390ec41..cd4b9cc9ae 100644 --- a/website/src/controllers/payments/stripe.js +++ b/website/src/controllers/payments/stripe.js @@ -64,7 +64,7 @@ exports.checkout = function(req, res, next) { } ], function(err){ if (err) return res.send(500, err.toString()); // don't json this, let toString() handle errors - res.send(200); + res.sendStatus(200); user = token = null; }); }; @@ -117,7 +117,7 @@ exports.subscribeEdit = function(req, res, next) { } ], function(err, saved){ if (err) return res.send(500, err.toString()); // don't json this, let toString() handle errors - res.send(200); + res.sendStatus(200); token = user = user_id = sub_id; }); -}; \ No newline at end of file +}; diff --git a/website/src/middlewares/cors.js b/website/src/middlewares/cors.js index b694aff2af..e72db26981 100644 --- a/website/src/middlewares/cors.js +++ b/website/src/middlewares/cors.js @@ -2,6 +2,6 @@ module.exports = function(req, res, next) { res.header("Access-Control-Allow-Origin", req.headers.origin || "*"); res.header("Access-Control-Allow-Methods", "OPTIONS,GET,POST,PUT,HEAD,DELETE"); res.header("Access-Control-Allow-Headers", "Content-Type,Accept,Content-Encoding,X-Requested-With,x-api-user,x-api-key"); - if (req.method === 'OPTIONS') return res.send(200); + if (req.method === 'OPTIONS') return res.sendStatus(200); return next(); };