EditorControllerTests.coffee 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. SandboxedModule = require('sandboxed-module')
  2. sinon = require('sinon')
  3. require('chai').should()
  4. expect = require("chai").expect
  5. modulePath = require('path').join __dirname, '../../../../app/js/Features/Editor/EditorController'
  6. MockClient = require "../helpers/MockClient"
  7. assert = require('assert')
  8. describe "EditorController", ->
  9. beforeEach ->
  10. @project_id = "test-project-id"
  11. @project =
  12. _id: @project_id
  13. owner_ref:{_id:"something"}
  14. @doc_id = "test-doc-id"
  15. @source = "dropbox"
  16. @user =
  17. _id: @user_id = "user-id"
  18. projects: {}
  19. @rooms = {}
  20. @io =
  21. sockets :
  22. clients : (room_id) =>
  23. @rooms[room_id]
  24. @DocumentUpdaterHandler = {}
  25. @ProjectOptionsHandler =
  26. setCompiler : sinon.spy()
  27. setSpellCheckLanguage: sinon.spy()
  28. @ProjectEntityHandler =
  29. flushProjectToThirdPartyDataStore:sinon.stub()
  30. @Project =
  31. findPopulatedById: sinon.stub().callsArgWith(1, null, @project)
  32. @client = new MockClient()
  33. @settings =
  34. apis:{thirdPartyDataStore:{emptyProjectFlushDelayMiliseconds:0.5}}
  35. redis: web:{}
  36. @dropboxProjectLinker = {}
  37. @callback = sinon.stub()
  38. @ProjectDetailsHandler =
  39. setProjectDescription:sinon.stub()
  40. @CollaboratorsHandler =
  41. removeUserFromProject: sinon.stub().callsArgWith(2)
  42. addUserToProject: sinon.stub().callsArgWith(3)
  43. @ProjectDeleter =
  44. deleteProject: sinon.stub()
  45. @LockManager =
  46. getLock : sinon.stub()
  47. releaseLock : sinon.stub()
  48. @EditorController = SandboxedModule.require modulePath, requires:
  49. "../../infrastructure/Server" : io : @io
  50. '../Project/ProjectEntityHandler' : @ProjectEntityHandler
  51. '../Project/ProjectOptionsHandler' : @ProjectOptionsHandler
  52. '../Project/ProjectDetailsHandler': @ProjectDetailsHandler
  53. '../Project/ProjectDeleter' : @ProjectDeleter
  54. '../Collaborators/CollaboratorsHandler': @CollaboratorsHandler
  55. '../DocumentUpdater/DocumentUpdaterHandler' : @DocumentUpdaterHandler
  56. '../../models/Project' : Project: @Project
  57. "settings-sharelatex":@settings
  58. '../Dropbox/DropboxProjectLinker':@dropboxProjectLinker
  59. './EditorRealTimeController':@EditorRealTimeController = {}
  60. "../../infrastructure/Metrics": @Metrics = { inc: sinon.stub() }
  61. "../TrackChanges/TrackChangesManager": @TrackChangesManager = {}
  62. "../../infrastructure/LockManager":@LockManager
  63. 'redis-sharelatex':createClient:-> auth:->
  64. "logger-sharelatex": @logger =
  65. log: sinon.stub()
  66. err: sinon.stub()
  67. describe "updating compiler used for project", ->
  68. it "should send the new compiler and project id to the project options handler", (done)->
  69. compiler = "latex"
  70. @EditorRealTimeController.emitToRoom = sinon.stub()
  71. @EditorController.setCompiler @project_id, compiler, (err) =>
  72. @ProjectOptionsHandler.setCompiler.calledWith(@project_id, compiler).should.equal true
  73. @EditorRealTimeController.emitToRoom.calledWith(@project_id, "compilerUpdated", compiler).should.equal true
  74. done()
  75. @ProjectOptionsHandler.setCompiler.args[0][2]()
  76. describe "updating language code used for project", ->
  77. it "should send the new languageCode and project id to the project options handler", (done)->
  78. languageCode = "fr"
  79. @EditorRealTimeController.emitToRoom = sinon.stub()
  80. @EditorController.setSpellCheckLanguage @project_id, languageCode, (err) =>
  81. @ProjectOptionsHandler.setSpellCheckLanguage.calledWith(@project_id, languageCode).should.equal true
  82. @EditorRealTimeController.emitToRoom.calledWith(@project_id, "spellCheckLanguageUpdated", languageCode).should.equal true
  83. done()
  84. @ProjectOptionsHandler.setSpellCheckLanguage.args[0][2]()
  85. describe 'setDoc', ->
  86. beforeEach ->
  87. @docLines = ["foo", "bar"]
  88. @DocumentUpdaterHandler.flushDocToMongo = sinon.stub().callsArg(2)
  89. @DocumentUpdaterHandler.setDocument = sinon.stub().callsArg(5)
  90. it 'should send the document to the documentUpdaterHandler', (done)->
  91. @DocumentUpdaterHandler.setDocument = sinon.stub().withArgs(@project_id, @doc_id, @user_id, @docLines, @source).callsArg(5)
  92. @EditorController.setDoc @project_id, @doc_id, @user_id, @docLines, @source, (err)->
  93. done()
  94. it 'should send the new doc lines to the doucment updater', (done)->
  95. @DocumentUpdaterHandler.setDocument = ->
  96. mock = sinon.mock(@DocumentUpdaterHandler).expects("setDocument").withArgs(@project_id, @doc_id, @user_id, @docLines, @source).once().callsArg(5)
  97. @EditorController.setDoc @project_id, @doc_id, @user_id, @docLines, @source, (err)=>
  98. mock.verify()
  99. done()
  100. it 'should flush the doc to mongo', (done)->
  101. @EditorController.setDoc @project_id, @doc_id, @user_id, @docLines, @source, (err)=>
  102. @DocumentUpdaterHandler.flushDocToMongo.calledWith(@project_id, @doc_id).should.equal true
  103. done()
  104. describe 'addDocWithoutLock', ->
  105. beforeEach ->
  106. @ProjectEntityHandler.addDoc = ()->
  107. @EditorRealTimeController.emitToRoom = sinon.stub()
  108. @project_id = "12dsankj"
  109. @folder_id = "213kjd"
  110. @doc = {_id:"123ds"}
  111. @folder_id = "123ksajdn"
  112. @docName = "doc.tex"
  113. @docLines = ["1234","dskl"]
  114. it 'should add the doc using the project entity handler', (done)->
  115. mock = sinon.mock(@ProjectEntityHandler).expects("addDoc").withArgs(@project_id, @folder_id, @docName, @docLines).callsArg(4)
  116. @EditorController.addDocWithoutLock @project_id, @folder_id, @docName, @docLines, @source, ->
  117. mock.verify()
  118. done()
  119. it 'should send the update out to the users in the project', (done)->
  120. @ProjectEntityHandler.addDoc = sinon.stub().callsArgWith(4, null, @doc, @folder_id)
  121. @EditorController.addDocWithoutLock @project_id, @folder_id, @docName, @docLines, @source, =>
  122. @EditorRealTimeController.emitToRoom
  123. .calledWith(@project_id, "reciveNewDoc", @folder_id, @doc, @source)
  124. .should.equal true
  125. done()
  126. it 'should return the doc to the callback', (done) ->
  127. @ProjectEntityHandler.addDoc = sinon.stub().callsArgWith(4, null, @doc, @folder_id)
  128. @EditorController.addDocWithoutLock @project_id, @folder_id, @docName, @docLines, @source, (error, doc) =>
  129. doc.should.equal @doc
  130. done()
  131. describe "addDoc", ->
  132. beforeEach ->
  133. @LockManager.getLock.callsArgWith(1)
  134. @LockManager.releaseLock.callsArgWith(1)
  135. @EditorController.addDocWithoutLock = sinon.stub().callsArgWith(5)
  136. it "should call addDocWithoutLock", (done)->
  137. @EditorController.addDoc @project_id, @folder_id, @docName, @docLines, @source, =>
  138. @EditorController.addDocWithoutLock.calledWith(@project_id, @folder_id, @docName, @docLines, @source).should.equal true
  139. done()
  140. it "should take the lock", (done)->
  141. @EditorController.addDoc @project_id, @folder_id, @docName, @docLines, @source, =>
  142. @LockManager.getLock.calledWith(@project_id).should.equal true
  143. done()
  144. it "should release the lock", (done)->
  145. @EditorController.addDoc @project_id, @folder_id, @docName, @docLines, @source, =>
  146. @LockManager.releaseLock.calledWith(@project_id).should.equal true
  147. done()
  148. it "should error if it can't cat the lock", (done)->
  149. @LockManager.getLock = sinon.stub().callsArgWith(1, "timed out")
  150. @EditorController.addDoc @project_id, @folder_id, @docName, @docLines, @source, (err)=>
  151. expect(err).to.exist
  152. err.should.equal "timed out"
  153. done()
  154. describe 'addFileWithoutLock:', ->
  155. beforeEach ->
  156. @ProjectEntityHandler.addFile = ->
  157. @EditorRealTimeController.emitToRoom = sinon.stub()
  158. @project_id = "12dsankj"
  159. @folder_id = "213kjd"
  160. @fileName = "file.png"
  161. @folder_id = "123ksajdn"
  162. @file = {_id:"dasdkjk"}
  163. @stream = new ArrayBuffer()
  164. it 'should add the folder using the project entity handler', (done)->
  165. @ProjectEntityHandler.addFile = sinon.stub().callsArgWith(4)
  166. @EditorController.addFileWithoutLock @project_id, @folder_id, @fileName, @stream, @source, =>
  167. @ProjectEntityHandler.addFile.calledWith(@project_id, @folder_id).should.equal true
  168. done()
  169. it 'should send the update of a new folder out to the users in the project', (done)->
  170. @ProjectEntityHandler.addFile = sinon.stub().callsArgWith(4, null, @file, @folder_id)
  171. @EditorController.addFileWithoutLock @project_id, @folder_id, @fileName, @stream, @source, =>
  172. @EditorRealTimeController.emitToRoom
  173. .calledWith(@project_id, "reciveNewFile", @folder_id, @file, @source)
  174. .should.equal true
  175. done()
  176. it "should return the file in the callback", (done) ->
  177. @ProjectEntityHandler.addFile = sinon.stub().callsArgWith(4, null, @file, @folder_id)
  178. @EditorController.addFileWithoutLock @project_id, @folder_id, @fileName, @stream, @source, (error, file) =>
  179. file.should.equal @file
  180. done()
  181. describe "addFile", ->
  182. beforeEach ->
  183. @LockManager.getLock.callsArgWith(1)
  184. @LockManager.releaseLock.callsArgWith(1)
  185. @EditorController.addFileWithoutLock = sinon.stub().callsArgWith(5)
  186. it "should call addFileWithoutLock", (done)->
  187. @EditorController.addFile @project_id, @folder_id, @fileName, @stream, @source, (error, file) =>
  188. @EditorController.addFileWithoutLock.calledWith(@project_id, @folder_id, @fileName, @stream, @source).should.equal true
  189. done()
  190. it "should take the lock", (done)->
  191. @EditorController.addFile @project_id, @folder_id, @fileName, @stream, @source, (error, file) =>
  192. @LockManager.getLock.calledWith(@project_id).should.equal true
  193. done()
  194. it "should release the lock", (done)->
  195. @EditorController.addFile @project_id, @folder_id, @fileName, @stream, @source, (error, file) =>
  196. @LockManager.releaseLock.calledWith(@project_id).should.equal true
  197. done()
  198. it "should error if it can't cat the lock", (done)->
  199. @LockManager.getLock = sinon.stub().callsArgWith(1, "timed out")
  200. @EditorController.addFile @project_id, @folder_id, @fileName, @stream, @source, (err, file) =>
  201. expect(err).to.exist
  202. err.should.equal "timed out"
  203. done()
  204. describe "replaceFile", ->
  205. beforeEach ->
  206. @project_id = "12dsankj"
  207. @file_id = "file_id_here"
  208. @fsPath = "/folder/file.png"
  209. it 'should send the replace file message to the editor controller', (done)->
  210. @ProjectEntityHandler.replaceFile = sinon.stub().callsArgWith(3)
  211. @EditorController.replaceFile @project_id, @file_id, @fsPath, @source, =>
  212. @ProjectEntityHandler.replaceFile.calledWith(@project_id, @file_id, @fsPath).should.equal true
  213. done()
  214. describe 'addFolderWithoutLock :', ->
  215. beforeEach ->
  216. @ProjectEntityHandler.addFolder = ->
  217. @EditorRealTimeController.emitToRoom = sinon.stub()
  218. @project_id = "12dsankj"
  219. @folder_id = "213kjd"
  220. @folderName = "folder"
  221. @folder = {_id:"123ds"}
  222. it 'should add the folder using the project entity handler', (done)->
  223. mock = sinon.mock(@ProjectEntityHandler).expects("addFolder").withArgs(@project_id, @folder_id, @folderName).callsArg(3)
  224. @EditorController.addFolderWithoutLock @project_id, @folder_id, @folderName, @source, ->
  225. mock.verify()
  226. done()
  227. it 'should notifyProjectUsersOfNewFolder', (done)->
  228. @ProjectEntityHandler.addFolder = (project_id, folder_id, folderName, callback)=> callback(null, @folder, @folder_id)
  229. mock = sinon.mock(@EditorController.p).expects('notifyProjectUsersOfNewFolder').withArgs(@project_id, @folder_id, @folder).callsArg(3)
  230. @EditorController.addFolderWithoutLock @project_id, @folder_id, @folderName, @source, ->
  231. mock.verify()
  232. done()
  233. it 'notifyProjectUsersOfNewFolder should send update out to all users', (done)->
  234. @EditorController.p.notifyProjectUsersOfNewFolder @project_id, @folder_id, @folder, =>
  235. @EditorRealTimeController.emitToRoom
  236. .calledWith(@project_id, "reciveNewFolder", @folder_id, @folder)
  237. .should.equal true
  238. done()
  239. it 'should return the folder in the callback', (done) ->
  240. @ProjectEntityHandler.addFolder = (project_id, folder_id, folderName, callback)=> callback(null, @folder, @folder_id)
  241. @EditorController.addFolderWithoutLock @project_id, @folder_id, @folderName, @source, (error, folder) =>
  242. folder.should.equal @folder
  243. done()
  244. describe "addFolder", ->
  245. beforeEach ->
  246. @LockManager.getLock.callsArgWith(1)
  247. @LockManager.releaseLock.callsArgWith(1)
  248. @EditorController.addFolderWithoutLock = sinon.stub().callsArgWith(4)
  249. it "should call addFolderWithoutLock", (done)->
  250. @EditorController.addFolder @project_id, @folder_id, @folderName, @source, (error, file) =>
  251. @EditorController.addFolderWithoutLock.calledWith(@project_id, @folder_id, @folderName, @source).should.equal true
  252. done()
  253. it "should take the lock", (done)->
  254. @EditorController.addFolder @project_id, @folder_id, @folderName, @source, (error, file) =>
  255. @LockManager.getLock.calledWith(@project_id).should.equal true
  256. done()
  257. it "should release the lock", (done)->
  258. @EditorController.addFolder @project_id, @folder_id, @folderName, @source, (error, file) =>
  259. @LockManager.releaseLock.calledWith(@project_id).should.equal true
  260. done()
  261. it "should error if it can't cat the lock", (done)->
  262. @LockManager.getLock = sinon.stub().callsArgWith(1, "timed out")
  263. @EditorController.addFolder @project_id, @folder_id, @folderName, @source, (err, file) =>
  264. expect(err).to.exist
  265. err.should.equal "timed out"
  266. done()
  267. describe 'mkdirpWithoutLock :', ->
  268. it 'should make the dirs and notifyProjectUsersOfNewFolder', (done)->
  269. path = "folder1/folder2"
  270. @folder1 = {_id:"folder_1_id_here"}
  271. @folder2 = {_id:"folder_2_id_here", parentFolder_id:@folder1._id}
  272. @folder3 = {_id:"folder_3_id_here", parentFolder_id:@folder2._id}
  273. @ProjectEntityHandler.mkdirp = sinon.stub().withArgs(@project_id, path).callsArgWith(2, null, [@folder1, @folder2, @folder3], @folder3)
  274. @EditorController.p.notifyProjectUsersOfNewFolder = sinon.stub().callsArg(3)
  275. @EditorController.mkdirpWithoutLock @project_id, path, (err, newFolders, lastFolder)=>
  276. @EditorController.p.notifyProjectUsersOfNewFolder.calledWith(@project_id, @folder1._id, @folder2).should.equal true
  277. @EditorController.p.notifyProjectUsersOfNewFolder.calledWith(@project_id, @folder2._id, @folder3).should.equal true
  278. newFolders.should.deep.equal [@folder1, @folder2, @folder3]
  279. lastFolder.should.equal @folder3
  280. done()
  281. describe "mkdirp", ->
  282. beforeEach ->
  283. @path = "folder1/folder2"
  284. @LockManager.getLock.callsArgWith(1)
  285. @LockManager.releaseLock.callsArgWith(1)
  286. @EditorController.mkdirpWithoutLock = sinon.stub().callsArgWith(2)
  287. it "should call mkdirpWithoutLock", (done)->
  288. @EditorController.mkdirp @project_id, @path, (error, file) =>
  289. @EditorController.mkdirpWithoutLock.calledWith(@project_id, @path).should.equal true
  290. done()
  291. it "should take the lock", (done)->
  292. @EditorController.mkdirp @project_id, @path, (error, file) =>
  293. @LockManager.getLock.calledWith(@project_id).should.equal true
  294. done()
  295. it "should release the lock", (done)->
  296. @EditorController.mkdirp @project_id, @path, (error, file) =>
  297. @LockManager.releaseLock.calledWith(@project_id).should.equal true
  298. done()
  299. it "should error if it can't cat the lock", (done)->
  300. @LockManager.getLock = sinon.stub().callsArgWith(1, "timed out")
  301. @EditorController.mkdirp @project_id, @path, (err, file) =>
  302. expect(err).to.exist
  303. err.should.equal "timed out"
  304. done()
  305. describe "deleteEntity", ->
  306. beforeEach ->
  307. @LockManager.getLock.callsArgWith(1)
  308. @LockManager.releaseLock.callsArgWith(1)
  309. @EditorController.deleteEntityWithoutLock = sinon.stub().callsArgWith(4)
  310. it "should call deleteEntityWithoutLock", (done)->
  311. @EditorController.deleteEntity @project_id, @entity_id, @type, @source, =>
  312. @EditorController.deleteEntityWithoutLock.calledWith(@project_id, @entity_id, @type, @source).should.equal true
  313. done()
  314. it "should take the lock", (done)->
  315. @EditorController.deleteEntity @project_id, @entity_id, @type, @source, =>
  316. @LockManager.getLock.calledWith(@project_id).should.equal true
  317. done()
  318. it "should release the lock", (done)->
  319. @EditorController.deleteEntity @project_id, @entity_id, @type, @source, (error)=>
  320. @LockManager.releaseLock.calledWith(@project_id).should.equal true
  321. done()
  322. it "should error if it can't cat the lock", (done)->
  323. @LockManager.getLock = sinon.stub().callsArgWith(1, "timed out")
  324. @EditorController.deleteEntity @project_id, @entity_id, @type, @source, (err)=>
  325. expect(err).to.exist
  326. err.should.equal "timed out"
  327. done()
  328. describe 'deleteEntityWithoutLock', ->
  329. beforeEach ->
  330. @ProjectEntityHandler.deleteEntity = (project_id, entity_id, type, callback)-> callback()
  331. @entity_id = "entity_id_here"
  332. @type = "doc"
  333. @EditorRealTimeController.emitToRoom = sinon.stub()
  334. it 'should delete the folder using the project entity handler', (done)->
  335. mock = sinon.mock(@ProjectEntityHandler).expects("deleteEntity").withArgs(@project_id, @entity_id, @type).callsArg(3)
  336. @EditorController.deleteEntityWithoutLock @project_id, @entity_id, @type, @source, ->
  337. mock.verify()
  338. done()
  339. it 'notify users an entity has been deleted', (done)->
  340. @EditorController.deleteEntityWithoutLock @project_id, @entity_id, @type, @source, =>
  341. @EditorRealTimeController.emitToRoom
  342. .calledWith(@project_id, "removeEntity", @entity_id, @source)
  343. .should.equal true
  344. done()
  345. describe "getting a list of project paths", ->
  346. it 'should call the project entity handler to get an array of docs', (done)->
  347. fullDocsHash =
  348. "/doc1.tex":{lines:["das"], _id:"1234"}
  349. "/doc2.tex":{lines:["dshajkh"]}
  350. project_id = "d312nkjnajn"
  351. @ProjectEntityHandler.getAllDocs = sinon.stub().callsArgWith(1, null, fullDocsHash)
  352. @EditorController.getListOfDocPaths project_id, (err, returnedDocs)->
  353. returnedDocs.length.should.equal 2
  354. returnedDocs[0]._id.should.equal "1234"
  355. assert.equal returnedDocs[0].lines, undefined
  356. returnedDocs[1].path.should.equal "doc2.tex"
  357. done()
  358. describe "notifyUsersProjectHasBeenDeletedOrRenamed", ->
  359. it 'should emmit a message to all users in a project', (done)->
  360. @EditorRealTimeController.emitToRoom = sinon.stub()
  361. @EditorController.notifyUsersProjectHasBeenDeletedOrRenamed @project_id, (err)=>
  362. @EditorRealTimeController.emitToRoom
  363. .calledWith(@project_id, "projectRenamedOrDeletedByExternalSource")
  364. .should.equal true
  365. done()
  366. describe "updateProjectDescription", ->
  367. beforeEach ->
  368. @description = "new description"
  369. @EditorRealTimeController.emitToRoom = sinon.stub()
  370. it "should send the new description to the project details handler", (done)->
  371. @ProjectDetailsHandler.setProjectDescription.callsArgWith(2)
  372. @EditorController.updateProjectDescription @project_id, @description, =>
  373. @ProjectDetailsHandler.setProjectDescription.calledWith(@project_id, @description).should.equal true
  374. done()
  375. it "should notify the other clients about the updated description", (done)->
  376. @ProjectDetailsHandler.setProjectDescription.callsArgWith(2)
  377. @EditorController.updateProjectDescription @project_id, @description, =>
  378. @EditorRealTimeController.emitToRoom.calledWith(@project_id, "projectDescriptionUpdated", @description).should.equal true
  379. done()
  380. describe "deleteProject", ->
  381. beforeEach ->
  382. @err = "errro"
  383. @ProjectDeleter.deleteProject = sinon.stub().callsArgWith(1, @err)
  384. it "should call the project handler", (done)->
  385. @EditorController.deleteProject @project_id, (err)=>
  386. err.should.equal @err
  387. @ProjectDeleter.deleteProject.calledWith(@project_id).should.equal true
  388. done()
  389. describe "renameEntity", ->
  390. beforeEach ->
  391. @err = "errro"
  392. @entity_id = "entity_id_here"
  393. @entityType = "doc"
  394. @newName = "bobsfile.tex"
  395. @ProjectEntityHandler.renameEntity = sinon.stub().callsArgWith(4, @err)
  396. @EditorRealTimeController.emitToRoom = sinon.stub()
  397. it "should call the project handler", (done)->
  398. @EditorController.renameEntity @project_id, @entity_id, @entityType, @newName, =>
  399. @ProjectEntityHandler.renameEntity.calledWith(@project_id, @entity_id, @entityType, @newName).should.equal true
  400. done()
  401. it "should emit the update to the room", (done)->
  402. @EditorController.renameEntity @project_id, @entity_id, @entityType, @newName, =>
  403. @EditorRealTimeController.emitToRoom.calledWith(@project_id, 'reciveEntityRename', @entity_id, @newName).should.equal true
  404. done()
  405. describe "moveEntity", ->
  406. beforeEach ->
  407. @err = "errro"
  408. @entity_id = "entity_id_here"
  409. @entityType = "doc"
  410. @folder_id = "313dasd21dasdsa"
  411. @ProjectEntityHandler.moveEntity = sinon.stub().callsArgWith(4, @err)
  412. @EditorRealTimeController.emitToRoom = sinon.stub()
  413. @LockManager.releaseLock.callsArgWith(1)
  414. @LockManager.getLock.callsArgWith(1)
  415. it "should call the ProjectEntityHandler", (done)->
  416. @EditorController.moveEntity @project_id, @entity_id, @folder_id, @entityType, =>
  417. @ProjectEntityHandler.moveEntity.calledWith(@project_id, @entity_id, @folder_id, @entityType).should.equal true
  418. done()
  419. it "should take the lock", (done)->
  420. @EditorController.moveEntity @project_id, @entity_id, @folder_id, @entityType, =>
  421. @LockManager.getLock.calledWith(@project_id).should.equal true
  422. done()
  423. it "should release the lock", (done)->
  424. @EditorController.moveEntity @project_id, @entity_id, @folder_id, @entityType, =>
  425. @LockManager.releaseLock.calledWith(@project_id).should.equal true
  426. done()
  427. it "should emit the update to the room", (done)->
  428. @EditorController.moveEntity @project_id, @entity_id, @folder_id, @entityType, =>
  429. @EditorRealTimeController.emitToRoom.calledWith(@project_id, 'reciveEntityMove', @entity_id, @folder_id).should.equal true
  430. done()
  431. describe "renameProject", ->
  432. beforeEach ->
  433. @err = "errro"
  434. @window_id = "kdsjklj290jlk"
  435. @newName = "new name here"
  436. @ProjectDetailsHandler.renameProject = sinon.stub().callsArgWith(2, @err)
  437. @EditorRealTimeController.emitToRoom = sinon.stub()
  438. it "should call the EditorController", (done)->
  439. @EditorController.renameProject @project_id, @newName, =>
  440. @ProjectDetailsHandler.renameProject.calledWith(@project_id, @newName).should.equal true
  441. done()
  442. it "should emit the update to the room", (done)->
  443. @EditorController.renameProject @project_id, @newName, =>
  444. @EditorRealTimeController.emitToRoom.calledWith(@project_id, 'projectNameUpdated', @newName).should.equal true
  445. done()
  446. describe "setPublicAccessLevel", ->
  447. beforeEach ->
  448. @newAccessLevel = "public"
  449. @ProjectDetailsHandler.setPublicAccessLevel = sinon.stub().callsArgWith(2, null)
  450. @EditorRealTimeController.emitToRoom = sinon.stub()
  451. it "should call the EditorController", (done)->
  452. @EditorController.setPublicAccessLevel @project_id, @newAccessLevel, =>
  453. @ProjectDetailsHandler.setPublicAccessLevel.calledWith(@project_id, @newAccessLevel).should.equal true
  454. done()
  455. it "should emit the update to the room", (done)->
  456. @EditorController.setPublicAccessLevel @project_id, @newAccessLevel, =>
  457. @EditorRealTimeController.emitToRoom.calledWith(@project_id, 'publicAccessLevelUpdated', @newAccessLevel).should.equal true
  458. done()
  459. describe "setRootDoc", ->
  460. beforeEach ->
  461. @newRootDocID = "21312321321"
  462. @ProjectEntityHandler.setRootDoc = sinon.stub().callsArgWith(2, null)
  463. @EditorRealTimeController.emitToRoom = sinon.stub()
  464. it "should call the ProjectEntityHandler", (done)->
  465. @EditorController.setRootDoc @project_id, @newRootDocID, =>
  466. @ProjectEntityHandler.setRootDoc.calledWith(@project_id, @newRootDocID).should.equal true
  467. done()
  468. it "should emit the update to the room", (done)->
  469. @EditorController.setRootDoc @project_id, @newRootDocID, =>
  470. @EditorRealTimeController.emitToRoom.calledWith(@project_id, 'rootDocUpdated', @newRootDocID).should.equal true
  471. done()