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) ->
if !data? or !data.keys?
return res.send()
else if shouldBroadcast
return res.json({projectId, keys: []})
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

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