From 9888d6631a10ffad5f8a2fc6c6b77040387d5567 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Fri, 24 Jun 2016 15:46:37 +0100 Subject: [PATCH] don't error if references is not enabled --- .../References/ReferencesController.coffee | 8 +++--- .../ReferencesControllerTests.coffee | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/services/web/app/coffee/Features/References/ReferencesController.coffee b/services/web/app/coffee/Features/References/ReferencesController.coffee index 0536e3b680..5976af9430 100644 --- a/services/web/app/coffee/Features/References/ReferencesController.coffee +++ b/services/web/app/coffee/Features/References/ReferencesController.coffee @@ -15,7 +15,7 @@ module.exports = ReferencesController = return res.sendStatus 400 logger.log {projectId, docIds: docIds}, "index references for project" ReferencesHandler.index projectId, docIds, (err, data) -> - if err + if err? logger.err {err, projectId}, "error indexing all references" return res.sendStatus 500 ReferencesController._handleIndexResponse(req, res, projectId, shouldBroadcast, data) @@ -25,13 +25,15 @@ module.exports = ReferencesController = shouldBroadcast = req.body.shouldBroadcast logger.log {projectId}, "index all references for project" ReferencesHandler.indexAll projectId, (err, data) -> - if err + if err? logger.err {err, projectId}, "error indexing all references" return res.sendStatus 500 ReferencesController._handleIndexResponse(req, res, projectId, shouldBroadcast, data) _handleIndexResponse: (req, res, projectId, shouldBroadcast, data) -> - if shouldBroadcast + if !data? or !data.keys? + return res.send() + else if shouldBroadcast logger.log {projectId}, "emitting new references keys to connected clients" EditorRealTimeController.emitToRoom projectId, 'references:keys:updated', data.keys return res.json data diff --git a/services/web/test/UnitTests/coffee/References/ReferencesControllerTests.coffee b/services/web/test/UnitTests/coffee/References/ReferencesControllerTests.coffee index 16266c0820..0d58da7631 100644 --- a/services/web/test/UnitTests/coffee/References/ReferencesControllerTests.coffee +++ b/services/web/test/UnitTests/coffee/References/ReferencesControllerTests.coffee @@ -32,6 +32,7 @@ describe "ReferencesController", -> shouldBroadcast: false @res = new MockResponse() @res.json = sinon.stub() + @res.send = sinon.stub() @res.sendStatus = sinon.stub() @fakeResponseData = projectId: @projectId, @@ -113,6 +114,30 @@ describe "ReferencesController", -> @res.json.calledWith(@fakeResponseData).should.equal true done() + describe 'there is no dataaaaaaa', -> + + beforeEach -> + @ReferencesHandler.indexAll.callsArgWith(1) + @call = (callback) => + @controller.indexAll @req, @res + callback() + + it 'should not call EditorRealTimeController.emitToRoom', (done) -> + @call () => + @EditorRealTimeController.emitToRoom.callCount.should.equal 0 + done() + + it 'should not produce an error', (done) -> + @call () => + @res.sendStatus.callCount.should.equal 0 + @res.sendStatus.calledWith(500).should.equal false + @res.sendStatus.calledWith(400).should.equal false + done() + + it 'should close the response', (done) -> + @call () => + @res.send.called.should.equal true + done() describe 'index', ->