Send an empty keys array when there is no data

This commit is contained in:
Shane Kilkelly 2016-07-26 14:23:00 +01:00
parent 8492ea7d28
commit e46901a21b
2 changed files with 5 additions and 4 deletions

View file

@ -32,8 +32,8 @@ module.exports = ReferencesController =
_handleIndexResponse: (req, res, projectId, shouldBroadcast, data) -> _handleIndexResponse: (req, res, projectId, shouldBroadcast, data) ->
if !data? or !data.keys? if !data? or !data.keys?
return res.send() return res.json({projectId, keys: []})
else if shouldBroadcast if shouldBroadcast
logger.log {projectId}, "emitting new references keys to connected clients" logger.log {projectId}, "emitting new references keys to connected clients"
EditorRealTimeController.emitToRoom projectId, 'references:keys:updated', data.keys EditorRealTimeController.emitToRoom projectId, 'references:keys:updated', data.keys
return res.json data return res.json data

View file

@ -134,9 +134,10 @@ describe "ReferencesController", ->
@res.sendStatus.calledWith(400).should.equal false @res.sendStatus.calledWith(400).should.equal false
done() done()
it 'should close the response', (done) -> it 'should send a response with an empty keys list', (done) ->
@call () => @call () =>
@res.send.called.should.equal true @res.json.called.should.equal true
@res.json.calledWith({projectId: @projectId, keys: []}).should.equal true
done() done()
describe 'index', -> describe 'index', ->