2014-02-12 05:23:40 -05:00
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
sinon = require('sinon')
|
|
|
|
require('chai').should()
|
2014-11-26 09:07:04 -05:00
|
|
|
expect = require("chai").expect
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
modulePath = require('path').join __dirname, '../../../../app/js/Features/Editor/EditorController'
|
|
|
|
MockClient = require "../helpers/MockClient"
|
|
|
|
assert = require('assert')
|
|
|
|
|
|
|
|
describe "EditorController", ->
|
|
|
|
beforeEach ->
|
|
|
|
@project_id = "test-project-id"
|
2018-02-01 10:31:42 -05:00
|
|
|
@source = "dropbox"
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
@doc = _id: @doc_id = "test-doc-id"
|
|
|
|
@docName = "doc.tex"
|
|
|
|
@docLines = ["1234","dskl"]
|
|
|
|
@file = _id: @file_id ="dasdkjk"
|
|
|
|
@fileName = "file.png"
|
|
|
|
@fsPath = "/folder/file.png"
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
@folder_id = "123ksajdn"
|
|
|
|
@folder = _id: @folder_id
|
|
|
|
@folderName = "folder"
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
@callback = sinon.stub()
|
2018-02-01 10:31:42 -05:00
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
@EditorController = SandboxedModule.require modulePath, requires:
|
2018-02-01 10:31:42 -05:00
|
|
|
'../Project/ProjectEntityUpdateHandler' : @ProjectEntityUpdateHandler = {}
|
|
|
|
'../Project/ProjectOptionsHandler' : @ProjectOptionsHandler =
|
|
|
|
setCompiler: sinon.stub().yields()
|
|
|
|
setSpellCheckLanguage: sinon.stub().yields()
|
|
|
|
'../Project/ProjectDetailsHandler': @ProjectDetailsHandler =
|
|
|
|
setProjectDescription: sinon.stub().yields()
|
|
|
|
renameProject: sinon.stub().yields()
|
|
|
|
setPublicAccessLevel: sinon.stub().yields()
|
|
|
|
'../Project/ProjectDeleter' : @ProjectDeleter = {}
|
|
|
|
'../DocumentUpdater/DocumentUpdaterHandler' : @DocumentUpdaterHandler =
|
|
|
|
flushDocToMongo: sinon.stub().yields()
|
|
|
|
setDocument: sinon.stub().yields()
|
|
|
|
'./EditorRealTimeController':@EditorRealTimeController =
|
|
|
|
emitToRoom: sinon.stub()
|
|
|
|
"metrics-sharelatex": @Metrics = inc: sinon.stub()
|
2014-02-12 05:23:40 -05:00
|
|
|
"logger-sharelatex": @logger =
|
|
|
|
log: sinon.stub()
|
|
|
|
err: sinon.stub()
|
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
describe 'addDoc', ->
|
|
|
|
beforeEach ->
|
|
|
|
@ProjectEntityUpdateHandler.addDoc = sinon.stub().yields(null, @doc, @folder_id)
|
|
|
|
@EditorController.addDoc @project_id, @folder_id, @docName, @docLines, @source, @user_id, @callback
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'should add the doc using the project entity handler', ->
|
|
|
|
@ProjectEntityUpdateHandler.addDoc
|
|
|
|
.calledWith(@project_id, @folder_id, @docName, @docLines)
|
|
|
|
.should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'should send the update out to the users in the project', ->
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, "reciveNewDoc", @folder_id, @doc, @source)
|
|
|
|
.should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'calls the callback', ->
|
|
|
|
@callback.calledWith(null, @doc).should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
describe 'addFile', ->
|
2014-02-12 05:23:40 -05:00
|
|
|
beforeEach ->
|
2018-02-01 10:31:42 -05:00
|
|
|
@ProjectEntityUpdateHandler.addFile = sinon.stub().yields(null, @file, @folder_id)
|
|
|
|
@EditorController.addFile @project_id, @folder_id, @fileName, @fsPath, @source, @user_id, @callback
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'should add the folder using the project entity handler', ->
|
|
|
|
@ProjectEntityUpdateHandler.addFile
|
|
|
|
.calledWith(@project_id, @folder_id, @fileName, @fsPath, @user_id)
|
|
|
|
.should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'should send the update of a new folder out to the users in the project', ->
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, "reciveNewFile", @folder_id, @file, @source)
|
|
|
|
.should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'calls the callback', ->
|
|
|
|
@callback.calledWith(null, @file).should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
describe 'upsertDoc', ->
|
|
|
|
beforeEach ->
|
|
|
|
@ProjectEntityUpdateHandler.upsertDoc = sinon.stub().yields(null, @doc, false)
|
|
|
|
@EditorController.upsertDoc @project_id, @folder_id, @docName, @docLines, @source, @user_id, @callback
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'upserts the doc using the project entity handler', ->
|
|
|
|
@ProjectEntityUpdateHandler.upsertDoc
|
|
|
|
.calledWith(@project_id, @folder_id, @docName, @docLines, @source)
|
|
|
|
.should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'returns the doc', ->
|
|
|
|
@callback.calledWith(null, @doc).should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
describe 'doc does not exist', ->
|
|
|
|
beforeEach ->
|
|
|
|
@ProjectEntityUpdateHandler.upsertDoc = sinon.stub().yields(null, @doc, true)
|
|
|
|
@EditorController.upsertDoc @project_id, @folder_id, @docName, @docLines, @source, @user_id, @callback
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'sends an update out to users in the project', ->
|
2014-02-12 05:23:40 -05:00
|
|
|
@EditorRealTimeController.emitToRoom
|
2014-10-15 10:18:31 -04:00
|
|
|
.calledWith(@project_id, "reciveNewDoc", @folder_id, @doc, @source)
|
2014-02-12 05:23:40 -05:00
|
|
|
.should.equal true
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
describe 'upsertFile', ->
|
2014-11-26 09:07:04 -05:00
|
|
|
beforeEach ->
|
2018-02-01 10:31:42 -05:00
|
|
|
@ProjectEntityUpdateHandler.upsertFile = sinon.stub().yields(null, @file, false)
|
|
|
|
@EditorController.upsertFile @project_id, @folder_id, @fileName, @fsPath, @source, @user_id, @callback
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'upserts the file using the project entity handler', ->
|
|
|
|
@ProjectEntityUpdateHandler.upsertFile
|
|
|
|
.calledWith(@project_id, @folder_id, @fileName, @fsPath, @user_id)
|
|
|
|
.should.equal true
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'returns the file', ->
|
|
|
|
@callback.calledWith(null, @file).should.equal true
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
describe 'file does not exist', ->
|
|
|
|
beforeEach ->
|
|
|
|
@ProjectEntityUpdateHandler.upsertFile = sinon.stub().yields(null, @file, true)
|
|
|
|
@EditorController.upsertFile @project_id, @folder_id, @fileName, @fsPath, @source, @user_id, @callback
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'should send the update out to users in the project', ->
|
2014-02-12 05:23:40 -05:00
|
|
|
@EditorRealTimeController.emitToRoom
|
2014-10-15 10:18:31 -04:00
|
|
|
.calledWith(@project_id, "reciveNewFile", @folder_id, @file, @source)
|
2014-02-12 05:23:40 -05:00
|
|
|
.should.equal true
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
describe "upsertDocWithPath", ->
|
2014-11-26 09:07:04 -05:00
|
|
|
beforeEach ->
|
2018-02-01 10:31:42 -05:00
|
|
|
@docPath = '/folder/doc'
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
@ProjectEntityUpdateHandler.upsertDocWithPath = sinon.stub().yields(null, @doc, false, [], @folder)
|
|
|
|
@EditorController.upsertDocWithPath @project_id, @docPath, @docLines, @source, @user_id, @callback
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'upserts the doc using the project entity handler', ->
|
|
|
|
@ProjectEntityUpdateHandler.upsertDocWithPath
|
|
|
|
.calledWith(@project_id, @docPath, @docLines, @source)
|
|
|
|
.should.equal true
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
describe 'doc does not exist', ->
|
|
|
|
beforeEach ->
|
|
|
|
@ProjectEntityUpdateHandler.upsertDocWithPath = sinon.stub().yields(null, @doc, true, [], @folder)
|
|
|
|
@EditorController.upsertDocWithPath @project_id, @docPath, @docLines, @source, @user_id, @callback
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'should send the update for the doc out to users in the project', ->
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, "reciveNewDoc", @folder_id, @doc, @source)
|
2017-12-20 10:52:28 -05:00
|
|
|
.should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
describe 'folders required for doc do not exist', ->
|
|
|
|
beforeEach ->
|
|
|
|
folders = [
|
|
|
|
@folderA = { _id: 2, parentFolder_id: 1}
|
|
|
|
@folderB = { _id: 3, parentFolder_id: 2}
|
|
|
|
]
|
|
|
|
@ProjectEntityUpdateHandler.upsertDocWithPath = sinon.stub().yields(null, @doc, true, folders, @folderB)
|
|
|
|
@EditorController.upsertDocWithPath @project_id, @docPath, @docLines, @source, @user_id, @callback
|
|
|
|
|
|
|
|
it 'should send the update for each folder to users in the project', ->
|
2014-02-12 05:23:40 -05:00
|
|
|
@EditorRealTimeController.emitToRoom
|
2018-02-01 10:31:42 -05:00
|
|
|
.calledWith(@project_id, "reciveNewFolder", @folderA.parentFolder_id, @folderA)
|
|
|
|
.should.equal true
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, "reciveNewFolder", @folderB.parentFolder_id, @folderB)
|
2014-02-12 05:23:40 -05:00
|
|
|
.should.equal true
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
describe "upsertFileWithPath", ->
|
2014-11-26 09:07:04 -05:00
|
|
|
beforeEach ->
|
2018-02-01 10:31:42 -05:00
|
|
|
@filePath = '/folder/file'
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
@ProjectEntityUpdateHandler.upsertFileWithPath = sinon.stub().yields(null, @file, false, [], @folder)
|
|
|
|
@EditorController.upsertFileWithPath @project_id, @filePath, @fsPath, @source, @user_id, @callback
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'upserts the file using the project entity handler', ->
|
|
|
|
@ProjectEntityUpdateHandler.upsertFileWithPath
|
|
|
|
.calledWith(@project_id, @filePath, @fsPath)
|
|
|
|
.should.equal true
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
describe 'file does not exist', ->
|
|
|
|
beforeEach ->
|
|
|
|
@ProjectEntityUpdateHandler.upsertFileWithPath = sinon.stub().yields(null, @file, true, [], @folder)
|
|
|
|
@EditorController.upsertFileWithPath @project_id, @filePath, @fsPath, @source, @user_id, @callback
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'should send the update for the file out to users in the project', ->
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, "reciveNewFile", @folder_id, @file, @source)
|
|
|
|
.should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
describe 'folders required for file do not exist', ->
|
|
|
|
beforeEach ->
|
|
|
|
folders = [
|
|
|
|
@folderA = { _id: 2, parentFolder_id: 1}
|
|
|
|
@folderB = { _id: 3, parentFolder_id: 2}
|
|
|
|
]
|
|
|
|
@ProjectEntityUpdateHandler.upsertFileWithPath = sinon.stub().yields(null, @file, true, folders, @folderB)
|
|
|
|
@EditorController.upsertFileWithPath @project_id, @filePath, @fsPath, @source, @user_id, @callback
|
|
|
|
|
|
|
|
it 'should send the update for each folder to users in the project', ->
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, "reciveNewFolder", @folderA.parentFolder_id, @folderA)
|
|
|
|
.should.equal true
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, "reciveNewFolder", @folderB.parentFolder_id, @folderB)
|
|
|
|
.should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
describe 'addFolder', ->
|
|
|
|
beforeEach ->
|
|
|
|
@EditorController._notifyProjectUsersOfNewFolder = sinon.stub().yields()
|
|
|
|
@ProjectEntityUpdateHandler.addFolder = sinon.stub().yields(null, @folder, @folder_id)
|
|
|
|
@EditorController.addFolder @project_id, @folder_id, @folderName, @source, @callback
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'should add the folder using the project entity handler', ->
|
|
|
|
@ProjectEntityUpdateHandler.addFolder
|
|
|
|
.calledWith(@project_id, @folder_id, @folderName)
|
|
|
|
.should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'should notifyProjectUsersOfNewFolder', ->
|
|
|
|
@EditorController._notifyProjectUsersOfNewFolder
|
|
|
|
.calledWith(@project_id, @folder_id, @folder)
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'should return the folder in the callback', ->
|
|
|
|
@callback.calledWith(null, @folder).should.equal true
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
describe 'mkdirp', ->
|
2014-11-26 09:07:04 -05:00
|
|
|
beforeEach ->
|
|
|
|
@path = "folder1/folder2"
|
2018-02-01 10:31:42 -05:00
|
|
|
@folders = [
|
|
|
|
@folderA = { _id: 2, parentFolder_id: 1}
|
|
|
|
@folderB = { _id: 3, parentFolder_id: 2}
|
|
|
|
]
|
|
|
|
@EditorController._notifyProjectUsersOfNewFolders = sinon.stub().yields()
|
|
|
|
@ProjectEntityUpdateHandler.mkdirp = sinon.stub().yields(null, @folders, @folder)
|
|
|
|
@EditorController.mkdirp @project_id, @path, @callback
|
|
|
|
|
|
|
|
it 'should create the folder using the project entity handler', ->
|
|
|
|
@ProjectEntityUpdateHandler.mkdirp
|
|
|
|
.calledWith(@project_id, @path)
|
|
|
|
.should.equal true
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'should notifyProjectUsersOfNewFolder', ->
|
|
|
|
@EditorController._notifyProjectUsersOfNewFolders
|
|
|
|
.calledWith(@project_id, @folders)
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'should return the folder in the callback', ->
|
|
|
|
@callback.calledWith(null, @folders, @folder).should.equal true
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
describe 'deleteEntity', ->
|
2014-11-26 09:07:04 -05:00
|
|
|
beforeEach ->
|
2018-02-01 10:31:42 -05:00
|
|
|
@entity_id = "entity_id_here"
|
|
|
|
@type = "doc"
|
|
|
|
@ProjectEntityUpdateHandler.deleteEntity = sinon.stub().yields()
|
|
|
|
@EditorController.deleteEntity @project_id, @entity_id, @type, @source, @user_id, @callback
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'should delete the folder using the project entity handler', ->
|
|
|
|
@ProjectEntityUpdateHandler.deleteEntity
|
|
|
|
.calledWith(@project_id, @entity_id, @type, @user_id)
|
|
|
|
.should.equal.true
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'notify users an entity has been deleted', ->
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, "removeEntity", @entity_id, @source)
|
|
|
|
.should.equal true
|
2014-11-26 09:07:04 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
describe "deleteEntityWithPath", ->
|
|
|
|
beforeEach () ->
|
2014-02-12 05:23:40 -05:00
|
|
|
@entity_id = "entity_id_here"
|
2018-02-01 10:31:42 -05:00
|
|
|
@ProjectEntityUpdateHandler.deleteEntityWithPath = sinon.stub().yields(null, @entity_id)
|
|
|
|
@path = "folder1/folder2"
|
|
|
|
@EditorController.deleteEntityWithPath @project_id, @path, @source, @user_id, @callback
|
2017-12-15 05:23:10 -05:00
|
|
|
|
|
|
|
it 'should delete the folder using the project entity handler', ->
|
2018-02-01 10:31:42 -05:00
|
|
|
@ProjectEntityUpdateHandler.deleteEntityWithPath
|
|
|
|
.calledWith(@project_id, @path, @user_id)
|
2017-12-15 05:23:10 -05:00
|
|
|
.should.equal.true
|
|
|
|
|
|
|
|
it 'notify users an entity has been deleted', ->
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, "removeEntity", @entity_id, @source)
|
|
|
|
.should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
describe "notifyUsersProjectHasBeenDeletedOrRenamed", ->
|
|
|
|
it 'should emmit a message to all users in a project', (done)->
|
|
|
|
@EditorController.notifyUsersProjectHasBeenDeletedOrRenamed @project_id, (err)=>
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, "projectRenamedOrDeletedByExternalSource")
|
|
|
|
.should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "updateProjectDescription", ->
|
|
|
|
beforeEach ->
|
|
|
|
@description = "new description"
|
2018-02-01 10:31:42 -05:00
|
|
|
@EditorController.updateProjectDescription @project_id, @description, @callback
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it "should send the new description to the project details handler", ->
|
|
|
|
@ProjectDetailsHandler.setProjectDescription.calledWith(@project_id, @description).should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it "should notify the other clients about the updated description", ->
|
|
|
|
@EditorRealTimeController.emitToRoom.calledWith(@project_id, "projectDescriptionUpdated", @description).should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2014-04-04 11:21:20 -04:00
|
|
|
describe "deleteProject", ->
|
|
|
|
beforeEach ->
|
|
|
|
@err = "errro"
|
2014-04-07 15:46:58 -04:00
|
|
|
@ProjectDeleter.deleteProject = sinon.stub().callsArgWith(1, @err)
|
2014-04-04 11:21:20 -04:00
|
|
|
|
|
|
|
it "should call the project handler", (done)->
|
|
|
|
@EditorController.deleteProject @project_id, (err)=>
|
|
|
|
err.should.equal @err
|
2014-04-07 15:46:58 -04:00
|
|
|
@ProjectDeleter.deleteProject.calledWith(@project_id).should.equal true
|
2014-04-04 11:21:20 -04:00
|
|
|
done()
|
|
|
|
|
2014-04-04 11:35:02 -04:00
|
|
|
describe "renameEntity", ->
|
2017-12-20 10:21:36 -05:00
|
|
|
beforeEach (done) ->
|
2014-04-04 11:35:02 -04:00
|
|
|
@entity_id = "entity_id_here"
|
|
|
|
@entityType = "doc"
|
|
|
|
@newName = "bobsfile.tex"
|
2018-02-01 10:31:42 -05:00
|
|
|
@ProjectEntityUpdateHandler.renameEntity = sinon.stub().yields()
|
2014-04-04 11:35:02 -04:00
|
|
|
|
2017-12-20 10:21:36 -05:00
|
|
|
@EditorController.renameEntity @project_id, @entity_id, @entityType, @newName, @user_id, done
|
2014-04-04 11:35:02 -04:00
|
|
|
|
2017-12-20 10:21:36 -05:00
|
|
|
it "should call the project handler", ->
|
2018-02-01 10:31:42 -05:00
|
|
|
@ProjectEntityUpdateHandler.renameEntity
|
2017-12-20 10:21:36 -05:00
|
|
|
.calledWith(@project_id, @entity_id, @entityType, @newName, @user_id)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it "should emit the update to the room", ->
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, 'reciveEntityRename', @entity_id, @newName)
|
|
|
|
.should.equal true
|
2014-04-04 11:35:02 -04:00
|
|
|
|
2014-04-04 11:40:53 -04:00
|
|
|
describe "moveEntity", ->
|
|
|
|
beforeEach ->
|
|
|
|
@entity_id = "entity_id_here"
|
|
|
|
@entityType = "doc"
|
2018-02-01 10:31:42 -05:00
|
|
|
@ProjectEntityUpdateHandler.moveEntity = sinon.stub().yields()
|
|
|
|
@EditorController.moveEntity @project_id, @entity_id, @folder_id, @entityType, @user_id, @callback
|
2014-04-04 11:40:53 -04:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it "should call the ProjectEntityUpdateHandler", ->
|
|
|
|
@ProjectEntityUpdateHandler.moveEntity
|
|
|
|
.calledWith(@project_id, @entity_id, @folder_id, @entityType, @user_id)
|
|
|
|
.should.equal true
|
2016-03-15 08:29:41 -04:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it "should emit the update to the room", ->
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, 'reciveEntityMove', @entity_id, @folder_id)
|
|
|
|
.should.equal true
|
2014-04-04 11:40:53 -04:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it "calls the callback", ->
|
|
|
|
@callback.called.should.equal true
|
2014-04-04 11:49:44 -04:00
|
|
|
|
|
|
|
describe "renameProject", ->
|
|
|
|
beforeEach ->
|
|
|
|
@err = "errro"
|
|
|
|
@newName = "new name here"
|
2018-02-01 10:31:42 -05:00
|
|
|
@EditorController.renameProject @project_id, @newName, @callback
|
2014-04-04 11:49:44 -04:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it "should call the EditorController", ->
|
|
|
|
@ProjectDetailsHandler.renameProject.calledWith(@project_id, @newName).should.equal true
|
2014-04-04 11:49:44 -04:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it "should emit the update to the room", ->
|
|
|
|
@EditorRealTimeController.emitToRoom.calledWith(@project_id, 'projectNameUpdated', @newName).should.equal true
|
2014-04-04 11:49:44 -04:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
describe "setCompiler", ->
|
|
|
|
beforeEach ->
|
|
|
|
@compiler = "latex"
|
|
|
|
@EditorController.setCompiler @project_id, @compiler, @callback
|
2014-04-04 11:53:59 -04:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it "should send the new compiler and project id to the project options handler", ->
|
|
|
|
@ProjectOptionsHandler.setCompiler
|
|
|
|
.calledWith(@project_id, @compiler)
|
|
|
|
.should.equal true
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, "compilerUpdated", @compiler)
|
|
|
|
.should.equal true
|
2014-04-04 11:53:59 -04:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
describe "setSpellCheckLanguage", ->
|
|
|
|
beforeEach ->
|
|
|
|
@languageCode = "fr"
|
|
|
|
@EditorController.setSpellCheckLanguage @project_id, @languageCode, @callback
|
2014-04-04 11:53:59 -04:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it "should send the new languageCode and project id to the project options handler", ->
|
|
|
|
@ProjectOptionsHandler.setSpellCheckLanguage
|
|
|
|
.calledWith(@project_id, @languageCode)
|
|
|
|
.should.equal true
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, "spellCheckLanguageUpdated", @languageCode)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
describe "setPublicAccessLevel", ->
|
2017-10-04 11:31:24 -04:00
|
|
|
describe 'when setting to private', ->
|
|
|
|
beforeEach ->
|
|
|
|
@newAccessLevel = 'private'
|
2018-02-01 10:31:42 -05:00
|
|
|
@ProjectDetailsHandler.ensureTokensArePresent = sinon.stub().yields(null, @tokens)
|
|
|
|
@EditorController.setPublicAccessLevel @project_id, @newAccessLevel, @callback
|
2017-10-04 11:31:24 -04:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'should set the access level', ->
|
2017-10-04 11:31:24 -04:00
|
|
|
@ProjectDetailsHandler.setPublicAccessLevel
|
2018-02-01 10:31:42 -05:00
|
|
|
.calledWith(@project_id, @newAccessLevel)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it 'should broadcast the access level change', ->
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, 'project:publicAccessLevel:changed')
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it 'should not ensure tokens are present for project', ->
|
|
|
|
@ProjectDetailsHandler.ensureTokensArePresent
|
|
|
|
.calledWith(@project_id)
|
|
|
|
.should.equal false
|
|
|
|
|
|
|
|
it 'should not broadcast a token change', ->
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, 'project:tokens:changed', {tokens: @tokens})
|
|
|
|
.should.equal false
|
2017-10-04 11:31:24 -04:00
|
|
|
|
|
|
|
describe 'when setting to tokenBased', ->
|
|
|
|
beforeEach ->
|
|
|
|
@newAccessLevel = 'tokenBased'
|
|
|
|
@tokens = {readOnly: 'aaa', readAndWrite: '42bbb'}
|
2018-02-01 10:31:42 -05:00
|
|
|
@ProjectDetailsHandler.ensureTokensArePresent = sinon.stub().yields(null, @tokens)
|
|
|
|
@EditorController.setPublicAccessLevel @project_id, @newAccessLevel, @callback
|
2014-04-04 11:53:59 -04:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'should set the access level', ->
|
|
|
|
@ProjectDetailsHandler.setPublicAccessLevel
|
|
|
|
.calledWith(@project_id, @newAccessLevel)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it 'should broadcast the access level change', ->
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, 'project:publicAccessLevel:changed')
|
|
|
|
.should.equal true
|
2014-04-04 11:59:45 -04:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it 'should ensure tokens are present for project', ->
|
|
|
|
@ProjectDetailsHandler.ensureTokensArePresent
|
|
|
|
.calledWith(@project_id)
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
it 'should broadcast the token change too', ->
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, 'project:tokens:changed', {tokens: @tokens})
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
describe "setRootDoc", ->
|
2014-04-04 11:59:45 -04:00
|
|
|
beforeEach ->
|
|
|
|
@newRootDocID = "21312321321"
|
2018-02-01 10:31:42 -05:00
|
|
|
@ProjectEntityUpdateHandler.setRootDoc = sinon.stub().yields()
|
|
|
|
@EditorController.setRootDoc @project_id, @newRootDocID, @callback
|
2014-04-04 11:59:45 -04:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it "should call the ProjectEntityUpdateHandler", ->
|
|
|
|
@ProjectEntityUpdateHandler.setRootDoc
|
|
|
|
.calledWith(@project_id, @newRootDocID)
|
|
|
|
.should.equal true
|
2014-04-04 11:59:45 -04:00
|
|
|
|
2018-02-01 10:31:42 -05:00
|
|
|
it "should emit the update to the room", ->
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, 'rootDocUpdated', @newRootDocID)
|
|
|
|
.should.equal true
|