mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-31 04:41:32 +02:00
Change getLabelsForDoc to broadcastLabelsForDoc
This commit is contained in:
@@ -13,7 +13,7 @@ module.exports = LabelsController =
|
||||
return next(err)
|
||||
res.json {projectId: project_id, projectLabels: projectLabels}
|
||||
|
||||
getLabelsForDoc: (req, res, next) ->
|
||||
broadcastLabelsForDoc: (req, res, next) ->
|
||||
project_id = req.params.project_id
|
||||
doc_id = req.params.doc_id
|
||||
LabelsHandler.getLabelsForDoc project_id, doc_id, (err, docLabels) ->
|
||||
@@ -23,4 +23,4 @@ module.exports = LabelsController =
|
||||
EditorRealTimeController.emitToRoom project_id, 'broadcastDocLabels', {
|
||||
docId: doc_id, labels: docLabels
|
||||
}
|
||||
res.json {projectId: project_id, docId: doc_id, labels: docLabels}
|
||||
res.sendStatus(200)
|
||||
|
||||
@@ -195,7 +195,7 @@ module.exports = class Router
|
||||
webRouter.get '/project/download/zip', AuthorizationMiddlewear.ensureUserCanReadMultipleProjects, ProjectDownloadsController.downloadMultipleProjects
|
||||
|
||||
webRouter.get '/project/:project_id/labels', AuthorizationMiddlewear.ensureUserCanReadProject, AuthenticationController.requireLogin(), LabelsController.getAllLabels
|
||||
webRouter.get '/project/:project_id/doc/:doc_id/labels', AuthorizationMiddlewear.ensureUserCanReadProject, AuthenticationController.requireLogin(), LabelsController.getLabelsForDoc
|
||||
webRouter.post '/project/:project_id/doc/:doc_id/labels', AuthorizationMiddlewear.ensureUserCanReadProject, AuthenticationController.requireLogin(), LabelsController.broadcastLabelsForDoc
|
||||
|
||||
webRouter.get '/tag', AuthenticationController.requireLogin(), TagsController.getAllTags
|
||||
webRouter.post '/tag', AuthenticationController.requireLogin(), TagsController.createTag
|
||||
|
||||
@@ -35,9 +35,10 @@ define [
|
||||
|
||||
labels.loadDocLabelsFromServer = (docId) ->
|
||||
$http
|
||||
.get("/project/#{window.project_id}/doc/#{docId}/labels")
|
||||
.post(
|
||||
"/project/#{window.project_id}/doc/#{docId}/labels",
|
||||
{_csrf: window.csrfToken}
|
||||
)
|
||||
.success (data) ->
|
||||
if data.docId and data.labels
|
||||
state.documents[data.docId] = data.labels
|
||||
|
||||
return labels
|
||||
|
||||
@@ -64,31 +64,31 @@ describe 'LabelsController', ->
|
||||
@LabelsController.getAllLabels(@req, @res, @next)
|
||||
@res.json.callCount.should.equal 0
|
||||
|
||||
describe 'getLabelsForDoc', ->
|
||||
describe 'broadcastLabelsForDoc', ->
|
||||
beforeEach ->
|
||||
@LabelsHandler.getLabelsForDoc = sinon.stub().callsArgWith(2, null, @fakeLabels)
|
||||
@EditorRealTimeController.emitToRoom = sinon.stub()
|
||||
@docId = 'somedoc'
|
||||
@req = {params: {project_id: @projectId, doc_id: @docId}}
|
||||
@res = {json: sinon.stub()}
|
||||
@res = {sendStatus: sinon.stub()}
|
||||
@next = sinon.stub()
|
||||
|
||||
it 'should call LabelsHandler.getLabelsForDoc', () ->
|
||||
@LabelsController.getLabelsForDoc(@req, @res, @next)
|
||||
@LabelsController.broadcastLabelsForDoc(@req, @res, @next)
|
||||
@LabelsHandler.getLabelsForDoc.callCount.should.equal 1
|
||||
@LabelsHandler.getLabelsForDoc.calledWith(@projectId).should.equal true
|
||||
|
||||
it 'should call not call next with an error', () ->
|
||||
@LabelsController.getLabelsForDoc(@req, @res, @next)
|
||||
@LabelsController.broadcastLabelsForDoc(@req, @res, @next)
|
||||
@next.callCount.should.equal 0
|
||||
|
||||
it 'should send a json response', () ->
|
||||
@LabelsController.getLabelsForDoc(@req, @res, @next)
|
||||
@res.json.callCount.should.equal 1
|
||||
expect(@res.json.lastCall.args[0]).to.have.all.keys ['projectId', 'docId', 'labels']
|
||||
it 'should send a success response', () ->
|
||||
@LabelsController.broadcastLabelsForDoc(@req, @res, @next)
|
||||
@res.sendStatus.callCount.should.equal 1
|
||||
@res.sendStatus.calledWith(200).should.equal true
|
||||
|
||||
it 'should emit a message to room', () ->
|
||||
@LabelsController.getLabelsForDoc(@req, @res, @next)
|
||||
@LabelsController.broadcastLabelsForDoc(@req, @res, @next)
|
||||
@EditorRealTimeController.emitToRoom.callCount.should.equal 1
|
||||
lastCall = @EditorRealTimeController.emitToRoom.lastCall
|
||||
expect(lastCall.args[0]).to.equal @projectId
|
||||
@@ -105,15 +105,15 @@ describe 'LabelsController', ->
|
||||
@next = sinon.stub()
|
||||
|
||||
it 'should call LabelsHandler.getLabelsForDoc', () ->
|
||||
@LabelsController.getLabelsForDoc(@req, @res, @next)
|
||||
@LabelsController.broadcastLabelsForDoc(@req, @res, @next)
|
||||
@LabelsHandler.getLabelsForDoc.callCount.should.equal 1
|
||||
@LabelsHandler.getLabelsForDoc.calledWith(@projectId).should.equal true
|
||||
|
||||
it 'should call next with an error', ->
|
||||
@LabelsController.getLabelsForDoc(@req, @res, @next)
|
||||
@LabelsController.broadcastLabelsForDoc(@req, @res, @next)
|
||||
@next.callCount.should.equal 1
|
||||
expect(@next.lastCall.args[0]).to.be.instanceof Error
|
||||
|
||||
it 'should not send a json response', ->
|
||||
@LabelsController.getLabelsForDoc(@req, @res, @next)
|
||||
@LabelsController.broadcastLabelsForDoc(@req, @res, @next)
|
||||
@res.json.callCount.should.equal 0
|
||||
|
||||
Reference in New Issue
Block a user