From 06ec5556b094acd7f0e5c2c681e6ab92171b5e81 Mon Sep 17 00:00:00 2001 From: Ersun Warncke Date: Wed, 18 Mar 2020 10:07:01 -0400 Subject: [PATCH] [misc] fix express deprecations Co-Authored-By: Jakob Ackermann --- services/docstore/app.js | 6 ++--- services/docstore/app/js/HttpController.js | 24 +++++++++---------- .../test/unit/js/HttpControllerTests.js | 15 ++++++------ 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/services/docstore/app.js b/services/docstore/app.js index 468dc77983..555f31137b 100644 --- a/services/docstore/app.js +++ b/services/docstore/app.js @@ -52,7 +52,7 @@ app.post( bodyParser.json({ limit: (Settings.max_doc_length + 64 * 1024) * 2 }), HttpController.updateDoc ) -app.del('/project/:project_id/doc/:doc_id', HttpController.deleteDoc) +app.delete('/project/:project_id/doc/:doc_id', HttpController.deleteDoc) app.post('/project/:project_id/archive', HttpController.archiveAllDocs) app.post('/project/:project_id/unarchive', HttpController.unArchiveAllDocs) @@ -65,9 +65,9 @@ app.get('/status', (req, res) => res.send('docstore is alive')) app.use(function (error, req, res, next) { logger.error({ err: error, req }, 'request errored') if (error instanceof Errors.NotFoundError) { - return res.send(404) + return res.sendStatus(404) } else { - return res.send(500, 'Oops, something went wrong') + return res.status(500).send('Oops, something went wrong') } }) diff --git a/services/docstore/app/js/HttpController.js b/services/docstore/app/js/HttpController.js index 86139e6f45..50c779736c 100644 --- a/services/docstore/app/js/HttpController.js +++ b/services/docstore/app/js/HttpController.js @@ -35,9 +35,9 @@ module.exports = HttpController = { } logger.log({ doc_id, project_id }, 'got doc') if (doc == null) { - return res.send(404) + return res.sendStatus(404) } else if (doc.deleted && !include_deleted) { - return res.send(404) + return res.sendStatus(404) } else { return res.json(HttpController._buildDocView(doc)) } @@ -56,7 +56,7 @@ module.exports = HttpController = { return next(error) } if (doc == null) { - return res.send(404) + return res.sendStatus(404) } else { res.setHeader('content-type', 'text/plain') return res.send(HttpController._buildRawDocView(doc)) @@ -118,19 +118,19 @@ module.exports = HttpController = { if (lines == null || !(lines instanceof Array)) { logger.error({ project_id, doc_id }, 'no doc lines provided') - res.send(400) // Bad Request + res.sendStatus(400) // Bad Request return } if (version == null || typeof version === !'number') { logger.error({ project_id, doc_id }, 'no doc version provided') - res.send(400) // Bad Request + res.sendStatus(400) // Bad Request return } if (ranges == null) { logger.error({ project_id, doc_id }, 'no doc ranges provided') - res.send(400) // Bad Request + res.sendStatus(400) // Bad Request return } @@ -174,7 +174,7 @@ module.exports = HttpController = { if (error != null) { return next(error) } - return res.send(204) + return res.sendStatus(204) }) }, @@ -218,7 +218,7 @@ module.exports = HttpController = { if (error != null) { return next(error) } - return res.send(204) + return res.sendStatus(204) }) }, @@ -232,7 +232,7 @@ module.exports = HttpController = { if (error != null) { return next(error) } - return res.send(200) + return res.sendStatus(200) }) }, @@ -246,7 +246,7 @@ module.exports = HttpController = { if (error != null) { return next(error) } - return res.send(204) + return res.sendStatus(204) }) }, @@ -254,9 +254,9 @@ module.exports = HttpController = { return HealthChecker.check(function (err) { if (err != null) { logger.err({ err }, 'error performing health check') - return res.send(500) + return res.sendStatus(500) } else { - return res.send(200) + return res.sendStatus(200) } }) } diff --git a/services/docstore/test/unit/js/HttpControllerTests.js b/services/docstore/test/unit/js/HttpControllerTests.js index 5463660269..46132737f2 100644 --- a/services/docstore/test/unit/js/HttpControllerTests.js +++ b/services/docstore/test/unit/js/HttpControllerTests.js @@ -37,6 +37,7 @@ describe('HttpController', function () { }) this.res = { send: sinon.stub(), + sendStatus: sinon.stub(), json: sinon.stub(), setHeader: sinon.stub() } @@ -111,7 +112,7 @@ describe('HttpController', function () { it('should return 404 if the query string delete is not set ', function () { this.HttpController.getDoc(this.req, this.res, this.next) - return this.res.send.calledWith(404).should.equal(true) + return this.res.sendStatus.calledWith(404).should.equal(true) }) return it('should return the doc as JSON if include_deleted is set to true', function () { @@ -374,7 +375,7 @@ describe('HttpController', function () { }) return it('should return a 400 (bad request) response', function () { - return this.res.send.calledWith(400).should.equal(true) + return this.res.sendStatus.calledWith(400).should.equal(true) }) }) @@ -390,7 +391,7 @@ describe('HttpController', function () { }) return it('should return a 400 (bad request) response', function () { - return this.res.send.calledWith(400).should.equal(true) + return this.res.sendStatus.calledWith(400).should.equal(true) }) }) @@ -406,7 +407,7 @@ describe('HttpController', function () { }) return it('should return a 400 (bad request) response', function () { - return this.res.send.calledWith(400).should.equal(true) + return this.res.sendStatus.calledWith(400).should.equal(true) }) }) @@ -447,7 +448,7 @@ describe('HttpController', function () { }) return it('should return a 204 (No Content)', function () { - return this.res.send.calledWith(204).should.equal(true) + return this.res.sendStatus.calledWith(204).should.equal(true) }) }) @@ -465,7 +466,7 @@ describe('HttpController', function () { }) return it('should return a 204 (No Content)', function () { - return this.res.send.calledWith(204).should.equal(true) + return this.res.sendStatus.calledWith(204).should.equal(true) }) }) @@ -484,7 +485,7 @@ describe('HttpController', function () { }) return it('should return 204', function () { - return sinon.assert.calledWith(this.res.send, 204) + return sinon.assert.calledWith(this.res.sendStatus, 204) }) }) })