diff --git a/services/web/app/coffee/Features/Chat/ChatController.coffee b/services/web/app/coffee/Features/Chat/ChatController.coffee index 7df835a1f8..ef3cbf94fc 100644 --- a/services/web/app/coffee/Features/Chat/ChatController.coffee +++ b/services/web/app/coffee/Features/Chat/ChatController.coffee @@ -12,7 +12,7 @@ module.exports = ChatHandler.sendMessage project_id, user_id, messageContent, (err, builtMessge)-> if err? logger.err err:err, project_id:project_id, user_id:user_id, messageContent:messageContent, "problem sending message to chat api" - return res.send(500) + return res.sendStatus(500) EditorRealTimeController.emitToRoom project_id, "new-chat-message", builtMessge, (err)-> res.send() @@ -23,7 +23,7 @@ module.exports = ChatHandler.getMessages project_id, query, (err, messages)-> if err? logger.err err:err, query:query, "problem getting messages from chat api" - return res.send 500 + return res.sendStatus 500 logger.log length:messages?.length, "sending messages to client" res.set 'Content-Type', 'application/json' res.send messages diff --git a/services/web/app/coffee/Features/Collaborators/CollaboratorsController.coffee b/services/web/app/coffee/Features/Collaborators/CollaboratorsController.coffee index e956b7f6bf..d51a604637 100644 --- a/services/web/app/coffee/Features/Collaborators/CollaboratorsController.coffee +++ b/services/web/app/coffee/Features/Collaborators/CollaboratorsController.coffee @@ -18,7 +18,7 @@ module.exports = CollaboratorsController = return next(new Error("User should be logged in")) CollaboratorsHandler.removeUserFromProject req.params.project_id, user_id, (error) -> return next(error) if error? - res.send 204 + res.sendStatus 204 addUserToProject: (req, res, next) -> project_id = req.params.Project_id @@ -32,7 +32,7 @@ module.exports = CollaboratorsController = user_id = req.params.user_id EditorController.removeUserFromProject project_id, user_id, (error)-> return next(error) if error? - res.send 204 + res.sendStatus 204 _formatCollaborators: (project, callback = (error, collaborators) ->) -> collaborators = [] diff --git a/services/web/app/coffee/Features/Compile/CompileController.coffee b/services/web/app/coffee/Features/Compile/CompileController.coffee index 9dd52b4e66..667accd65a 100755 --- a/services/web/app/coffee/Features/Compile/CompileController.coffee +++ b/services/web/app/coffee/Features/Compile/CompileController.coffee @@ -51,14 +51,14 @@ module.exports = CompileController = project_id = req.params.Project_id CompileManager.deleteAuxFiles project_id, (error) -> return next(error) if error? - res.send(200) + res.sendStatus(200) compileAndDownloadPdf: (req, res, next)-> project_id = req.params.project_id CompileManager.compile project_id, null, {}, (err)-> if err? logger.err err:err, project_id:project_id, "something went wrong compile and downloading pdf" - res.send 500 + res.sendStatus 500 url = "/project/#{project_id}/output/output.pdf" CompileController.proxyToClsi project_id, url, req, res, next diff --git a/services/web/app/coffee/Features/Documents/DocumentController.coffee b/services/web/app/coffee/Features/Documents/DocumentController.coffee index 1170da2ef4..4ac575af58 100644 --- a/services/web/app/coffee/Features/Documents/DocumentController.coffee +++ b/services/web/app/coffee/Features/Documents/DocumentController.coffee @@ -26,7 +26,7 @@ module.exports = logger.err err:error, doc_id:doc_id, project_id:project_id, "error finding element for getDocument" return next(error) logger.log doc_id:doc_id, project_id:project_id, "finished receiving set document request from api (docupdater)" - res.send 200 + res.sendStatus 200 diff --git a/services/web/app/coffee/Features/Editor/EditorHttpController.coffee b/services/web/app/coffee/Features/Editor/EditorHttpController.coffee index 848d33bdfb..2619316e6d 100644 --- a/services/web/app/coffee/Features/Editor/EditorHttpController.coffee +++ b/services/web/app/coffee/Features/Editor/EditorHttpController.coffee @@ -49,7 +49,7 @@ module.exports = EditorHttpController = name = req.body.name if !name? - return res.send 400 # Malformed request + return res.sendStatus 400 # Malformed request logger.log project_id: project_id, doc_id: doc_id, "restoring doc" ProjectEntityHandler.restoreDoc project_id, doc_id, name, (err, doc, folder_id) => @@ -68,7 +68,7 @@ module.exports = EditorHttpController = name = req.body.name parent_folder_id = req.body.parent_folder_id if !EditorHttpController._nameIsAcceptableLength(name) - return res.send 400 + return res.sendStatus 400 EditorController.addDoc project_id, parent_folder_id, name, [], "editor", (error, doc) -> return next(error) if error? res.json doc @@ -78,7 +78,7 @@ module.exports = EditorHttpController = name = req.body.name parent_folder_id = req.body.parent_folder_id if !EditorHttpController._nameIsAcceptableLength(name) - return res.send 400 + return res.sendStatus 400 EditorController.addFolder project_id, parent_folder_id, name, "editor", (error, doc) -> return next(error) if error? res.json doc @@ -89,10 +89,10 @@ module.exports = EditorHttpController = entity_type = req.params.entity_type name = req.body.name if !EditorHttpController._nameIsAcceptableLength(name) - return res.send 400 + return res.sendStatus 400 EditorController.renameEntity project_id, entity_id, entity_type, name, (error) -> return next(error) if error? - res.send 204 + res.sendStatus 204 moveEntity: (req, res, next) -> project_id = req.params.Project_id @@ -101,7 +101,7 @@ module.exports = EditorHttpController = folder_id = req.body.folder_id EditorController.moveEntity project_id, entity_id, folder_id, entity_type, (error) -> return next(error) if error? - res.send 204 + res.sendStatus 204 deleteDoc: (req, res, next)-> req.params.entity_type = "doc" @@ -121,6 +121,6 @@ module.exports = EditorHttpController = entity_type = req.params.entity_type EditorController.deleteEntity project_id, entity_id, entity_type, "editor", (error) -> return next(error) if error? - res.send 204 + res.sendStatus 204 diff --git a/services/web/app/coffee/Features/FileStore/FileStoreController.coffee b/services/web/app/coffee/Features/FileStore/FileStoreController.coffee index 8182268d8e..85ca986eff 100644 --- a/services/web/app/coffee/Features/FileStore/FileStoreController.coffee +++ b/services/web/app/coffee/Features/FileStore/FileStoreController.coffee @@ -12,10 +12,10 @@ module.exports = ProjectLocator.findElement {project_id: project_id, element_id: file_id, type: "file"}, (err, file)-> if err? logger.err err:err, project_id: project_id, file_id: file_id, queryString:queryString, "error finding element for downloading file" - return res.send 500 + return res.sendStatus 500 FileStoreHandler.getFileStream project_id, file_id, queryString, (err, stream)-> if err? logger.err err:err, project_id: project_id, file_id: file_id, queryString:queryString, "error getting file stream for downloading file" - return res.send 500 + return res.sendStatus 500 res.setHeader("Content-Disposition", "attachment; filename=#{file.name}") stream.pipe res \ No newline at end of file diff --git a/services/web/app/coffee/Features/HealthCheck/HealthCheckController.coffee b/services/web/app/coffee/Features/HealthCheck/HealthCheckController.coffee index 97be776549..5ed5b85e08 100644 --- a/services/web/app/coffee/Features/HealthCheck/HealthCheckController.coffee +++ b/services/web/app/coffee/Features/HealthCheck/HealthCheckController.coffee @@ -32,9 +32,9 @@ module.exports = HealthCheckController = checkRedis: (req, res, next)-> if redisCheck.isAlive() - res.send 200 + res.sendStatus 200 else - res.send 500 + res.sendStatus 500 Reporter = (res) -> (runner) -> diff --git a/services/web/app/coffee/Features/PasswordReset/PasswordResetController.coffee b/services/web/app/coffee/Features/PasswordReset/PasswordResetController.coffee index 5c5903466e..06bd4ba023 100644 --- a/services/web/app/coffee/Features/PasswordReset/PasswordResetController.coffee +++ b/services/web/app/coffee/Features/PasswordReset/PasswordResetController.coffee @@ -23,7 +23,7 @@ module.exports = if err? res.send 500, {message:err?.message} else if exists - res.send 200 + res.sendStatus 200 else res.send 404, {message: req.i18n.translate("cant_find_email")} @@ -35,10 +35,10 @@ module.exports = setNewUserPassword: (req, res)-> {passwordResetToken, password} = req.body if !password? or password.length == 0 or !passwordResetToken? or passwordResetToken.length == 0 - return res.send 400 + return res.sendStatus 400 PasswordResetHandler.setNewUserPassword passwordResetToken?.trim(), password?.trim(), (err, found) -> return next(err) if err? if found - res.send 200 + res.sendStatus 200 else res.send 404, {message: req.i18n.translate("password_reset_token_expired")} \ No newline at end of file diff --git a/services/web/app/coffee/Features/Project/ProjectApiController.coffee b/services/web/app/coffee/Features/Project/ProjectApiController.coffee index d62e40ad05..b16991ac62 100644 --- a/services/web/app/coffee/Features/Project/ProjectApiController.coffee +++ b/services/web/app/coffee/Features/Project/ProjectApiController.coffee @@ -9,6 +9,6 @@ module.exports = ProjectDetailsHandler.getDetails project_id, (err, projDetails)-> if err? logger.log err:err, project_id:project_id, "something went wrong getting project details" - return res.send 500 + return res.sendStatus 500 res.json(projDetails) diff --git a/services/web/app/coffee/Features/Project/ProjectController.coffee b/services/web/app/coffee/Features/Project/ProjectController.coffee index 50a8e91670..5466fe1bf9 100644 --- a/services/web/app/coffee/Features/Project/ProjectController.coffee +++ b/services/web/app/coffee/Features/Project/ProjectController.coffee @@ -44,7 +44,7 @@ module.exports = ProjectController = async.series jobs, (error) -> return next(error) if error? - res.send(204) + res.sendStatus(204) deleteProject: (req, res) -> project_id = req.params.Project_id @@ -58,18 +58,18 @@ module.exports = ProjectController = doDelete project_id, (err)-> if err? - res.send 500 + res.sendStatus 500 else - res.send 200 + res.sendStatus 200 restoreProject: (req, res) -> project_id = req.params.Project_id logger.log project_id:project_id, "received request to restore project" projectDeleter.restoreProject project_id, (err)-> if err? - res.send 500 + res.sendStatus 500 else - res.send 200 + res.sendStatus 200 cloneProject: (req, res, next)-> metrics.inc "cloned-project" @@ -99,7 +99,7 @@ module.exports = ProjectController = ], (err, project)-> if err? logger.error err: err, project: project, user: user, name: projectName, templateType: template, "error creating project" - res.send 500 + res.sendStatus 500 else logger.log project: project, user: user, name: projectName, templateType: template, "created project" res.send {project_id:project._id} @@ -109,13 +109,13 @@ module.exports = ProjectController = project_id = req.params.Project_id newName = req.body.newProjectName if newName.length > 150 - return res.send 400 + return res.sendStatus 400 editorController.renameProject project_id, newName, (err)-> if err? logger.err err:err, project_id:project_id, newName:newName, "problem renaming project" - res.send 500 + res.sendStatus 500 else - res.send 200 + res.sendStatus 200 projectListPage: (req, res, next)-> timer = new metrics.Timer("project-list") @@ -196,7 +196,7 @@ module.exports = ProjectController = SecurityManager.userCanAccessProject user, project, (canAccess, privilegeLevel)-> if !canAccess - return res.send 401 + return res.sendStatus 401 if subscription? and subscription.freeTrial? and subscription.freeTrial.expiresAt? allowedFreeTrial = !!subscription.freeTrial.allowed || true diff --git a/services/web/app/coffee/Features/ServerAdmin/AdminController.coffee b/services/web/app/coffee/Features/ServerAdmin/AdminController.coffee index e875413908..005f2d23d3 100755 --- a/services/web/app/coffee/Features/ServerAdmin/AdminController.coffee +++ b/services/web/app/coffee/Features/ServerAdmin/AdminController.coffee @@ -50,12 +50,12 @@ module.exports = AdminController = dissconectAllUsers: (req, res)=> logger.warn "disconecting everyone" EditorRealTimeController.emitToAll 'forceDisconnect', "Sorry, we are performing a quick update to the editor and need to close it down. Please refresh the page to continue." - res.send(200) + res.sendStatus(200) closeEditor : (req, res)-> logger.warn "closing editor" Settings.editorIsOpen = req.body.isOpen - res.send(200) + res.sendStatus(200) writeAllToMongo : (req, res)-> logger.log "writing all docs to mongo" @@ -74,19 +74,19 @@ module.exports = AdminController = flushProjectToTpds: (req, res)-> projectEntityHandler.flushProjectToThirdPartyDataStore req.body.project_id, (err)-> - res.send 200 + res.sendStatus 200 pollDropboxForUser: (req, res)-> user_id = req.body.user_id TpdsUpdateSender.pollDropboxForUser user_id, () -> - res.send 200 + res.sendStatus 200 createMessage: (req, res, next) -> SystemMessageManager.createMessage req.body.content, (error) -> return next(error) if error? - res.send 200 + res.sendStatus 200 clearMessages: (req, res, next) -> SystemMessageManager.clearMessages (error) -> return next(error) if error? - res.send 200 + res.sendStatus 200 diff --git a/services/web/app/coffee/Features/Spelling/SpellingController.coffee b/services/web/app/coffee/Features/Spelling/SpellingController.coffee index 0a1c8f0917..f87504e5d0 100644 --- a/services/web/app/coffee/Features/Spelling/SpellingController.coffee +++ b/services/web/app/coffee/Features/Spelling/SpellingController.coffee @@ -11,4 +11,4 @@ module.exports = SpellingController = getReq.pipe(res) getReq.on "error", (error) -> logger.error err: error, "Spelling API error" - res.send 500 + res.sendStatus 500 diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee index ea03458093..e3b3747baa 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionController.coffee @@ -147,8 +147,8 @@ module.exports = SubscriptionController = SubscriptionHandler.createSubscription user, subscriptionDetails, recurly_token_id, (err)-> if err? logger.err err:err, user_id:user._id, "something went wrong creating subscription" - return res.send 500 - res.send 201 + return res.sendStatus 500 + res.sendStatus 201 successful_subscription: (req, res)-> SecurityManager.getCurrentUser req, (error, user) => @@ -191,9 +191,9 @@ module.exports = SubscriptionController = if req.body? and req.body["expired_subscription_notification"]? recurlySubscription = req.body["expired_subscription_notification"].subscription SubscriptionHandler.recurlyCallback recurlySubscription, -> - res.send 200 + res.sendStatus 200 else - res.send 200 + res.sendStatus 200 renderUpgradeToAnnualPlanPage: (req, res)-> SecurityManager.getCurrentUser req, (error, user) -> @@ -221,9 +221,9 @@ module.exports = SubscriptionController = SubscriptionHandler.updateSubscription user, annualPlanName, coupon_code, (err)-> if err? logger.err err:err, user_id:user._id, "error updating subscription" - res.send 500 + res.sendStatus 500 else - res.send 200 + res.sendStatus 200 recurlyNotificationParser: (req, res, next) -> diff --git a/services/web/app/coffee/Features/Subscription/SubscriptionGroupController.coffee b/services/web/app/coffee/Features/Subscription/SubscriptionGroupController.coffee index 8d8bd59bde..3bf8d4a631 100644 --- a/services/web/app/coffee/Features/Subscription/SubscriptionGroupController.coffee +++ b/services/web/app/coffee/Features/Subscription/SubscriptionGroupController.coffee @@ -62,9 +62,9 @@ module.exports = return ErrorsController.notFound(req, res) SubscriptionGroupHandler.sendVerificationEmail subscription_id, licence.name, req.session.user.email, (err)-> if err? - res.send 500 + res.sendStatus 500 else - res.send 200 + res.sendStatus 200 completeJoin: (req, res)-> subscription_id = req.params.subscription_id @@ -74,7 +74,7 @@ module.exports = if err? and err == "token_not_found" res.redirect "/user/subscription/#{subscription_id}/group/invited?expired=true" else if err? - res.send 500 + res.sendStatus 500 else res.redirect "/user/subscription/#{subscription_id}/group/successful-join" diff --git a/services/web/app/coffee/Features/ThirdPartyDataStore/TpdsController.coffee b/services/web/app/coffee/Features/ThirdPartyDataStore/TpdsController.coffee index 3dbb30f75c..f256760808 100644 --- a/services/web/app/coffee/Features/ThirdPartyDataStore/TpdsController.coffee +++ b/services/web/app/coffee/Features/ThirdPartyDataStore/TpdsController.coffee @@ -17,10 +17,10 @@ module.exports = logger.log user_id:user_id, filePath:filePath, fullPath:req.params[0], "sending response that tpdsUpdate has been completed" if err? logger.err err:err, user_id:user_id, filePath:filePath, "error reciving update from tpds" - res.send(500) + res.sendStatus(500) else logger.log user_id:user_id, filePath:filePath, projectName:projectName, "telling tpds update has been processed" - res.send 200 + res.sendStatus 200 deleteUpdate: (req, res)-> @@ -31,10 +31,10 @@ module.exports = tpdsUpdateHandler.deleteUpdate user_id, projectName, filePath, source, (err)-> if err? logger.err err:err, user_id:user_id, filePath:filePath, "error reciving update from tpds" - res.send(500) + res.sendStatus(500) else logger.log user_id:user_id, filePath:filePath, projectName:projectName, "telling tpds delete has been processed" - res.send 200 + res.sendStatus 200 # updateProjectContents and deleteProjectContents are used by GitHub. The project_id is known so we # can skip right ahead to creating/updating/deleting the file. These methods will not ignore noisy @@ -47,7 +47,7 @@ module.exports = logger.log project_id: project_id, path: path, source: source, "received project contents update" UpdateMerger.mergeUpdate project_id, path, req, source, (error) -> return next(error) if error? - res.send(200) + res.sendStatus(200) deleteProjectContents: (req, res, next = (error) ->) -> {project_id} = req.params @@ -56,7 +56,7 @@ module.exports = logger.log project_id: project_id, path: path, source: source, "received project contents delete request" UpdateMerger.deleteUpdate project_id, path, source, (error) -> return next(error) if error? - res.send(200) + res.sendStatus(200) parseParams: parseParams = (req)-> path = req.params[0] diff --git a/services/web/app/coffee/Features/User/UserController.coffee b/services/web/app/coffee/Features/User/UserController.coffee index 643404a14d..468832ca98 100644 --- a/services/web/app/coffee/Features/User/UserController.coffee +++ b/services/web/app/coffee/Features/User/UserController.coffee @@ -21,7 +21,7 @@ module.exports = UserDeleter.deleteUser user_id, (err)-> if !err? req.session?.destroy() - res.send(200) + res.sendStatus(200) unsubscribe: (req, res)-> UserLocator.findById req.session.user._id, (err, user)-> @@ -34,7 +34,7 @@ module.exports = User.findById user_id, (err, user)-> if err? or !user? logger.err err:err, user_id:user_id, "problem updaing user settings" - return res.send 500 + return res.sendStatus 500 if req.body.first_name? user.first_name = req.body.first_name.trim() @@ -59,9 +59,9 @@ module.exports = user.save (err)-> newEmail = req.body.email?.trim().toLowerCase() if !newEmail? or newEmail == user.email - return res.send 200 + return res.sendStatus 200 else if newEmail.indexOf("@") == -1 - return res.send(400) + return res.sendStatus(400) else UserUpdater.changeEmailAddress user_id, newEmail, (err)-> if err? @@ -71,7 +71,7 @@ module.exports = else message = req.i18n.translate("problem_changing_email_address") return res.send 500, {message:message} - res.send(200) + res.sendStatus(200) logout : (req, res)-> metrics.inc "user.logout" @@ -84,7 +84,7 @@ module.exports = register : (req, res, next = (error) ->)-> email = req.body.email if !email? or email == "" - res.send 422 # Unprocessable Entity + res.sendStatus 422 # Unprocessable Entity return logger.log {email}, "registering new user" UserRegistrationHandler.registerNewUser { diff --git a/services/web/app/coffee/router.coffee b/services/web/app/coffee/router.coffee index a7240e27d3..4d0c8279df 100644 --- a/services/web/app/coffee/router.coffee +++ b/services/web/app/coffee/router.coffee @@ -212,6 +212,6 @@ module.exports = class Router webRouter.post '/error/client', (req, res, next) -> logger.error err: req.body.error, meta: req.body.meta, "client side error" - res.send(204) + res.sendStatus(204) webRouter.get '*', ErrorController.notFound diff --git a/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsControllerTests.coffee b/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsControllerTests.coffee index 11659296cb..c2e8f45685 100644 --- a/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Collaborators/CollaboratorsControllerTests.coffee @@ -91,7 +91,7 @@ describe "CollaboratorsController", -> @req.params = Project_id: @project_id = "project-id-123" user_id: @user_id = "user-id-123" - @res.send = sinon.stub() + @res.sendStatus = sinon.stub() @EditorController.removeUserFromProject = sinon.stub().callsArg(2) @CollaboratorsController.removeUserFromProject @req, @res @@ -101,7 +101,7 @@ describe "CollaboratorsController", -> .should.equal true it "should send the back a success response", -> - @res.send.calledWith(204).should.equal true + @res.sendStatus.calledWith(204).should.equal true describe "_formatCollaborators", -> diff --git a/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee b/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee index e3fd444870..08299812fe 100644 --- a/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Compile/CompileControllerTests.coffee @@ -321,7 +321,7 @@ describe "CompileController", -> @CompileManager.deleteAuxFiles = sinon.stub().callsArg(1) @req.params = Project_id: @project_id - @res.send = sinon.stub() + @res.sendStatus = sinon.stub() @CompileController.deleteAuxFiles @req, @res, @next it "should proxy to the CLSI", -> @@ -330,7 +330,7 @@ describe "CompileController", -> .should.equal true it "should return a 200", -> - @res.send + @res.sendStatus .calledWith(200) .should.equal true diff --git a/services/web/test/UnitTests/coffee/Editor/EditorHttpControllerTests.coffee b/services/web/test/UnitTests/coffee/Editor/EditorHttpControllerTests.coffee index e740e35882..ab003208c2 100644 --- a/services/web/test/UnitTests/coffee/Editor/EditorHttpControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Editor/EditorHttpControllerTests.coffee @@ -24,6 +24,7 @@ describe "EditorHttpController", -> @req = {} @res = send: sinon.stub() + sendStatus: sinon.stub() json: sinon.stub() @callback = sinon.stub() @@ -190,7 +191,7 @@ describe "EditorHttpController", -> @EditorHttpController.addDoc @req, @res it "should send back a bad request status code", -> - @res.send.calledWith(400).should.equal true + @res.sendStatus.calledWith(400).should.equal true describe "addFolder", -> beforeEach -> @@ -223,7 +224,7 @@ describe "EditorHttpController", -> @EditorHttpController.addFolder @req, @res it "should send back a bad request status code", -> - @res.send.calledWith(400).should.equal true + @res.sendStatus.calledWith(400).should.equal true describe "renameEntity", -> @@ -243,7 +244,7 @@ describe "EditorHttpController", -> .should.equal true it "should send back a success response", -> - @res.send.calledWith(204).should.equal true + @res.sendStatus.calledWith(204).should.equal true describe "renameEntity with long name", -> beforeEach -> @@ -257,7 +258,7 @@ describe "EditorHttpController", -> @EditorHttpController.renameEntity @req, @res it "should send back a bad request status code", -> - @res.send.calledWith(400).should.equal true + @res.sendStatus.calledWith(400).should.equal true describe "rename entity with 0 length name", -> @@ -272,7 +273,7 @@ describe "EditorHttpController", -> @EditorHttpController.renameEntity @req, @res it "should send back a bad request status code", -> - @res.send.calledWith(400).should.equal true + @res.sendStatus.calledWith(400).should.equal true describe "moveEntity", -> @@ -292,7 +293,7 @@ describe "EditorHttpController", -> .should.equal true it "should send back a success response", -> - @res.send.calledWith(204).should.equal true + @res.sendStatus.calledWith(204).should.equal true describe "deleteEntity", -> beforeEach -> @@ -309,4 +310,4 @@ describe "EditorHttpController", -> .should.equal true it "should send back a success response", -> - @res.send.calledWith(204).should.equal true + @res.sendStatus.calledWith(204).should.equal true diff --git a/services/web/test/UnitTests/coffee/PasswordReset/PasswordResetControllerTests.coffee b/services/web/test/UnitTests/coffee/PasswordReset/PasswordResetControllerTests.coffee index a6590b31da..efc4d9cbde 100644 --- a/services/web/test/UnitTests/coffee/PasswordReset/PasswordResetControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/PasswordReset/PasswordResetControllerTests.coffee @@ -51,7 +51,7 @@ describe "PasswordResetController", -> it "should tell the handler to process that email", (done)-> @RateLimiter.addCount.callsArgWith(1, null, true) @PasswordResetHandler.generateAndEmailResetToken.callsArgWith(1, null, true) - @res.send = (code)=> + @res.sendStatus = (code)=> code.should.equal 200 @PasswordResetHandler.generateAndEmailResetToken.calledWith(@email.trim()).should.equal true done() @@ -78,7 +78,7 @@ describe "PasswordResetController", -> @req.body.email = @email @RateLimiter.addCount.callsArgWith(1, null, true) @PasswordResetHandler.generateAndEmailResetToken.callsArgWith(1, null, true) - @res.send = (code)=> + @res.sendStatus = (code)=> code.should.equal 200 @PasswordResetHandler.generateAndEmailResetToken.calledWith(@email.toLowerCase()).should.equal true done() @@ -88,7 +88,7 @@ describe "PasswordResetController", -> it "should tell the user handler to reset the password", (done)-> @PasswordResetHandler.setNewUserPassword.callsArgWith(2, null, true) - @res.send = (code)=> + @res.sendStatus = (code)=> code.should.equal 200 @PasswordResetHandler.setNewUserPassword.calledWith(@token, @password).should.equal true done() @@ -104,7 +104,7 @@ describe "PasswordResetController", -> it "should return 400 (Bad Request) if there is no password", (done)-> @req.body.password = "" @PasswordResetHandler.setNewUserPassword.callsArgWith(2) - @res.send = (code)=> + @res.sendStatus = (code)=> code.should.equal 400 @PasswordResetHandler.setNewUserPassword.called.should.equal false done() @@ -113,7 +113,7 @@ describe "PasswordResetController", -> it "should return 400 (Bad Request) if there is no passwordResetToken", (done)-> @req.body.passwordResetToken = "" @PasswordResetHandler.setNewUserPassword.callsArgWith(2) - @res.send = (code)=> + @res.sendStatus = (code)=> code.should.equal 400 @PasswordResetHandler.setNewUserPassword.called.should.equal false done() diff --git a/services/web/test/UnitTests/coffee/Project/ProjectApiControllerTests.coffee b/services/web/test/UnitTests/coffee/Project/ProjectApiControllerTests.coffee index 322d61750e..9476a80019 100644 --- a/services/web/test/UnitTests/coffee/Project/ProjectApiControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Project/ProjectApiControllerTests.coffee @@ -36,7 +36,7 @@ describe 'Project api controller', -> it "should send a 500 if there is an error", (done)-> @ProjectDetailsHandler.getDetails.callsArgWith(1, "error") - @res.send = (resCode)=> + @res.sendStatus = (resCode)=> resCode.should.equal 500 done() @controller.getProjectDetails @req, @res diff --git a/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee b/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee index 77bfcebd35..c5c14c4359 100644 --- a/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Project/ProjectControllerTests.coffee @@ -78,7 +78,7 @@ describe "ProjectController", -> @EditorController.renameProject = sinon.stub().callsArg(2) @req.body = name: @name = "New name" - @res.send = (code) => + @res.sendStatus = (code) => @EditorController.renameProject .calledWith(@project_id, @name) .should.equal true @@ -90,7 +90,7 @@ describe "ProjectController", -> @EditorController.setCompiler = sinon.stub().callsArg(2) @req.body = compiler: @compiler = "pdflatex" - @res.send = (code) => + @res.sendStatus = (code) => @EditorController.setCompiler .calledWith(@project_id, @compiler) .should.equal true @@ -102,7 +102,7 @@ describe "ProjectController", -> @EditorController.setSpellCheckLanguage = sinon.stub().callsArg(2) @req.body = spellCheckLanguage: @languageCode = "fr" - @res.send = (code) => + @res.sendStatus = (code) => @EditorController.setSpellCheckLanguage .calledWith(@project_id, @languageCode) .should.equal true @@ -114,7 +114,7 @@ describe "ProjectController", -> @EditorController.setPublicAccessLevel = sinon.stub().callsArg(2) @req.body = publicAccessLevel: @publicAccessLevel = "readonly" - @res.send = (code) => + @res.sendStatus = (code) => @EditorController.setPublicAccessLevel .calledWith(@project_id, @publicAccessLevel) .should.equal true @@ -126,7 +126,7 @@ describe "ProjectController", -> @EditorController.setRootDoc = sinon.stub().callsArg(2) @req.body = rootDocId: @rootDocId = "root-doc-id" - @res.send = (code) => + @res.sendStatus = (code) => @EditorController.setRootDoc .calledWith(@project_id, @rootDocId) .should.equal true @@ -136,7 +136,7 @@ describe "ProjectController", -> describe "deleteProject", -> it "should tell the project deleter to archive when forever=false", (done)-> - @res.send = (code)=> + @res.sendStatus = (code)=> @ProjectDeleter.archiveProject.calledWith(@project_id).should.equal true code.should.equal 200 done() @@ -144,7 +144,7 @@ describe "ProjectController", -> it "should tell the project deleter to delete when forever=true", (done)-> @req.query = forever: "true" - @res.send = (code)=> + @res.sendStatus = (code)=> @ProjectDeleter.deleteProject.calledWith(@project_id).should.equal true code.should.equal 200 done() @@ -152,7 +152,7 @@ describe "ProjectController", -> describe "restoreProject", -> it "should tell the project deleter", (done)-> - @res.send = (code)=> + @res.sendStatus = (code)=> @ProjectDeleter.restoreProject.calledWith(@project_id).should.equal true code.should.equal 200 done() @@ -244,7 +244,7 @@ describe "ProjectController", -> it "should call the editor controller", (done)-> @EditorController.renameProject.callsArgWith(2) - @res.send = (code)=> + @res.sendStatus = (code)=> code.should.equal 200 @EditorController.renameProject.calledWith(@project_id, @newProjectName).should.equal true done() @@ -252,7 +252,7 @@ describe "ProjectController", -> it "should send a 500 if there is a problem", (done)-> @EditorController.renameProject.callsArgWith(2, "problem") - @res.send = (code)=> + @res.sendStatus = (code)=> code.should.equal 500 @EditorController.renameProject.calledWith(@project_id, @newProjectName).should.equal true done() @@ -260,7 +260,7 @@ describe "ProjectController", -> it "should return an error if the name is over 150 chars", (done)-> @req.body.newProjectName = "EDMUBEEBKBXUUUZERMNSXFFWIBHGSDAWGMRIQWJBXGWSBVWSIKLFPRBYSJEKMFHTRZBHVKJSRGKTBHMJRXPHORFHAKRNPZGGYIOTEDMUBEEBKBXUUUZERMNSXFFWIBHGSDAWGMRIQWJBXGWSBVWSIKLFPRBYSJEKMFHTRZBHVKJSRGKTBHMJRXPHORFHAKRNPZGGYIOT" - @res.send = (code)=> + @res.sendStatus = (code)=> code.should.equal 400 done() @ProjectController.renameProject @req, @res @@ -317,7 +317,7 @@ describe "ProjectController", -> it "should not render the page if the project can not be accessed", (done)-> @SecurityManager.userCanAccessProject = sinon.stub().callsArgWith 2, false - @res.send = (resCode, opts)=> + @res.sendStatus = (resCode, opts)=> resCode.should.equal 401 done() @ProjectController.loadEditor @req, @res diff --git a/services/web/test/UnitTests/coffee/Subscription/SubscriptionControllerTests.coffee b/services/web/test/UnitTests/coffee/Subscription/SubscriptionControllerTests.coffee index 56e31c5f26..87cbc11671 100644 --- a/services/web/test/UnitTests/coffee/Subscription/SubscriptionControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Subscription/SubscriptionControllerTests.coffee @@ -285,9 +285,9 @@ describe "SubscriptionController sanboxed", -> describe "createSubscription", -> beforeEach (done)-> @res = - send:-> + sendStatus:-> done() - sinon.spy @res, "send" + sinon.spy @res, "sendStatus" @subscriptionDetails = card:"1234" cvv:"123" @@ -300,7 +300,7 @@ describe "SubscriptionController sanboxed", -> done() it "should redurect to the subscription page", (done)-> - @res.send.calledWith(201).should.equal true + @res.sendStatus.calledWith(201).should.equal true done() @@ -363,9 +363,9 @@ describe "SubscriptionController sanboxed", -> expired_subscription_notification: subscription: uuid: @activeRecurlySubscription.uuid - @res = send:-> + @res = sendStatus:-> done() - sinon.spy @res, "send" + sinon.spy @res, "sendStatus" @SubscriptionController.recurlyCallback @req, @res it "should tell the SubscriptionHandler to process the recurly callback", (done)-> @@ -374,7 +374,7 @@ describe "SubscriptionController sanboxed", -> it "should send a 200", (done)-> - @res.send.calledWith(200) + @res.sendStatus.calledWith(200) done() describe "with a non-actionable request", -> @@ -385,16 +385,16 @@ describe "SubscriptionController sanboxed", -> new_subscription_notification: subscription: uuid: @activeRecurlySubscription.uuid - @res = send:-> + @res = sendStatus:-> done() - sinon.spy @res, "send" + sinon.spy @res, "sendStatus" @SubscriptionController.recurlyCallback @req, @res it "should not call the subscriptionshandler", -> @SubscriptionHandler.recurlyCallback.called.should.equal false it "should respond with a 200 status", -> - @res.send.calledWith(200) + @res.sendStatus.calledWith(200) describe "renderUpgradeToAnnualPlanPage", -> @@ -442,7 +442,7 @@ describe "SubscriptionController sanboxed", -> @req.body = planName:"student" - @res.send = ()=> + @res.sendStatus = ()=> @SubscriptionHandler.updateSubscription.calledWith(@user, "student-annual", "STUDENTCODEHERE").should.equal true done() @@ -453,7 +453,7 @@ describe "SubscriptionController sanboxed", -> @req.body = planName:"collaborator" - @res.send = (url)=> + @res.sendStatus = (url)=> @SubscriptionHandler.updateSubscription.calledWith(@user, "collaborator-annual", "COLLABORATORCODEHERE").should.equal true done() diff --git a/services/web/test/UnitTests/coffee/Subscription/SubscriptionGroupControllerTests.coffee b/services/web/test/UnitTests/coffee/Subscription/SubscriptionGroupControllerTests.coffee index 8c3181da03..dbaf751c70 100644 --- a/services/web/test/UnitTests/coffee/Subscription/SubscriptionGroupControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/Subscription/SubscriptionGroupControllerTests.coffee @@ -127,7 +127,7 @@ describe "SubscriptionGroupController", -> it "should ask the SubscriptionGroupHandler to send the verification email", (done)-> res = - send : (statusCode)=> + sendStatus : (statusCode)=> statusCode.should.equal 200 @GroupHandler.sendVerificationEmail.calledWith(@subscription_id, @licenceName, @user_email).should.equal true done() diff --git a/services/web/test/UnitTests/coffee/ThirdPartyDataStore/TpdsControllerTests.coffee b/services/web/test/UnitTests/coffee/ThirdPartyDataStore/TpdsControllerTests.coffee index 769582a95a..39248be52d 100644 --- a/services/web/test/UnitTests/coffee/ThirdPartyDataStore/TpdsControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/ThirdPartyDataStore/TpdsControllerTests.coffee @@ -28,7 +28,7 @@ describe 'TpdsController', -> headers: "x-sl-update-source": @source = "dropbox" @TpdsUpdateHandler.newUpdate = sinon.stub().callsArg(5) - res = send: => + res = sendStatus: => @TpdsUpdateHandler.newUpdate.calledWith(@user_id, "projectName","/here.txt", req, @source).should.equal true done() @TpdsController.mergeUpdate req, res @@ -43,7 +43,7 @@ describe 'TpdsController', -> headers: "x-sl-update-source": @source = "dropbox" @TpdsUpdateHandler.deleteUpdate = sinon.stub().callsArg(4) - res = send: => + res = sendStatus: => @TpdsUpdateHandler.deleteUpdate.calledWith(@user_id, "projectName", "/here.txt", @source).should.equal true done() @TpdsController.deleteUpdate req, res @@ -86,7 +86,7 @@ describe 'TpdsController', -> headers: "x-sl-update-source": @source = "github" @res = - send: sinon.stub() + sendStatus: sinon.stub() @TpdsController.updateProjectContents @req, @res @@ -96,7 +96,7 @@ describe 'TpdsController', -> .should.equal true it "should return a success", -> - @res.send.calledWith(200).should.equal true + @res.sendStatus.calledWith(200).should.equal true describe 'deleteProjectContents', -> @@ -111,7 +111,7 @@ describe 'TpdsController', -> headers: "x-sl-update-source": @source = "github" @res = - send: sinon.stub() + sendStatus: sinon.stub() @TpdsController.deleteProjectContents @req, @res @@ -121,5 +121,5 @@ describe 'TpdsController', -> .should.equal true it "should return a success", -> - @res.send.calledWith(200).should.equal true + @res.sendStatus.calledWith(200).should.equal true diff --git a/services/web/test/UnitTests/coffee/User/UserControllerTests.coffee b/services/web/test/UnitTests/coffee/User/UserControllerTests.coffee index 3bc8a3ca46..e1883cb262 100644 --- a/services/web/test/UnitTests/coffee/User/UserControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/User/UserControllerTests.coffee @@ -78,7 +78,7 @@ describe "UserController", -> it "should delete the user", (done)-> - @res.send = (code)=> + @res.sendStatus = (code)=> @UserDeleter.deleteUser.calledWith(@user_id) code.should.equal 200 done() @@ -98,7 +98,7 @@ describe "UserController", -> it "should call save", (done)-> @req.body = {} - @res.send = (code)=> + @res.sendStatus = (code)=> @user.save.called.should.equal true done() @UserController.updateUserSettings @req, @res @@ -106,7 +106,7 @@ describe "UserController", -> it "should set the first name", (done)-> @req.body = first_name: "bobby " - @res.send = (code)=> + @res.sendStatus = (code)=> @user.first_name.should.equal "bobby" done() @UserController.updateUserSettings @req, @res @@ -114,7 +114,7 @@ describe "UserController", -> it "should set the role", (done)-> @req.body = role: "student" - @res.send = (code)=> + @res.sendStatus = (code)=> @user.role.should.equal "student" done() @UserController.updateUserSettings @req, @res @@ -122,7 +122,7 @@ describe "UserController", -> it "should set the institution", (done)-> @req.body = institution: "MIT" - @res.send = (code)=> + @res.sendStatus = (code)=> @user.institution.should.equal "MIT" done() @UserController.updateUserSettings @req, @res @@ -130,21 +130,21 @@ describe "UserController", -> it "should set some props on ace", (done)-> @req.body = theme: "something" - @res.send = (code)=> + @res.sendStatus = (code)=> @user.ace.theme.should.equal "something" done() @UserController.updateUserSettings @req, @res it "should send an error if the email is 0 len", (done)-> @req.body.email = "" - @res.send = (code)-> + @res.sendStatus = (code)-> code.should.equal 400 done() @UserController.updateUserSettings @req, @res it "should send an error if the email does not contain an @", (done)-> @req.body.email = "bob at something dot com" - @res.send = (code)-> + @res.sendStatus = (code)-> code.should.equal 400 done() @UserController.updateUserSettings @req, @res @@ -152,7 +152,7 @@ describe "UserController", -> it "should call the user updater with the new email and user _id", (done)-> @req.body.email = @newEmail.toUpperCase() @UserUpdater.changeEmailAddress.callsArgWith(2) - @res.send = (code)=> + @res.sendStatus = (code)=> code.should.equal 200 @UserUpdater.changeEmailAddress.calledWith(@user_id, @newEmail).should.equal true done() diff --git a/services/web/test/UnitTests/coffee/helpers/MockResponse.coffee b/services/web/test/UnitTests/coffee/helpers/MockResponse.coffee index ab78f248b9..f3a7f7a775 100644 --- a/services/web/test/UnitTests/coffee/helpers/MockResponse.coffee +++ b/services/web/test/UnitTests/coffee/helpers/MockResponse.coffee @@ -22,6 +22,19 @@ class MockResponse @redirectedTo = url @callback() if @callback? + sendStatus: (status) -> + if arguments.length < 2 + if typeof status != "number" + body = status + status = 200 + @statusCode = status + @returned = true + if 200 <= status < 300 + @success = true + else + @success = false + @callback() if @callback? + send: (status, body) -> if arguments.length < 2 if typeof status != "number"