diff --git a/services/web/app/coffee/Features/Documents/DocumentController.coffee b/services/web/app/coffee/Features/Documents/DocumentController.coffee index 9d147e8287..f32262a02c 100644 --- a/services/web/app/coffee/Features/Documents/DocumentController.coffee +++ b/services/web/app/coffee/Features/Documents/DocumentController.coffee @@ -27,8 +27,7 @@ module.exports = else projectHistoryId = project?.overleaf?.history?.id - res.type "json" - res.send JSON.stringify { + res.json { lines: lines version: version ranges: ranges diff --git a/services/web/app/coffee/Features/User/UserInfoController.coffee b/services/web/app/coffee/Features/User/UserInfoController.coffee index 56883d6f1c..659c17416a 100644 --- a/services/web/app/coffee/Features/User/UserInfoController.coffee +++ b/services/web/app/coffee/Features/User/UserInfoController.coffee @@ -37,7 +37,7 @@ module.exports = UserController = sendFormattedPersonalInfo: (user, res, next = (error) ->) -> info = UserController.formatPersonalInfo(user) - res.send JSON.stringify(info) + res.json info formatPersonalInfo: (user, callback = (error, info) ->) -> if !user? diff --git a/services/web/test/acceptance/coffee/helpers/MockDocstoreApi.coffee b/services/web/test/acceptance/coffee/helpers/MockDocstoreApi.coffee index 2c78d93321..96fc75dc59 100644 --- a/services/web/test/acceptance/coffee/helpers/MockDocstoreApi.coffee +++ b/services/web/test/acceptance/coffee/helpers/MockDocstoreApi.coffee @@ -21,7 +21,7 @@ module.exports = MockDocStoreApi = app.get "/project/:project_id/doc", (req, res, next) => docs = (doc for doc_id, doc of @docs[req.params.project_id]) - res.send JSON.stringify docs + res.json docs app.get "/project/:project_id/doc/:doc_id", (req, res, next) => {project_id, doc_id} = req.params @@ -29,7 +29,7 @@ module.exports = MockDocStoreApi = if !doc? or (doc.deleted and !req.query.include_deleted) res.sendStatus 404 else - res.send JSON.stringify doc + res.json doc app.delete "/project/:project_id/doc/:doc_id", (req, res, next) => {project_id, doc_id} = req.params diff --git a/services/web/test/unit/coffee/Documents/DocumentControllerTests.coffee b/services/web/test/unit/coffee/Documents/DocumentControllerTests.coffee index 6f4db7f8d5..d9d2e542ef 100644 --- a/services/web/test/unit/coffee/Documents/DocumentControllerTests.coffee +++ b/services/web/test/unit/coffee/Documents/DocumentControllerTests.coffee @@ -64,7 +64,7 @@ describe "DocumentController", -> .should.equal true it "should return the document data to the client as JSON", -> - @res.type.should.equal "json" + @res.type.should.equal "application/json" @res.body.should.equal JSON.stringify lines: @doc_lines version: @version @@ -91,7 +91,7 @@ describe "DocumentController", -> @DocumentController.getDocument(@req, @res, @next) it "should return the history id to the client as JSON", -> - @res.type.should.equal "json" + @res.type.should.equal "application/json" @res.body.should.equal JSON.stringify lines: @doc_lines version: @version diff --git a/services/web/test/unit/coffee/helpers/MockResponse.coffee b/services/web/test/unit/coffee/helpers/MockResponse.coffee index d7fbb76a69..7b2c8e88cd 100644 --- a/services/web/test/unit/coffee/helpers/MockResponse.coffee +++ b/services/web/test/unit/coffee/helpers/MockResponse.coffee @@ -56,11 +56,12 @@ class MockResponse status = 200 @statusCode = status @returned = true + @type = 'application/json' if 200 <= status < 300 @success = true else @success = false - @body = body if body + @body = JSON.stringify(body) if body @callback() if @callback? status: (@statusCode)->