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"
|
|
|
|
@project =
|
|
|
|
_id: @project_id
|
|
|
|
owner_ref:{_id:"something"}
|
|
|
|
|
|
|
|
|
|
|
|
@doc_id = "test-doc-id"
|
2014-10-15 10:18:31 -04:00
|
|
|
@source = "dropbox"
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
@user =
|
|
|
|
_id: @user_id = "user-id"
|
|
|
|
projects: {}
|
|
|
|
|
|
|
|
@rooms = {}
|
|
|
|
@io =
|
|
|
|
sockets :
|
|
|
|
clients : (room_id) =>
|
|
|
|
@rooms[room_id]
|
|
|
|
@DocumentUpdaterHandler = {}
|
|
|
|
@ProjectOptionsHandler =
|
|
|
|
setCompiler : sinon.spy()
|
|
|
|
setSpellCheckLanguage: sinon.spy()
|
2014-04-07 15:46:58 -04:00
|
|
|
@ProjectEntityHandler =
|
|
|
|
flushProjectToThirdPartyDataStore:sinon.stub()
|
2014-02-12 05:23:40 -05:00
|
|
|
@Project =
|
|
|
|
findPopulatedById: sinon.stub().callsArgWith(1, null, @project)
|
|
|
|
@client = new MockClient()
|
|
|
|
|
|
|
|
@settings =
|
|
|
|
apis:{thirdPartyDataStore:{emptyProjectFlushDelayMiliseconds:0.5}}
|
|
|
|
redis: web:{}
|
|
|
|
@dropboxProjectLinker = {}
|
|
|
|
@callback = sinon.stub()
|
|
|
|
@ProjectDetailsHandler =
|
|
|
|
setProjectDescription:sinon.stub()
|
2014-04-07 15:46:58 -04:00
|
|
|
@CollaboratorsHandler =
|
|
|
|
removeUserFromProject: sinon.stub().callsArgWith(2)
|
|
|
|
addUserToProject: sinon.stub().callsArgWith(3)
|
|
|
|
@ProjectDeleter =
|
|
|
|
deleteProject: sinon.stub()
|
2014-11-26 09:07:04 -05:00
|
|
|
@LockManager =
|
|
|
|
getLock : sinon.stub()
|
|
|
|
releaseLock : sinon.stub()
|
2014-02-12 05:23:40 -05:00
|
|
|
@EditorController = SandboxedModule.require modulePath, requires:
|
|
|
|
"../../infrastructure/Server" : io : @io
|
|
|
|
'../Project/ProjectEntityHandler' : @ProjectEntityHandler
|
|
|
|
'../Project/ProjectOptionsHandler' : @ProjectOptionsHandler
|
|
|
|
'../Project/ProjectDetailsHandler': @ProjectDetailsHandler
|
2014-04-07 15:46:58 -04:00
|
|
|
'../Project/ProjectDeleter' : @ProjectDeleter
|
|
|
|
'../Collaborators/CollaboratorsHandler': @CollaboratorsHandler
|
2014-02-12 05:23:40 -05:00
|
|
|
'../DocumentUpdater/DocumentUpdaterHandler' : @DocumentUpdaterHandler
|
|
|
|
'../../models/Project' : Project: @Project
|
|
|
|
"settings-sharelatex":@settings
|
|
|
|
'../Dropbox/DropboxProjectLinker':@dropboxProjectLinker
|
|
|
|
'./EditorRealTimeController':@EditorRealTimeController = {}
|
2017-04-03 11:18:30 -04:00
|
|
|
"metrics-sharelatex": @Metrics = { inc: sinon.stub() }
|
2014-03-22 05:34:32 -04:00
|
|
|
"../TrackChanges/TrackChangesManager": @TrackChangesManager = {}
|
2014-11-26 09:07:04 -05:00
|
|
|
"../../infrastructure/LockManager":@LockManager
|
2014-09-26 12:49:31 -04:00
|
|
|
'redis-sharelatex':createClient:-> auth:->
|
2014-02-12 05:23:40 -05:00
|
|
|
"logger-sharelatex": @logger =
|
|
|
|
log: sinon.stub()
|
|
|
|
err: sinon.stub()
|
|
|
|
|
|
|
|
describe "updating compiler used for project", ->
|
|
|
|
it "should send the new compiler and project id to the project options handler", (done)->
|
|
|
|
compiler = "latex"
|
2014-06-25 08:51:02 -04:00
|
|
|
@EditorRealTimeController.emitToRoom = sinon.stub()
|
|
|
|
@EditorController.setCompiler @project_id, compiler, (err) =>
|
2014-02-12 05:23:40 -05:00
|
|
|
@ProjectOptionsHandler.setCompiler.calledWith(@project_id, compiler).should.equal true
|
2014-06-25 08:51:02 -04:00
|
|
|
@EditorRealTimeController.emitToRoom.calledWith(@project_id, "compilerUpdated", compiler).should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
done()
|
|
|
|
@ProjectOptionsHandler.setCompiler.args[0][2]()
|
|
|
|
|
|
|
|
|
|
|
|
describe "updating language code used for project", ->
|
|
|
|
it "should send the new languageCode and project id to the project options handler", (done)->
|
|
|
|
languageCode = "fr"
|
2014-06-25 08:51:02 -04:00
|
|
|
@EditorRealTimeController.emitToRoom = sinon.stub()
|
|
|
|
@EditorController.setSpellCheckLanguage @project_id, languageCode, (err) =>
|
2014-02-12 05:23:40 -05:00
|
|
|
@ProjectOptionsHandler.setSpellCheckLanguage.calledWith(@project_id, languageCode).should.equal true
|
2014-06-25 08:51:02 -04:00
|
|
|
@EditorRealTimeController.emitToRoom.calledWith(@project_id, "spellCheckLanguageUpdated", languageCode).should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
done()
|
|
|
|
@ProjectOptionsHandler.setSpellCheckLanguage.args[0][2]()
|
|
|
|
|
|
|
|
|
2014-10-15 09:11:02 -04:00
|
|
|
describe 'setDoc', ->
|
2014-02-12 05:23:40 -05:00
|
|
|
beforeEach ->
|
|
|
|
@docLines = ["foo", "bar"]
|
2014-05-08 10:47:50 -04:00
|
|
|
@DocumentUpdaterHandler.flushDocToMongo = sinon.stub().callsArg(2)
|
2016-02-04 09:26:50 -05:00
|
|
|
@DocumentUpdaterHandler.setDocument = sinon.stub().callsArg(5)
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
it 'should send the document to the documentUpdaterHandler', (done)->
|
2016-02-04 09:26:50 -05:00
|
|
|
@DocumentUpdaterHandler.setDocument = sinon.stub().withArgs(@project_id, @doc_id, @user_id, @docLines, @source).callsArg(5)
|
|
|
|
@EditorController.setDoc @project_id, @doc_id, @user_id, @docLines, @source, (err)->
|
2014-02-12 05:23:40 -05:00
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should send the new doc lines to the doucment updater', (done)->
|
|
|
|
@DocumentUpdaterHandler.setDocument = ->
|
2016-02-04 09:26:50 -05:00
|
|
|
mock = sinon.mock(@DocumentUpdaterHandler).expects("setDocument").withArgs(@project_id, @doc_id, @user_id, @docLines, @source).once().callsArg(5)
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2016-02-04 09:26:50 -05:00
|
|
|
@EditorController.setDoc @project_id, @doc_id, @user_id, @docLines, @source, (err)=>
|
2014-02-12 05:23:40 -05:00
|
|
|
mock.verify()
|
|
|
|
done()
|
|
|
|
|
2014-05-08 10:47:50 -04:00
|
|
|
it 'should flush the doc to mongo', (done)->
|
2016-02-04 09:26:50 -05:00
|
|
|
@EditorController.setDoc @project_id, @doc_id, @user_id, @docLines, @source, (err)=>
|
2014-05-08 10:47:50 -04:00
|
|
|
@DocumentUpdaterHandler.flushDocToMongo.calledWith(@project_id, @doc_id).should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
done()
|
|
|
|
|
|
|
|
|
2014-11-26 09:07:04 -05:00
|
|
|
describe 'addDocWithoutLock', ->
|
2014-02-12 05:23:40 -05:00
|
|
|
beforeEach ->
|
|
|
|
@ProjectEntityHandler.addDoc = ()->
|
|
|
|
@EditorRealTimeController.emitToRoom = sinon.stub()
|
|
|
|
@project_id = "12dsankj"
|
|
|
|
@folder_id = "213kjd"
|
|
|
|
@doc = {_id:"123ds"}
|
|
|
|
@folder_id = "123ksajdn"
|
|
|
|
@docName = "doc.tex"
|
|
|
|
@docLines = ["1234","dskl"]
|
|
|
|
|
|
|
|
it 'should add the doc using the project entity handler', (done)->
|
2017-11-23 10:18:43 -05:00
|
|
|
mock = sinon.mock(@ProjectEntityHandler).expects("addDoc").withArgs(@project_id, @folder_id, @docName, @docLines).callsArg(5)
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2017-11-23 10:34:24 -05:00
|
|
|
@EditorController.addDocWithoutLock @project_id, @folder_id, @docName, @docLines, @source, @user_id, ->
|
2014-02-12 05:23:40 -05:00
|
|
|
mock.verify()
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should send the update out to the users in the project', (done)->
|
2017-11-23 10:18:43 -05:00
|
|
|
@ProjectEntityHandler.addDoc = sinon.stub().callsArgWith(5, null, @doc, @folder_id)
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2017-11-23 10:34:24 -05:00
|
|
|
@EditorController.addDocWithoutLock @project_id, @folder_id, @docName, @docLines, @source, @user_id, =>
|
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
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should return the doc to the callback', (done) ->
|
2017-11-23 10:18:43 -05:00
|
|
|
@ProjectEntityHandler.addDoc = sinon.stub().callsArgWith(5, null, @doc, @folder_id)
|
2017-11-23 10:34:24 -05:00
|
|
|
@EditorController.addDocWithoutLock @project_id, @folder_id, @docName, @docLines, @source, @user_id, (error, doc) =>
|
2014-02-12 05:23:40 -05:00
|
|
|
doc.should.equal @doc
|
|
|
|
done()
|
|
|
|
|
2014-11-26 09:07:04 -05:00
|
|
|
describe "addDoc", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
@LockManager.getLock.callsArgWith(1)
|
|
|
|
@LockManager.releaseLock.callsArgWith(1)
|
2017-11-23 10:34:24 -05:00
|
|
|
@EditorController.addDocWithoutLock = sinon.stub().callsArgWith(6)
|
2014-11-26 09:07:04 -05:00
|
|
|
|
|
|
|
it "should call addDocWithoutLock", (done)->
|
2017-11-23 10:40:14 -05:00
|
|
|
@EditorController.addDoc @project_id, @folder_id, @docName, @docLines, @source, @user_id, =>
|
|
|
|
@EditorController.addDocWithoutLock.calledWith(@project_id, @folder_id, @docName, @docLines, @source, @user_id).should.equal true
|
2014-11-26 09:07:04 -05:00
|
|
|
done()
|
|
|
|
|
|
|
|
it "should take the lock", (done)->
|
2017-11-23 10:40:14 -05:00
|
|
|
@EditorController.addDoc @project_id, @folder_id, @docName, @docLines, @source, @user_id, =>
|
2014-11-26 09:07:04 -05:00
|
|
|
@LockManager.getLock.calledWith(@project_id).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should release the lock", (done)->
|
2017-11-23 10:40:14 -05:00
|
|
|
@EditorController.addDoc @project_id, @folder_id, @docName, @docLines, @source, @user_id, =>
|
2014-11-26 09:07:04 -05:00
|
|
|
@LockManager.releaseLock.calledWith(@project_id).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should error if it can't cat the lock", (done)->
|
|
|
|
@LockManager.getLock = sinon.stub().callsArgWith(1, "timed out")
|
2017-11-23 10:40:14 -05:00
|
|
|
@EditorController.addDoc @project_id, @folder_id, @docName, @docLines, @source, @user_id, (err)=>
|
2014-11-26 09:07:04 -05:00
|
|
|
expect(err).to.exist
|
|
|
|
err.should.equal "timed out"
|
2017-11-23 10:40:14 -05:00
|
|
|
done()
|
2014-11-26 09:07:04 -05:00
|
|
|
|
|
|
|
describe 'addFileWithoutLock:', ->
|
2014-02-12 05:23:40 -05:00
|
|
|
beforeEach ->
|
|
|
|
@ProjectEntityHandler.addFile = ->
|
|
|
|
@EditorRealTimeController.emitToRoom = sinon.stub()
|
|
|
|
@project_id = "12dsankj"
|
|
|
|
@folder_id = "213kjd"
|
|
|
|
@fileName = "file.png"
|
|
|
|
@folder_id = "123ksajdn"
|
|
|
|
@file = {_id:"dasdkjk"}
|
|
|
|
@stream = new ArrayBuffer()
|
|
|
|
|
|
|
|
it 'should add the folder using the project entity handler', (done)->
|
2017-11-13 06:16:54 -05:00
|
|
|
@ProjectEntityHandler.addFile = sinon.stub().callsArgWith(5)
|
2017-11-13 07:20:14 -05:00
|
|
|
@EditorController.addFileWithoutLock @project_id, @folder_id, @fileName, @stream, @source, @user_id, =>
|
|
|
|
@ProjectEntityHandler.addFile.calledWith(@project_id, @folder_id, @fileName, @stream, @user_id).should.equal true
|
2014-02-12 05:23:40 -05:00
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should send the update of a new folder out to the users in the project', (done)->
|
2017-11-13 06:16:54 -05:00
|
|
|
@ProjectEntityHandler.addFile = sinon.stub().callsArgWith(5, null, @file, @folder_id)
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2017-11-13 07:20:14 -05:00
|
|
|
@EditorController.addFileWithoutLock @project_id, @folder_id, @fileName, @stream, @source, @user_id, =>
|
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
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should return the file in the callback", (done) ->
|
2017-11-13 06:16:54 -05:00
|
|
|
@ProjectEntityHandler.addFile = sinon.stub().callsArgWith(5, null, @file, @folder_id)
|
2017-11-13 07:20:14 -05:00
|
|
|
@EditorController.addFileWithoutLock @project_id, @folder_id, @fileName, @stream, @source, @user_id, (error, file) =>
|
2014-02-12 05:23:40 -05:00
|
|
|
file.should.equal @file
|
|
|
|
done()
|
|
|
|
|
|
|
|
|
2014-11-26 09:07:04 -05:00
|
|
|
describe "addFile", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
@LockManager.getLock.callsArgWith(1)
|
|
|
|
@LockManager.releaseLock.callsArgWith(1)
|
2017-11-13 07:20:14 -05:00
|
|
|
@EditorController.addFileWithoutLock = sinon.stub().callsArgWith(6)
|
2014-11-26 09:07:04 -05:00
|
|
|
|
|
|
|
it "should call addFileWithoutLock", (done)->
|
2017-11-13 07:20:14 -05:00
|
|
|
@EditorController.addFile @project_id, @folder_id, @fileName, @stream, @source, @user_id, (error, file) =>
|
|
|
|
@EditorController.addFileWithoutLock.calledWith(@project_id, @folder_id, @fileName, @stream, @source, @user_id).should.equal true
|
2014-11-26 09:07:04 -05:00
|
|
|
done()
|
|
|
|
|
|
|
|
it "should take the lock", (done)->
|
2017-11-13 07:20:14 -05:00
|
|
|
@EditorController.addFile @project_id, @folder_id, @fileName, @stream, @source, @user_id, (error, file) =>
|
2014-11-26 09:07:04 -05:00
|
|
|
@LockManager.getLock.calledWith(@project_id).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should release the lock", (done)->
|
2017-11-13 07:20:14 -05:00
|
|
|
@EditorController.addFile @project_id, @folder_id, @fileName, @stream, @source, @user_id, (error, file) =>
|
2014-11-26 09:07:04 -05:00
|
|
|
@LockManager.releaseLock.calledWith(@project_id).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should error if it can't cat the lock", (done)->
|
|
|
|
@LockManager.getLock = sinon.stub().callsArgWith(1, "timed out")
|
2017-11-13 07:20:14 -05:00
|
|
|
@EditorController.addFile @project_id, @folder_id, @fileName, @stream, @source, @user_id, (error, file) =>
|
|
|
|
expect(error).to.exist
|
|
|
|
error.should.equal "timed out"
|
2014-11-26 09:07:04 -05:00
|
|
|
done()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
describe "replaceFile", ->
|
|
|
|
beforeEach ->
|
|
|
|
@project_id = "12dsankj"
|
|
|
|
@file_id = "file_id_here"
|
|
|
|
@fsPath = "/folder/file.png"
|
|
|
|
|
|
|
|
it 'should send the replace file message to the editor controller', (done)->
|
2017-11-24 06:26:43 -05:00
|
|
|
@ProjectEntityHandler.replaceFile = sinon.stub().callsArgWith(4)
|
2014-10-15 10:18:31 -04:00
|
|
|
@EditorController.replaceFile @project_id, @file_id, @fsPath, @source, =>
|
2014-02-12 05:23:40 -05:00
|
|
|
@ProjectEntityHandler.replaceFile.calledWith(@project_id, @file_id, @fsPath).should.equal true
|
|
|
|
done()
|
|
|
|
|
2014-11-26 09:07:04 -05:00
|
|
|
describe 'addFolderWithoutLock :', ->
|
2014-02-12 05:23:40 -05:00
|
|
|
beforeEach ->
|
|
|
|
@ProjectEntityHandler.addFolder = ->
|
|
|
|
@EditorRealTimeController.emitToRoom = sinon.stub()
|
|
|
|
@project_id = "12dsankj"
|
|
|
|
@folder_id = "213kjd"
|
|
|
|
@folderName = "folder"
|
|
|
|
@folder = {_id:"123ds"}
|
|
|
|
|
|
|
|
it 'should add the folder using the project entity handler', (done)->
|
|
|
|
mock = sinon.mock(@ProjectEntityHandler).expects("addFolder").withArgs(@project_id, @folder_id, @folderName).callsArg(3)
|
|
|
|
|
2014-11-26 09:07:04 -05:00
|
|
|
@EditorController.addFolderWithoutLock @project_id, @folder_id, @folderName, @source, ->
|
2014-02-12 05:23:40 -05:00
|
|
|
mock.verify()
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should notifyProjectUsersOfNewFolder', (done)->
|
|
|
|
@ProjectEntityHandler.addFolder = (project_id, folder_id, folderName, callback)=> callback(null, @folder, @folder_id)
|
|
|
|
mock = sinon.mock(@EditorController.p).expects('notifyProjectUsersOfNewFolder').withArgs(@project_id, @folder_id, @folder).callsArg(3)
|
|
|
|
|
2014-11-26 09:07:04 -05:00
|
|
|
@EditorController.addFolderWithoutLock @project_id, @folder_id, @folderName, @source, ->
|
2014-02-12 05:23:40 -05:00
|
|
|
mock.verify()
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'notifyProjectUsersOfNewFolder should send update out to all users', (done)->
|
|
|
|
@EditorController.p.notifyProjectUsersOfNewFolder @project_id, @folder_id, @folder, =>
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, "reciveNewFolder", @folder_id, @folder)
|
|
|
|
.should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should return the folder in the callback', (done) ->
|
|
|
|
@ProjectEntityHandler.addFolder = (project_id, folder_id, folderName, callback)=> callback(null, @folder, @folder_id)
|
2014-11-26 09:07:04 -05:00
|
|
|
@EditorController.addFolderWithoutLock @project_id, @folder_id, @folderName, @source, (error, folder) =>
|
2014-02-12 05:23:40 -05:00
|
|
|
folder.should.equal @folder
|
|
|
|
done()
|
|
|
|
|
2014-11-26 09:07:04 -05:00
|
|
|
|
|
|
|
describe "addFolder", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
@LockManager.getLock.callsArgWith(1)
|
|
|
|
@LockManager.releaseLock.callsArgWith(1)
|
|
|
|
@EditorController.addFolderWithoutLock = sinon.stub().callsArgWith(4)
|
|
|
|
|
|
|
|
it "should call addFolderWithoutLock", (done)->
|
|
|
|
@EditorController.addFolder @project_id, @folder_id, @folderName, @source, (error, file) =>
|
|
|
|
@EditorController.addFolderWithoutLock.calledWith(@project_id, @folder_id, @folderName, @source).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should take the lock", (done)->
|
|
|
|
@EditorController.addFolder @project_id, @folder_id, @folderName, @source, (error, file) =>
|
|
|
|
@LockManager.getLock.calledWith(@project_id).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should release the lock", (done)->
|
|
|
|
@EditorController.addFolder @project_id, @folder_id, @folderName, @source, (error, file) =>
|
|
|
|
@LockManager.releaseLock.calledWith(@project_id).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should error if it can't cat the lock", (done)->
|
|
|
|
@LockManager.getLock = sinon.stub().callsArgWith(1, "timed out")
|
|
|
|
@EditorController.addFolder @project_id, @folder_id, @folderName, @source, (err, file) =>
|
|
|
|
expect(err).to.exist
|
|
|
|
err.should.equal "timed out"
|
|
|
|
done()
|
|
|
|
|
|
|
|
|
|
|
|
describe 'mkdirpWithoutLock :', ->
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
it 'should make the dirs and notifyProjectUsersOfNewFolder', (done)->
|
|
|
|
path = "folder1/folder2"
|
|
|
|
@folder1 = {_id:"folder_1_id_here"}
|
|
|
|
@folder2 = {_id:"folder_2_id_here", parentFolder_id:@folder1._id}
|
|
|
|
@folder3 = {_id:"folder_3_id_here", parentFolder_id:@folder2._id}
|
|
|
|
|
|
|
|
@ProjectEntityHandler.mkdirp = sinon.stub().withArgs(@project_id, path).callsArgWith(2, null, [@folder1, @folder2, @folder3], @folder3)
|
|
|
|
|
|
|
|
@EditorController.p.notifyProjectUsersOfNewFolder = sinon.stub().callsArg(3)
|
|
|
|
|
2014-11-26 09:07:04 -05:00
|
|
|
@EditorController.mkdirpWithoutLock @project_id, path, (err, newFolders, lastFolder)=>
|
2014-02-12 05:23:40 -05:00
|
|
|
@EditorController.p.notifyProjectUsersOfNewFolder.calledWith(@project_id, @folder1._id, @folder2).should.equal true
|
|
|
|
@EditorController.p.notifyProjectUsersOfNewFolder.calledWith(@project_id, @folder2._id, @folder3).should.equal true
|
|
|
|
newFolders.should.deep.equal [@folder1, @folder2, @folder3]
|
|
|
|
lastFolder.should.equal @folder3
|
|
|
|
done()
|
|
|
|
|
2014-11-26 09:07:04 -05:00
|
|
|
|
|
|
|
describe "mkdirp", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
@path = "folder1/folder2"
|
|
|
|
@LockManager.getLock.callsArgWith(1)
|
|
|
|
@LockManager.releaseLock.callsArgWith(1)
|
|
|
|
@EditorController.mkdirpWithoutLock = sinon.stub().callsArgWith(2)
|
|
|
|
|
|
|
|
it "should call mkdirpWithoutLock", (done)->
|
|
|
|
@EditorController.mkdirp @project_id, @path, (error, file) =>
|
|
|
|
@EditorController.mkdirpWithoutLock.calledWith(@project_id, @path).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should take the lock", (done)->
|
|
|
|
@EditorController.mkdirp @project_id, @path, (error, file) =>
|
|
|
|
@LockManager.getLock.calledWith(@project_id).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should release the lock", (done)->
|
|
|
|
@EditorController.mkdirp @project_id, @path, (error, file) =>
|
|
|
|
@LockManager.releaseLock.calledWith(@project_id).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should error if it can't cat the lock", (done)->
|
|
|
|
@LockManager.getLock = sinon.stub().callsArgWith(1, "timed out")
|
|
|
|
@EditorController.mkdirp @project_id, @path, (err, file) =>
|
|
|
|
expect(err).to.exist
|
|
|
|
err.should.equal "timed out"
|
|
|
|
done()
|
|
|
|
|
|
|
|
|
|
|
|
describe "deleteEntity", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
@LockManager.getLock.callsArgWith(1)
|
|
|
|
@LockManager.releaseLock.callsArgWith(1)
|
|
|
|
@EditorController.deleteEntityWithoutLock = sinon.stub().callsArgWith(4)
|
|
|
|
|
|
|
|
it "should call deleteEntityWithoutLock", (done)->
|
|
|
|
@EditorController.deleteEntity @project_id, @entity_id, @type, @source, =>
|
|
|
|
@EditorController.deleteEntityWithoutLock.calledWith(@project_id, @entity_id, @type, @source).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should take the lock", (done)->
|
|
|
|
@EditorController.deleteEntity @project_id, @entity_id, @type, @source, =>
|
|
|
|
@LockManager.getLock.calledWith(@project_id).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should release the lock", (done)->
|
|
|
|
@EditorController.deleteEntity @project_id, @entity_id, @type, @source, (error)=>
|
|
|
|
@LockManager.releaseLock.calledWith(@project_id).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should error if it can't cat the lock", (done)->
|
|
|
|
@LockManager.getLock = sinon.stub().callsArgWith(1, "timed out")
|
|
|
|
@EditorController.deleteEntity @project_id, @entity_id, @type, @source, (err)=>
|
|
|
|
expect(err).to.exist
|
|
|
|
err.should.equal "timed out"
|
|
|
|
done()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe 'deleteEntityWithoutLock', ->
|
2014-02-12 05:23:40 -05:00
|
|
|
beforeEach ->
|
|
|
|
@ProjectEntityHandler.deleteEntity = (project_id, entity_id, type, callback)-> callback()
|
|
|
|
@entity_id = "entity_id_here"
|
|
|
|
@type = "doc"
|
|
|
|
@EditorRealTimeController.emitToRoom = sinon.stub()
|
|
|
|
|
|
|
|
it 'should delete the folder using the project entity handler', (done)->
|
|
|
|
mock = sinon.mock(@ProjectEntityHandler).expects("deleteEntity").withArgs(@project_id, @entity_id, @type).callsArg(3)
|
|
|
|
|
2014-11-26 09:07:04 -05:00
|
|
|
@EditorController.deleteEntityWithoutLock @project_id, @entity_id, @type, @source, ->
|
2014-02-12 05:23:40 -05:00
|
|
|
mock.verify()
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'notify users an entity has been deleted', (done)->
|
2014-11-26 09:07:04 -05:00
|
|
|
@EditorController.deleteEntityWithoutLock @project_id, @entity_id, @type, @source, =>
|
2014-02-12 05:23:40 -05:00
|
|
|
@EditorRealTimeController.emitToRoom
|
2014-10-15 10:18:31 -04:00
|
|
|
.calledWith(@project_id, "removeEntity", @entity_id, @source)
|
2014-02-12 05:23:40 -05:00
|
|
|
.should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "getting a list of project paths", ->
|
|
|
|
|
|
|
|
it 'should call the project entity handler to get an array of docs', (done)->
|
|
|
|
fullDocsHash =
|
|
|
|
"/doc1.tex":{lines:["das"], _id:"1234"}
|
|
|
|
"/doc2.tex":{lines:["dshajkh"]}
|
|
|
|
project_id = "d312nkjnajn"
|
|
|
|
@ProjectEntityHandler.getAllDocs = sinon.stub().callsArgWith(1, null, fullDocsHash)
|
|
|
|
@EditorController.getListOfDocPaths project_id, (err, returnedDocs)->
|
|
|
|
returnedDocs.length.should.equal 2
|
|
|
|
returnedDocs[0]._id.should.equal "1234"
|
|
|
|
assert.equal returnedDocs[0].lines, undefined
|
|
|
|
returnedDocs[1].path.should.equal "doc2.tex"
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "notifyUsersProjectHasBeenDeletedOrRenamed", ->
|
|
|
|
it 'should emmit a message to all users in a project', (done)->
|
|
|
|
@EditorRealTimeController.emitToRoom = sinon.stub()
|
|
|
|
@EditorController.notifyUsersProjectHasBeenDeletedOrRenamed @project_id, (err)=>
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, "projectRenamedOrDeletedByExternalSource")
|
|
|
|
.should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "updateProjectDescription", ->
|
|
|
|
beforeEach ->
|
|
|
|
@description = "new description"
|
|
|
|
@EditorRealTimeController.emitToRoom = sinon.stub()
|
|
|
|
|
|
|
|
|
|
|
|
it "should send the new description to the project details handler", (done)->
|
|
|
|
@ProjectDetailsHandler.setProjectDescription.callsArgWith(2)
|
|
|
|
@EditorController.updateProjectDescription @project_id, @description, =>
|
|
|
|
@ProjectDetailsHandler.setProjectDescription.calledWith(@project_id, @description).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should notify the other clients about the updated description", (done)->
|
|
|
|
@ProjectDetailsHandler.setProjectDescription.callsArgWith(2)
|
|
|
|
@EditorController.updateProjectDescription @project_id, @description, =>
|
|
|
|
@EditorRealTimeController.emitToRoom.calledWith(@project_id, "projectDescriptionUpdated", @description).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
|
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", ->
|
|
|
|
beforeEach ->
|
|
|
|
@entity_id = "entity_id_here"
|
|
|
|
@entityType = "doc"
|
|
|
|
@newName = "bobsfile.tex"
|
2017-11-01 14:21:05 -04:00
|
|
|
@ProjectEntityHandler.renameEntity = sinon.stub().callsArg(5)
|
2014-04-04 11:35:02 -04:00
|
|
|
@EditorRealTimeController.emitToRoom = sinon.stub()
|
|
|
|
|
|
|
|
it "should call the project handler", (done)->
|
2017-11-01 14:21:05 -04:00
|
|
|
@EditorController.renameEntity @project_id, @entity_id, @entityType, @newName, @user_id, =>
|
|
|
|
@ProjectEntityHandler.renameEntity.calledWith(@project_id, @entity_id, @entityType, @newName, @user_id).should.equal true
|
2014-04-04 11:35:02 -04:00
|
|
|
done()
|
|
|
|
|
|
|
|
|
|
|
|
it "should emit the update to the room", (done)->
|
2017-11-01 14:21:05 -04:00
|
|
|
@EditorController.renameEntity @project_id, @entity_id, @entityType, @newName, @user_id, =>
|
2014-04-04 11:35:02 -04:00
|
|
|
@EditorRealTimeController.emitToRoom.calledWith(@project_id, 'reciveEntityRename', @entity_id, @newName).should.equal true
|
|
|
|
done()
|
|
|
|
|
2014-04-04 11:40:53 -04:00
|
|
|
describe "moveEntity", ->
|
|
|
|
beforeEach ->
|
|
|
|
@entity_id = "entity_id_here"
|
|
|
|
@entityType = "doc"
|
|
|
|
@folder_id = "313dasd21dasdsa"
|
2017-11-02 05:44:23 -04:00
|
|
|
@ProjectEntityHandler.moveEntity = sinon.stub().callsArg(5)
|
2014-04-04 11:40:53 -04:00
|
|
|
@EditorRealTimeController.emitToRoom = sinon.stub()
|
2016-03-15 08:29:41 -04:00
|
|
|
@LockManager.releaseLock.callsArgWith(1)
|
|
|
|
@LockManager.getLock.callsArgWith(1)
|
2014-04-04 11:40:53 -04:00
|
|
|
|
|
|
|
it "should call the ProjectEntityHandler", (done)->
|
2017-11-02 05:44:23 -04:00
|
|
|
@EditorController.moveEntity @project_id, @entity_id, @folder_id, @entityType, @user_id, =>
|
|
|
|
@ProjectEntityHandler.moveEntity.calledWith(@project_id, @entity_id, @folder_id, @entityType, @user_id).should.equal true
|
2014-04-04 11:40:53 -04:00
|
|
|
done()
|
|
|
|
|
2016-03-15 08:29:41 -04:00
|
|
|
it "should take the lock", (done)->
|
2017-11-02 05:44:23 -04:00
|
|
|
@EditorController.moveEntity @project_id, @entity_id, @folder_id, @entityType, @user_id, =>
|
2016-03-15 08:29:41 -04:00
|
|
|
@LockManager.getLock.calledWith(@project_id).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should release the lock", (done)->
|
2017-11-02 05:44:23 -04:00
|
|
|
@EditorController.moveEntity @project_id, @entity_id, @folder_id, @entityType, @user_id, =>
|
2016-03-15 08:29:41 -04:00
|
|
|
@LockManager.releaseLock.calledWith(@project_id).should.equal true
|
|
|
|
done()
|
2014-04-04 11:40:53 -04:00
|
|
|
|
|
|
|
it "should emit the update to the room", (done)->
|
2017-11-02 05:44:23 -04:00
|
|
|
@EditorController.moveEntity @project_id, @entity_id, @folder_id, @entityType, @user_id, =>
|
2014-04-04 11:40:53 -04:00
|
|
|
@EditorRealTimeController.emitToRoom.calledWith(@project_id, 'reciveEntityMove', @entity_id, @folder_id).should.equal true
|
|
|
|
done()
|
2014-04-04 11:49:44 -04:00
|
|
|
|
|
|
|
describe "renameProject", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
@err = "errro"
|
|
|
|
@window_id = "kdsjklj290jlk"
|
|
|
|
@newName = "new name here"
|
2017-05-22 10:24:52 -04:00
|
|
|
@ProjectDetailsHandler.renameProject = sinon.stub().callsArg(2)
|
2014-04-04 11:49:44 -04:00
|
|
|
@EditorRealTimeController.emitToRoom = sinon.stub()
|
|
|
|
|
2014-04-07 15:46:58 -04:00
|
|
|
it "should call the EditorController", (done)->
|
2014-04-07 10:37:40 -04:00
|
|
|
@EditorController.renameProject @project_id, @newName, =>
|
|
|
|
@ProjectDetailsHandler.renameProject.calledWith(@project_id, @newName).should.equal true
|
2014-04-04 11:49:44 -04:00
|
|
|
done()
|
|
|
|
|
|
|
|
|
|
|
|
it "should emit the update to the room", (done)->
|
2014-04-07 10:37:40 -04:00
|
|
|
@EditorController.renameProject @project_id, @newName, =>
|
|
|
|
@EditorRealTimeController.emitToRoom.calledWith(@project_id, 'projectNameUpdated', @newName).should.equal true
|
2014-04-04 11:49:44 -04:00
|
|
|
done()
|
2014-04-04 11:53:59 -04:00
|
|
|
|
|
|
|
|
|
|
|
describe "setPublicAccessLevel", ->
|
|
|
|
|
2017-10-04 11:31:24 -04:00
|
|
|
describe 'when setting to private', ->
|
|
|
|
beforeEach ->
|
|
|
|
@newAccessLevel = 'private'
|
|
|
|
@ProjectDetailsHandler.setPublicAccessLevel = sinon.stub().callsArgWith(2, null)
|
|
|
|
@ProjectDetailsHandler.ensureTokensArePresent = sinon.stub()
|
|
|
|
.callsArgWith(1, null, @tokens)
|
|
|
|
@EditorRealTimeController.emitToRoom = sinon.stub()
|
|
|
|
|
|
|
|
it 'should set the access level', (done) ->
|
|
|
|
@EditorController.setPublicAccessLevel @project_id, @newAccessLevel, =>
|
|
|
|
@ProjectDetailsHandler.setPublicAccessLevel
|
|
|
|
.calledWith(@project_id, @newAccessLevel).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should broadcast the access level change', (done) ->
|
|
|
|
@EditorController.setPublicAccessLevel @project_id, @newAccessLevel, =>
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, 'project:publicAccessLevel:changed').should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should not ensure tokens are present for project', (done) ->
|
|
|
|
@EditorController.setPublicAccessLevel @project_id, @newAccessLevel, =>
|
|
|
|
@ProjectDetailsHandler.ensureTokensArePresent
|
|
|
|
.calledWith(@project_id).should.equal false
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should not broadcast a token change', (done) ->
|
|
|
|
@EditorController.setPublicAccessLevel @project_id, @newAccessLevel, =>
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, 'project:tokens:changed', {tokens: @tokens})
|
|
|
|
.should.equal false
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should not produce an error', (done) ->
|
|
|
|
@EditorController.setPublicAccessLevel @project_id, @newAccessLevel, (err) =>
|
|
|
|
expect(err).to.not.exist
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe 'when setting to tokenBased', ->
|
|
|
|
beforeEach ->
|
|
|
|
@newAccessLevel = 'tokenBased'
|
|
|
|
@tokens = {readOnly: 'aaa', readAndWrite: '42bbb'}
|
|
|
|
@ProjectDetailsHandler.setPublicAccessLevel = sinon.stub()
|
|
|
|
.callsArgWith(2, null)
|
|
|
|
@ProjectDetailsHandler.ensureTokensArePresent = sinon.stub()
|
|
|
|
.callsArgWith(1, null, @tokens)
|
|
|
|
@EditorRealTimeController.emitToRoom = sinon.stub()
|
|
|
|
|
|
|
|
it 'should set the access level', (done) ->
|
|
|
|
@EditorController.setPublicAccessLevel @project_id, @newAccessLevel, =>
|
|
|
|
@ProjectDetailsHandler.setPublicAccessLevel
|
|
|
|
.calledWith(@project_id, @newAccessLevel).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should broadcast the access level change', (done) ->
|
|
|
|
@EditorController.setPublicAccessLevel @project_id, @newAccessLevel, =>
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, 'project:publicAccessLevel:changed')
|
|
|
|
.should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should ensure tokens are present for project', (done) ->
|
|
|
|
@EditorController.setPublicAccessLevel @project_id, @newAccessLevel, =>
|
|
|
|
@ProjectDetailsHandler.ensureTokensArePresent
|
|
|
|
.calledWith(@project_id).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should broadcast the token change too', (done) ->
|
|
|
|
@EditorController.setPublicAccessLevel @project_id, @newAccessLevel, =>
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith(@project_id, 'project:tokens:changed', {tokens: @tokens})
|
|
|
|
.should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'should not produce an error', (done) ->
|
|
|
|
@EditorController.setPublicAccessLevel @project_id, @newAccessLevel, (err) =>
|
|
|
|
expect(err).to.not.exist
|
|
|
|
done()
|
|
|
|
|
|
|
|
# beforeEach ->
|
|
|
|
# @newAccessLevel = "public"
|
|
|
|
# @ProjectDetailsHandler.setPublicAccessLevel = sinon.stub().callsArgWith(2, null)
|
|
|
|
# @EditorRealTimeController.emitToRoom = sinon.stub()
|
|
|
|
|
|
|
|
# it "should call the EditorController", (done)->
|
|
|
|
# @EditorController.setPublicAccessLevel @project_id, @newAccessLevel, =>
|
|
|
|
# @ProjectDetailsHandler.setPublicAccessLevel.calledWith(@project_id, @newAccessLevel).should.equal true
|
|
|
|
# done()
|
|
|
|
|
|
|
|
# it "should emit the update to the room", (done)->
|
|
|
|
# @EditorController.setPublicAccessLevel @project_id, @newAccessLevel, =>
|
|
|
|
# @EditorRealTimeController.emitToRoom.calledWith(@project_id, 'publicAccessLevelUpdated', @newAccessLevel).should.equal true
|
|
|
|
# done()
|
2014-04-04 11:53:59 -04:00
|
|
|
|
2014-04-04 11:59:45 -04:00
|
|
|
describe "setRootDoc", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
@newRootDocID = "21312321321"
|
2014-06-25 08:51:02 -04:00
|
|
|
@ProjectEntityHandler.setRootDoc = sinon.stub().callsArgWith(2, null)
|
2014-04-04 11:59:45 -04:00
|
|
|
@EditorRealTimeController.emitToRoom = sinon.stub()
|
|
|
|
|
|
|
|
it "should call the ProjectEntityHandler", (done)->
|
|
|
|
@EditorController.setRootDoc @project_id, @newRootDocID, =>
|
|
|
|
@ProjectEntityHandler.setRootDoc.calledWith(@project_id, @newRootDocID).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
it "should emit the update to the room", (done)->
|
|
|
|
@EditorController.setRootDoc @project_id, @newRootDocID, =>
|
|
|
|
@EditorRealTimeController.emitToRoom.calledWith(@project_id, 'rootDocUpdated', @newRootDocID).should.equal true
|
2017-10-04 11:31:24 -04:00
|
|
|
done()
|