Преглед изворни кода

don't error if references is not enabled

Henry Oswald пре 10 година
родитељ
комит
9888d6631a

+ 5 - 3
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

+ 25 - 0
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', ->