diff --git a/services/web/app/src/Features/Analytics/AnalyticsController.js b/services/web/app/src/Features/Analytics/AnalyticsController.js index c27576199c..fe0ad397bc 100644 --- a/services/web/app/src/Features/Analytics/AnalyticsController.js +++ b/services/web/app/src/Features/Analytics/AnalyticsController.js @@ -8,7 +8,7 @@ const Features = require('../../infrastructure/Features') module.exports = { updateEditingSession(req, res, next) { if (!Features.hasFeature('analytics')) { - return res.send(204) + return res.sendStatus(204) } const userId = AuthenticationController.getLoggedInUserId(req) const { projectId } = req.params @@ -27,13 +27,13 @@ module.exports = { ) }) } else { - res.send(204) + res.sendStatus(204) } }, recordEvent(req, res, next) { if (!Features.hasFeature('analytics')) { - return res.send(204) + return res.sendStatus(204) } const userId = AuthenticationController.getLoggedInUserId(req) || req.sessionID diff --git a/services/web/app/src/Features/Chat/ChatController.js b/services/web/app/src/Features/Chat/ChatController.js index a1bc161558..79acd38a13 100644 --- a/services/web/app/src/Features/Chat/ChatController.js +++ b/services/web/app/src/Features/Chat/ChatController.js @@ -53,7 +53,7 @@ module.exports = ChatController = { 'new-chat-message', message ) - return res.send(204) + return res.sendStatus(204) }) } ) diff --git a/services/web/app/src/Features/Compile/CompileController.js b/services/web/app/src/Features/Compile/CompileController.js index ea48c74413..7261b6d0e0 100644 --- a/services/web/app/src/Features/Compile/CompileController.js +++ b/services/web/app/src/Features/Compile/CompileController.js @@ -214,13 +214,13 @@ module.exports = CompileController = { return rateLimit(function(err, canContinue) { if (err != null) { logger.err({ err }, 'error checking rate limit for pdf download') - return res.send(500) + return res.sendStatus(500) } else if (!canContinue) { logger.log( { project_id, ip: req.ip }, 'rate limit hit downloading pdf' ) - return res.send(500) + return res.sendStatus(500) } else { return CompileController._downloadAsUser(req, function( error, diff --git a/services/web/app/src/Features/LinkedFiles/LinkedFilesController.js b/services/web/app/src/Features/LinkedFiles/LinkedFilesController.js index 148a7a82d6..a5f0887ad4 100644 --- a/services/web/app/src/Features/LinkedFiles/LinkedFilesController.js +++ b/services/web/app/src/Features/LinkedFiles/LinkedFilesController.js @@ -106,7 +106,7 @@ module.exports = LinkedFilesController = { linkedFileData == null || (linkedFileData != null ? linkedFileData.provider : undefined) == null ) { - return res.send(409) + return res.sendStatus(409) } const { provider } = linkedFileData const parent_folder_id = parentFolder._id diff --git a/services/web/app/src/Features/Notifications/NotificationsController.js b/services/web/app/src/Features/Notifications/NotificationsController.js index e2461accbd..32d660fbca 100644 --- a/services/web/app/src/Features/Notifications/NotificationsController.js +++ b/services/web/app/src/Features/Notifications/NotificationsController.js @@ -35,6 +35,8 @@ module.exports = { markNotificationAsRead(req, res) { const user_id = AuthenticationController.getLoggedInUserId(req) const { notification_id } = req.params - NotificationsHandler.markAsRead(user_id, notification_id, () => res.send()) + NotificationsHandler.markAsRead(user_id, notification_id, () => + res.sendStatus(200) + ) } } diff --git a/services/web/app/src/Features/PasswordReset/PasswordResetController.js b/services/web/app/src/Features/PasswordReset/PasswordResetController.js index b8f268edaf..e70391e0cf 100644 --- a/services/web/app/src/Features/PasswordReset/PasswordResetController.js +++ b/services/web/app/src/Features/PasswordReset/PasswordResetController.js @@ -22,10 +22,10 @@ module.exports = { } RateLimiter.addCount(opts, (err, canContinue) => { if (err != null) { - res.send(500, { message: err.message }) + res.status(500).send({ message: err.message }) } if (!canContinue) { - return res.send(429, { + return res.status(429).send({ message: req.i18n.translate('rate_limit_hit_wait') }) } @@ -35,17 +35,17 @@ module.exports = { { err }, 'failed to generate and email password reset token' ) - res.send(500, { message: err.message }) + res.status(500).send({ message: err.message }) } else if (status === 'primary') { - res.send(200, { + res.status(200).send({ message: { text: req.i18n.translate('password_reset_email_sent') } }) } else if (status === 'secondary') { - res.send(404, { + res.status(404).send({ message: req.i18n.translate('secondary_email_password_reset') }) } else { - res.send(404, { + res.status(404).send({ message: req.i18n.translate('cant_find_email') }) } diff --git a/services/web/app/src/Features/ServerAdmin/AdminController.js b/services/web/app/src/Features/ServerAdmin/AdminController.js index a94ffbd8c0..060863d1c9 100644 --- a/services/web/app/src/Features/ServerAdmin/AdminController.js +++ b/services/web/app/src/Features/ServerAdmin/AdminController.js @@ -126,7 +126,7 @@ module.exports = AdminController = { Settings.mongo.writeAll = true return DocumentUpdaterHandler.flushAllDocsToMongo(function() { logger.log('all docs have been saved to mongo') - return res.send() + return res.sendStatus(200) }) }, diff --git a/services/web/app/src/Features/Subscription/SubscriptionController.js b/services/web/app/src/Features/Subscription/SubscriptionController.js index 8afa415c1b..caa0c354fb 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionController.js +++ b/services/web/app/src/Features/Subscription/SubscriptionController.js @@ -467,9 +467,9 @@ module.exports = SubscriptionController = { } return SubscriptionHandler.extendTrial(subscription, 14, function(err) { if (err != null) { - return res.send(500) + return res.sendStatus(500) } else { - return res.send(200) + return res.sendStatus(200) } }) }) diff --git a/services/web/app/src/Features/Subscription/SubscriptionGroupController.js b/services/web/app/src/Features/Subscription/SubscriptionGroupController.js index 113ab5bb93..ee31bdfff8 100644 --- a/services/web/app/src/Features/Subscription/SubscriptionGroupController.js +++ b/services/web/app/src/Features/Subscription/SubscriptionGroupController.js @@ -37,7 +37,7 @@ module.exports = { ) return next(err) } - return res.send() + return res.sendStatus(200) } ) }, @@ -61,7 +61,7 @@ module.exports = { ) return res.sendStatus(500) } - return res.send() + return res.sendStatus(200) } ) }) diff --git a/services/web/app/src/Features/User/UserController.js b/services/web/app/src/Features/User/UserController.js index c35a282f26..e6d86071cd 100644 --- a/services/web/app/src/Features/User/UserController.js +++ b/services/web/app/src/Features/User/UserController.js @@ -148,7 +148,7 @@ const UserController = { 'Failed to unsubscribe user from newsletter' ) } - res.send() + res.sendStatus(200) }) }) }, @@ -259,7 +259,7 @@ const UserController = { { err, userId }, 'error getting user for email update' ) - return res.send(500) + return res.sendStatus(500) } AuthenticationController.setInSessionUser(req, { email: user.email, diff --git a/services/web/app/src/Features/User/UserInfoController.js b/services/web/app/src/Features/User/UserInfoController.js index e916e5d7e9..be406a1991 100644 --- a/services/web/app/src/Features/User/UserInfoController.js +++ b/services/web/app/src/Features/User/UserInfoController.js @@ -37,7 +37,7 @@ module.exports = UserController = { } else if (/^[a-f0-9]{24}$/.test(userId)) { query = { _id: ObjectId(userId) } } else { - return res.send(400) + return res.sendStatus(400) } UserGetter.getUser( @@ -48,7 +48,7 @@ module.exports = UserController = { return next(error) } if (!user) { - return res.send(404) + return res.sendStatus(404) } UserController.sendFormattedPersonalInfo(user, res, next) } diff --git a/services/web/app/src/Features/UserMembership/UserMembershipController.js b/services/web/app/src/Features/UserMembership/UserMembershipController.js index 96653b1a98..d4b93e6d37 100644 --- a/services/web/app/src/Features/UserMembership/UserMembershipController.js +++ b/services/web/app/src/Features/UserMembership/UserMembershipController.js @@ -126,7 +126,7 @@ module.exports = { if (error != null) { return next(error) } - return res.send() + return res.sendStatus(200) } ) }, diff --git a/services/web/app/src/router.js b/services/web/app/src/router.js index 7d1ed33553..0baaee6b53 100644 --- a/services/web/app/src/router.js +++ b/services/web/app/src/router.js @@ -1043,7 +1043,7 @@ function initialize(webRouter, privateApiRouter, publicApiRouter) { privateApiRouter.get('/opps-small', function(req, res, next) { logger.err('test error occured') - res.send() + res.sendStatus(200) }) webRouter.post('/error/client', function(req, res, next) { diff --git a/services/web/test/acceptance/src/helpers/MockProjectHistoryApi.js b/services/web/test/acceptance/src/helpers/MockProjectHistoryApi.js index 8f602db1b2..50a157e2ad 100644 --- a/services/web/test/acceptance/src/helpers/MockProjectHistoryApi.js +++ b/services/web/test/acceptance/src/helpers/MockProjectHistoryApi.js @@ -79,7 +79,7 @@ module.exports = MockProjectHistoryApi = { if (this.oldFiles[key] != null) { res.send(this.oldFiles[key]) } else { - res.send(404) + res.sendStatus(404) } } ) @@ -99,7 +99,7 @@ module.exports = MockProjectHistoryApi = { if (this.projectVersions[projectId] != null) { res.json(this.projectVersions[projectId]) } else { - res.send(404) + res.sendStatus(404) } }) @@ -109,7 +109,7 @@ module.exports = MockProjectHistoryApi = { if (labels != null) { res.json(labels) } else { - res.send(404) + res.sendStatus(404) } }) @@ -135,9 +135,9 @@ module.exports = MockProjectHistoryApi = { : undefined if (label != null) { this.deleteLabel(projectId, labelId) - res.send(204) + res.sendStatus(204) } else { - res.send(404) + res.sendStatus(404) } } ) diff --git a/services/web/test/unit/src/Chat/ChatControllerTests.js b/services/web/test/unit/src/Chat/ChatControllerTests.js index 1de2943c50..d1b312324c 100644 --- a/services/web/test/unit/src/Chat/ChatControllerTests.js +++ b/services/web/test/unit/src/Chat/ChatControllerTests.js @@ -55,10 +55,11 @@ describe('ChatController', function() { project_id: this.project_id } } - return (this.res = { + this.res = { json: sinon.stub(), - send: sinon.stub() - }) + send: sinon.stub(), + sendStatus: sinon.stub() + } }) describe('sendMessage', function() { @@ -105,7 +106,7 @@ describe('ChatController', function() { }) it('should return a 204 status code', function() { - return this.res.send.calledWith(204).should.equal(true) + return this.res.sendStatus.calledWith(204).should.equal(true) }) }) diff --git a/services/web/test/unit/src/Notifications/NotificationsControllerTests.js b/services/web/test/unit/src/Notifications/NotificationsControllerTests.js index 211f3d95e0..67fab5bc23 100644 --- a/services/web/test/unit/src/Notifications/NotificationsControllerTests.js +++ b/services/web/test/unit/src/Notifications/NotificationsControllerTests.js @@ -82,7 +82,7 @@ describe('NotificationsController', function() { it('should send a delete request when a delete has been received to mark a notification', function(done) { return this.controller.markNotificationAsRead(this.req, { - send: () => { + sendStatus: () => { this.handler.markAsRead .calledWith(user_id, notification_id) .should.equal(true) diff --git a/services/web/test/unit/src/PasswordReset/PasswordResetControllerTests.js b/services/web/test/unit/src/PasswordReset/PasswordResetControllerTests.js index 3f26e54fbc..44339f84ca 100644 --- a/services/web/test/unit/src/PasswordReset/PasswordResetControllerTests.js +++ b/services/web/test/unit/src/PasswordReset/PasswordResetControllerTests.js @@ -2,6 +2,7 @@ const SandboxedModule = require('sandboxed-module') const path = require('path') const sinon = require('sinon') const { expect } = require('chai') +const MockResponse = require('../helpers/MockResponse') const MODULE_PATH = path.join( __dirname, @@ -26,7 +27,7 @@ describe('PasswordResetController', function() { session: {}, query: {} } - this.res = {} + this.res = new MockResponse() this.settings = {} this.PasswordResetHandler = { @@ -71,14 +72,12 @@ describe('PasswordResetController', function() { 'primary' ) this.RateLimiter.addCount.callsArgWith(1, null, false) - this.res.send = code => { - code.should.equal(429) - this.PasswordResetHandler.generateAndEmailResetToken - .calledWith(this.email) - .should.equal(false) - done() - } this.PasswordResetController.requestReset(this.req, this.res) + this.PasswordResetHandler.generateAndEmailResetToken + .calledWith(this.email) + .should.equal(false) + this.res.statusCode.should.equal(429) + done() }) it('should tell the handler to process that email', function(done) { @@ -88,14 +87,12 @@ describe('PasswordResetController', function() { null, 'primary' ) - this.res.send = code => { - code.should.equal(200) - this.PasswordResetHandler.generateAndEmailResetToken - .calledWith(this.email) - .should.equal(true) - done() - } this.PasswordResetController.requestReset(this.req, this.res) + this.PasswordResetHandler.generateAndEmailResetToken + .calledWith(this.email) + .should.equal(true) + this.res.statusCode.should.equal(200) + done() }) it('should send a 500 if there is an error', function(done) { @@ -104,11 +101,9 @@ describe('PasswordResetController', function() { 1, 'error' ) - this.res.send = code => { - code.should.equal(500) - done() - } this.PasswordResetController.requestReset(this.req, this.res) + this.res.statusCode.should.equal(500) + done() }) it("should send a 404 if the email doesn't exist", function(done) { @@ -118,11 +113,9 @@ describe('PasswordResetController', function() { null, null ) - this.res.send = code => { - code.should.equal(404) - done() - } this.PasswordResetController.requestReset(this.req, this.res) + this.res.statusCode.should.equal(404) + done() }) it('should send a 404 if the email is registered as a secondard email', function(done) { @@ -132,11 +125,9 @@ describe('PasswordResetController', function() { null, 'secondary' ) - this.res.send = code => { - code.should.equal(404) - done() - } this.PasswordResetController.requestReset(this.req, this.res) + this.res.statusCode.should.equal(404) + done() }) it('should normalize the email address', function(done) { @@ -148,14 +139,12 @@ describe('PasswordResetController', function() { null, 'primary' ) - this.res.send = code => { - code.should.equal(200) - this.PasswordResetHandler.generateAndEmailResetToken - .calledWith(this.email.toLowerCase().trim()) - .should.equal(true) - done() - } this.PasswordResetController.requestReset(this.req, this.res) + this.PasswordResetHandler.generateAndEmailResetToken + .calledWith(this.email.toLowerCase().trim()) + .should.equal(true) + this.res.statusCode.should.equal(200) + done() }) }) diff --git a/services/web/test/unit/src/Subscription/SubscriptionGroupControllerTests.js b/services/web/test/unit/src/Subscription/SubscriptionGroupControllerTests.js index 1f61d23b53..3832e066a3 100644 --- a/services/web/test/unit/src/Subscription/SubscriptionGroupControllerTests.js +++ b/services/web/test/unit/src/Subscription/SubscriptionGroupControllerTests.js @@ -81,7 +81,7 @@ describe('SubscriptionGroupController', function() { this.req.entity = this.subscription const res = { - send: () => { + sendStatus: () => { this.GroupHandler.removeUserFromGroup .calledWith(this.subscriptionId, userIdToRemove) .should.equal(true) diff --git a/services/web/test/unit/src/User/UserControllerTests.js b/services/web/test/unit/src/User/UserControllerTests.js index 62c1c9ce68..31e54980ea 100644 --- a/services/web/test/unit/src/User/UserControllerTests.js +++ b/services/web/test/unit/src/User/UserControllerTests.js @@ -267,7 +267,7 @@ describe('UserController', function() { describe('unsubscribe', function() { it('should send the user to unsubscribe', function(done) { - this.res.send = code => { + this.res.sendStatus = () => { this.NewsLetterManager.unsubscribe .calledWith(this.user) .should.equal(true) diff --git a/services/web/test/unit/src/UserMembership/UserMembershipControllerTests.js b/services/web/test/unit/src/UserMembership/UserMembershipControllerTests.js index 34a0651c47..e9bb19d8b9 100644 --- a/services/web/test/unit/src/UserMembership/UserMembershipControllerTests.js +++ b/services/web/test/unit/src/UserMembership/UserMembershipControllerTests.js @@ -231,7 +231,7 @@ describe('UserMembershipController', function() { it('remove user', function(done) { return this.UserMembershipController.remove(this.req, { - send: () => { + sendStatus: () => { sinon.assert.calledWithMatch( this.UserMembershipHandler.removeUser, this.subscription, diff --git a/services/web/test/unit/src/helpers/MockResponse.js b/services/web/test/unit/src/helpers/MockResponse.js index ee14ae720e..d5a9cfca48 100644 --- a/services/web/test/unit/src/helpers/MockResponse.js +++ b/services/web/test/unit/src/helpers/MockResponse.js @@ -52,7 +52,6 @@ class MockResponse { sendStatus(status) { if (arguments.length < 2) { if (typeof status !== 'number') { - const body = status status = 200 } } @@ -72,7 +71,7 @@ class MockResponse { if (arguments.length < 2) { if (typeof status !== 'number') { body = status - status = 200 + status = this.statusCode || 200 } } this.statusCode = status