don't error if references is not enabled

This commit is contained in:
Henry Oswald 2016-06-24 15:46:37 +01:00
parent 6e59a10fb3
commit 9888d6631a
2 changed files with 30 additions and 3 deletions

View file

@ -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

View file

@ -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', ->