EditorControllerTests.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966
  1. /* eslint-disable
  2. node/handle-callback-err,
  3. max-len,
  4. no-return-assign,
  5. no-unused-vars,
  6. */
  7. // TODO: This file was created by bulk-decaffeinate.
  8. // Fix any style issues and re-enable lint.
  9. /*
  10. * decaffeinate suggestions:
  11. * DS102: Remove unnecessary code created because of implicit returns
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. const SandboxedModule = require('sandboxed-module')
  15. const sinon = require('sinon')
  16. require('chai').should()
  17. const { expect } = require('chai')
  18. const modulePath = require('path').join(
  19. __dirname,
  20. '../../../../app/src/Features/Editor/EditorController'
  21. )
  22. const MockClient = require('../helpers/MockClient')
  23. const assert = require('assert')
  24. const { ObjectId } = require('mongodb')
  25. describe('EditorController', function() {
  26. beforeEach(function() {
  27. this.project_id = 'test-project-id'
  28. this.source = 'dropbox'
  29. this.user_id = new ObjectId()
  30. this.doc = { _id: (this.doc_id = 'test-doc-id') }
  31. this.docName = 'doc.tex'
  32. this.docLines = ['1234', 'dskl']
  33. this.file = { _id: (this.file_id = 'dasdkjk') }
  34. this.fileName = 'file.png'
  35. this.fsPath = '/folder/file.png'
  36. this.linkedFileData = { provider: 'url' }
  37. this.newFile = { _id: 'new-file-id' }
  38. this.folder_id = '123ksajdn'
  39. this.folder = { _id: this.folder_id }
  40. this.folderName = 'folder'
  41. this.callback = sinon.stub()
  42. return (this.EditorController = SandboxedModule.require(modulePath, {
  43. globals: {
  44. console: console
  45. },
  46. requires: {
  47. '../Project/ProjectEntityUpdateHandler': (this.ProjectEntityUpdateHandler = {}),
  48. '../Project/ProjectOptionsHandler': (this.ProjectOptionsHandler = {
  49. setCompiler: sinon.stub().yields(),
  50. setImageName: sinon.stub().yields(),
  51. setSpellCheckLanguage: sinon.stub().yields()
  52. }),
  53. '../Project/ProjectDetailsHandler': (this.ProjectDetailsHandler = {
  54. setProjectDescription: sinon.stub().yields(),
  55. renameProject: sinon.stub().yields(),
  56. setPublicAccessLevel: sinon.stub().yields()
  57. }),
  58. '../Project/ProjectDeleter': (this.ProjectDeleter = {}),
  59. '../DocumentUpdater/DocumentUpdaterHandler': (this.DocumentUpdaterHandler = {
  60. flushDocToMongo: sinon.stub().yields(),
  61. setDocument: sinon.stub().yields()
  62. }),
  63. './EditorRealTimeController': (this.EditorRealTimeController = {
  64. emitToRoom: sinon.stub()
  65. }),
  66. '@overleaf/metrics': (this.Metrics = { inc: sinon.stub() }),
  67. 'logger-sharelatex': (this.logger = {
  68. log: sinon.stub(),
  69. err: sinon.stub()
  70. })
  71. }
  72. }))
  73. })
  74. describe('addDoc', function() {
  75. beforeEach(function() {
  76. this.ProjectEntityUpdateHandler.addDocWithRanges = sinon
  77. .stub()
  78. .yields(null, this.doc, this.folder_id)
  79. return this.EditorController.addDoc(
  80. this.project_id,
  81. this.folder_id,
  82. this.docName,
  83. this.docLines,
  84. this.source,
  85. this.user_id,
  86. this.callback
  87. )
  88. })
  89. it('should add the doc using the project entity handler', function() {
  90. return this.ProjectEntityUpdateHandler.addDocWithRanges
  91. .calledWith(
  92. this.project_id,
  93. this.folder_id,
  94. this.docName,
  95. this.docLines,
  96. {}
  97. )
  98. .should.equal(true)
  99. })
  100. it('should send the update out to the users in the project', function() {
  101. return this.EditorRealTimeController.emitToRoom
  102. .calledWith(
  103. this.project_id,
  104. 'reciveNewDoc',
  105. this.folder_id,
  106. this.doc,
  107. this.source,
  108. this.user_id
  109. )
  110. .should.equal(true)
  111. })
  112. it('calls the callback', function() {
  113. return this.callback.calledWith(null, this.doc).should.equal(true)
  114. })
  115. })
  116. describe('addFile', function() {
  117. beforeEach(function() {
  118. this.ProjectEntityUpdateHandler.addFile = sinon
  119. .stub()
  120. .yields(null, this.file, this.folder_id)
  121. return this.EditorController.addFile(
  122. this.project_id,
  123. this.folder_id,
  124. this.fileName,
  125. this.fsPath,
  126. this.linkedFileData,
  127. this.source,
  128. this.user_id,
  129. this.callback
  130. )
  131. })
  132. it('should add the folder using the project entity handler', function() {
  133. return this.ProjectEntityUpdateHandler.addFile
  134. .calledWith(
  135. this.project_id,
  136. this.folder_id,
  137. this.fileName,
  138. this.fsPath,
  139. this.linkedFileData,
  140. this.user_id
  141. )
  142. .should.equal(true)
  143. })
  144. it('should send the update of a new folder out to the users in the project', function() {
  145. return this.EditorRealTimeController.emitToRoom
  146. .calledWith(
  147. this.project_id,
  148. 'reciveNewFile',
  149. this.folder_id,
  150. this.file,
  151. this.source,
  152. this.linkedFileData,
  153. this.user_id
  154. )
  155. .should.equal(true)
  156. })
  157. it('calls the callback', function() {
  158. return this.callback.calledWith(null, this.file).should.equal(true)
  159. })
  160. })
  161. describe('upsertDoc', function() {
  162. beforeEach(function() {
  163. this.ProjectEntityUpdateHandler.upsertDoc = sinon
  164. .stub()
  165. .yields(null, this.doc, false)
  166. return this.EditorController.upsertDoc(
  167. this.project_id,
  168. this.folder_id,
  169. this.docName,
  170. this.docLines,
  171. this.source,
  172. this.user_id,
  173. this.callback
  174. )
  175. })
  176. it('upserts the doc using the project entity handler', function() {
  177. return this.ProjectEntityUpdateHandler.upsertDoc
  178. .calledWith(
  179. this.project_id,
  180. this.folder_id,
  181. this.docName,
  182. this.docLines,
  183. this.source
  184. )
  185. .should.equal(true)
  186. })
  187. it('returns the doc', function() {
  188. return this.callback.calledWith(null, this.doc).should.equal(true)
  189. })
  190. describe('doc does not exist', function() {
  191. beforeEach(function() {
  192. this.ProjectEntityUpdateHandler.upsertDoc = sinon
  193. .stub()
  194. .yields(null, this.doc, true)
  195. return this.EditorController.upsertDoc(
  196. this.project_id,
  197. this.folder_id,
  198. this.docName,
  199. this.docLines,
  200. this.source,
  201. this.user_id,
  202. this.callback
  203. )
  204. })
  205. it('sends an update out to users in the project', function() {
  206. return this.EditorRealTimeController.emitToRoom
  207. .calledWith(
  208. this.project_id,
  209. 'reciveNewDoc',
  210. this.folder_id,
  211. this.doc,
  212. this.source,
  213. this.user_id
  214. )
  215. .should.equal(true)
  216. })
  217. })
  218. })
  219. describe('upsertFile', function() {
  220. beforeEach(function() {
  221. this.ProjectEntityUpdateHandler.upsertFile = sinon
  222. .stub()
  223. .yields(null, this.newFile, false, this.file)
  224. return this.EditorController.upsertFile(
  225. this.project_id,
  226. this.folder_id,
  227. this.fileName,
  228. this.fsPath,
  229. this.linkedFileData,
  230. this.source,
  231. this.user_id,
  232. this.callback
  233. )
  234. })
  235. it('upserts the file using the project entity handler', function() {
  236. return this.ProjectEntityUpdateHandler.upsertFile
  237. .calledWith(
  238. this.project_id,
  239. this.folder_id,
  240. this.fileName,
  241. this.fsPath,
  242. this.linkedFileData,
  243. this.user_id
  244. )
  245. .should.equal(true)
  246. })
  247. it('returns the file', function() {
  248. return this.callback.calledWith(null, this.newFile).should.equal(true)
  249. })
  250. describe('file does not exist', function() {
  251. beforeEach(function() {
  252. this.ProjectEntityUpdateHandler.upsertFile = sinon
  253. .stub()
  254. .yields(null, this.file, true)
  255. return this.EditorController.upsertFile(
  256. this.project_id,
  257. this.folder_id,
  258. this.fileName,
  259. this.fsPath,
  260. this.linkedFileData,
  261. this.source,
  262. this.user_id,
  263. this.callback
  264. )
  265. })
  266. it('should send the update out to users in the project', function() {
  267. return this.EditorRealTimeController.emitToRoom
  268. .calledWith(
  269. this.project_id,
  270. 'reciveNewFile',
  271. this.folder_id,
  272. this.file,
  273. this.source,
  274. this.linkedFileData,
  275. this.user_id
  276. )
  277. .should.equal(true)
  278. })
  279. })
  280. })
  281. describe('upsertDocWithPath', function() {
  282. beforeEach(function() {
  283. this.docPath = '/folder/doc'
  284. this.ProjectEntityUpdateHandler.upsertDocWithPath = sinon
  285. .stub()
  286. .yields(null, this.doc, false, [], this.folder)
  287. return this.EditorController.upsertDocWithPath(
  288. this.project_id,
  289. this.docPath,
  290. this.docLines,
  291. this.source,
  292. this.user_id,
  293. this.callback
  294. )
  295. })
  296. it('upserts the doc using the project entity handler', function() {
  297. return this.ProjectEntityUpdateHandler.upsertDocWithPath
  298. .calledWith(this.project_id, this.docPath, this.docLines, this.source)
  299. .should.equal(true)
  300. })
  301. describe('doc does not exist', function() {
  302. beforeEach(function() {
  303. this.ProjectEntityUpdateHandler.upsertDocWithPath = sinon
  304. .stub()
  305. .yields(null, this.doc, true, [], this.folder)
  306. return this.EditorController.upsertDocWithPath(
  307. this.project_id,
  308. this.docPath,
  309. this.docLines,
  310. this.source,
  311. this.user_id,
  312. this.callback
  313. )
  314. })
  315. it('should send the update for the doc out to users in the project', function() {
  316. return this.EditorRealTimeController.emitToRoom
  317. .calledWith(
  318. this.project_id,
  319. 'reciveNewDoc',
  320. this.folder_id,
  321. this.doc,
  322. this.source,
  323. this.user_id
  324. )
  325. .should.equal(true)
  326. })
  327. })
  328. describe('folders required for doc do not exist', function() {
  329. beforeEach(function() {
  330. const folders = [
  331. (this.folderA = { _id: 2, parentFolder_id: 1 }),
  332. (this.folderB = { _id: 3, parentFolder_id: 2 })
  333. ]
  334. this.ProjectEntityUpdateHandler.upsertDocWithPath = sinon
  335. .stub()
  336. .yields(null, this.doc, true, folders, this.folderB)
  337. return this.EditorController.upsertDocWithPath(
  338. this.project_id,
  339. this.docPath,
  340. this.docLines,
  341. this.source,
  342. this.user_id,
  343. this.callback
  344. )
  345. })
  346. it('should send the update for each folder to users in the project', function() {
  347. this.EditorRealTimeController.emitToRoom
  348. .calledWith(
  349. this.project_id,
  350. 'reciveNewFolder',
  351. this.folderA.parentFolder_id,
  352. this.folderA
  353. )
  354. .should.equal(true)
  355. return this.EditorRealTimeController.emitToRoom
  356. .calledWith(
  357. this.project_id,
  358. 'reciveNewFolder',
  359. this.folderB.parentFolder_id,
  360. this.folderB
  361. )
  362. .should.equal(true)
  363. })
  364. })
  365. })
  366. describe('upsertFileWithPath', function() {
  367. beforeEach(function() {
  368. this.filePath = '/folder/file'
  369. this.ProjectEntityUpdateHandler.upsertFileWithPath = sinon
  370. .stub()
  371. .yields(null, this.newFile, false, this.file, [], this.folder)
  372. return this.EditorController.upsertFileWithPath(
  373. this.project_id,
  374. this.filePath,
  375. this.fsPath,
  376. this.linkedFileData,
  377. this.source,
  378. this.user_id,
  379. this.callback
  380. )
  381. })
  382. it('upserts the file using the project entity handler', function() {
  383. return this.ProjectEntityUpdateHandler.upsertFileWithPath
  384. .calledWith(
  385. this.project_id,
  386. this.filePath,
  387. this.fsPath,
  388. this.linkedFileData
  389. )
  390. .should.equal(true)
  391. })
  392. describe('file does not exist', function() {
  393. beforeEach(function() {
  394. this.ProjectEntityUpdateHandler.upsertFileWithPath = sinon
  395. .stub()
  396. .yields(null, this.file, true, undefined, [], this.folder)
  397. return this.EditorController.upsertFileWithPath(
  398. this.project_id,
  399. this.filePath,
  400. this.fsPath,
  401. this.linkedFileData,
  402. this.source,
  403. this.user_id,
  404. this.callback
  405. )
  406. })
  407. it('should send the update for the file out to users in the project', function() {
  408. return this.EditorRealTimeController.emitToRoom
  409. .calledWith(
  410. this.project_id,
  411. 'reciveNewFile',
  412. this.folder_id,
  413. this.file,
  414. this.source,
  415. this.linkedFileData,
  416. this.user_id
  417. )
  418. .should.equal(true)
  419. })
  420. })
  421. describe('folders required for file do not exist', function() {
  422. beforeEach(function() {
  423. const folders = [
  424. (this.folderA = { _id: 2, parentFolder_id: 1 }),
  425. (this.folderB = { _id: 3, parentFolder_id: 2 })
  426. ]
  427. this.ProjectEntityUpdateHandler.upsertFileWithPath = sinon
  428. .stub()
  429. .yields(null, this.file, true, undefined, folders, this.folderB)
  430. return this.EditorController.upsertFileWithPath(
  431. this.project_id,
  432. this.filePath,
  433. this.fsPath,
  434. this.linkedFileData,
  435. this.source,
  436. this.user_id,
  437. this.callback
  438. )
  439. })
  440. it('should send the update for each folder to users in the project', function() {
  441. this.EditorRealTimeController.emitToRoom
  442. .calledWith(
  443. this.project_id,
  444. 'reciveNewFolder',
  445. this.folderA.parentFolder_id,
  446. this.folderA
  447. )
  448. .should.equal(true)
  449. return this.EditorRealTimeController.emitToRoom
  450. .calledWith(
  451. this.project_id,
  452. 'reciveNewFolder',
  453. this.folderB.parentFolder_id,
  454. this.folderB
  455. )
  456. .should.equal(true)
  457. })
  458. })
  459. })
  460. describe('addFolder', function() {
  461. beforeEach(function() {
  462. this.EditorController._notifyProjectUsersOfNewFolder = sinon
  463. .stub()
  464. .yields()
  465. this.ProjectEntityUpdateHandler.addFolder = sinon
  466. .stub()
  467. .yields(null, this.folder, this.folder_id)
  468. return this.EditorController.addFolder(
  469. this.project_id,
  470. this.folder_id,
  471. this.folderName,
  472. this.source,
  473. this.user_id,
  474. this.callback
  475. )
  476. })
  477. it('should add the folder using the project entity handler', function() {
  478. return this.ProjectEntityUpdateHandler.addFolder
  479. .calledWith(this.project_id, this.folder_id, this.folderName)
  480. .should.equal(true)
  481. })
  482. it('should notifyProjectUsersOfNewFolder', function() {
  483. return this.EditorController._notifyProjectUsersOfNewFolder
  484. .calledWith(this.project_id, this.folder_id, this.folder, this.user_id)
  485. .should.equal(true)
  486. })
  487. it('should return the folder in the callback', function() {
  488. return this.callback.calledWith(null, this.folder).should.equal(true)
  489. })
  490. })
  491. describe('mkdirp', function() {
  492. beforeEach(function() {
  493. this.path = 'folder1/folder2'
  494. this.folders = [
  495. (this.folderA = { _id: 2, parentFolder_id: 1 }),
  496. (this.folderB = { _id: 3, parentFolder_id: 2 })
  497. ]
  498. this.EditorController._notifyProjectUsersOfNewFolders = sinon
  499. .stub()
  500. .yields()
  501. this.ProjectEntityUpdateHandler.mkdirp = sinon
  502. .stub()
  503. .yields(null, this.folders, this.folder)
  504. return this.EditorController.mkdirp(
  505. this.project_id,
  506. this.path,
  507. this.callback
  508. )
  509. })
  510. it('should create the folder using the project entity handler', function() {
  511. return this.ProjectEntityUpdateHandler.mkdirp
  512. .calledWith(this.project_id, this.path)
  513. .should.equal(true)
  514. })
  515. it('should notifyProjectUsersOfNewFolder', function() {
  516. return this.EditorController._notifyProjectUsersOfNewFolders.calledWith(
  517. this.project_id,
  518. this.folders
  519. )
  520. })
  521. it('should return the folder in the callback', function() {
  522. return this.callback
  523. .calledWith(null, this.folders, this.folder)
  524. .should.equal(true)
  525. })
  526. })
  527. describe('deleteEntity', function() {
  528. beforeEach(function() {
  529. this.entity_id = 'entity_id_here'
  530. this.type = 'doc'
  531. this.ProjectEntityUpdateHandler.deleteEntity = sinon.stub().yields()
  532. return this.EditorController.deleteEntity(
  533. this.project_id,
  534. this.entity_id,
  535. this.type,
  536. this.source,
  537. this.user_id,
  538. this.callback
  539. )
  540. })
  541. it('should delete the folder using the project entity handler', function() {
  542. return this.ProjectEntityUpdateHandler.deleteEntity
  543. .calledWith(this.project_id, this.entity_id, this.type, this.user_id)
  544. .should.equal(true)
  545. })
  546. it('notify users an entity has been deleted', function() {
  547. return this.EditorRealTimeController.emitToRoom
  548. .calledWith(
  549. this.project_id,
  550. 'removeEntity',
  551. this.entity_id,
  552. this.source
  553. )
  554. .should.equal(true)
  555. })
  556. })
  557. describe('deleteEntityWithPath', function() {
  558. beforeEach(function() {
  559. this.entity_id = 'entity_id_here'
  560. this.ProjectEntityUpdateHandler.deleteEntityWithPath = sinon
  561. .stub()
  562. .yields(null, this.entity_id)
  563. this.path = 'folder1/folder2'
  564. return this.EditorController.deleteEntityWithPath(
  565. this.project_id,
  566. this.path,
  567. this.source,
  568. this.user_id,
  569. this.callback
  570. )
  571. })
  572. it('should delete the folder using the project entity handler', function() {
  573. return this.ProjectEntityUpdateHandler.deleteEntityWithPath
  574. .calledWith(this.project_id, this.path, this.user_id)
  575. .should.equal(true)
  576. })
  577. it('notify users an entity has been deleted', function() {
  578. return this.EditorRealTimeController.emitToRoom
  579. .calledWith(
  580. this.project_id,
  581. 'removeEntity',
  582. this.entity_id,
  583. this.source
  584. )
  585. .should.equal(true)
  586. })
  587. })
  588. describe('updateProjectDescription', function() {
  589. beforeEach(function() {
  590. this.description = 'new description'
  591. return this.EditorController.updateProjectDescription(
  592. this.project_id,
  593. this.description,
  594. this.callback
  595. )
  596. })
  597. it('should send the new description to the project details handler', function() {
  598. return this.ProjectDetailsHandler.setProjectDescription
  599. .calledWith(this.project_id, this.description)
  600. .should.equal(true)
  601. })
  602. it('should notify the other clients about the updated description', function() {
  603. return this.EditorRealTimeController.emitToRoom
  604. .calledWith(
  605. this.project_id,
  606. 'projectDescriptionUpdated',
  607. this.description
  608. )
  609. .should.equal(true)
  610. })
  611. })
  612. describe('deleteProject', function() {
  613. beforeEach(function() {
  614. this.err = 'errro'
  615. return (this.ProjectDeleter.deleteProject = sinon
  616. .stub()
  617. .callsArgWith(1, this.err))
  618. })
  619. it('should call the project handler', function(done) {
  620. return this.EditorController.deleteProject(this.project_id, err => {
  621. err.should.equal(this.err)
  622. this.ProjectDeleter.deleteProject
  623. .calledWith(this.project_id)
  624. .should.equal(true)
  625. return done()
  626. })
  627. })
  628. })
  629. describe('renameEntity', function() {
  630. beforeEach(function(done) {
  631. this.entity_id = 'entity_id_here'
  632. this.entityType = 'doc'
  633. this.newName = 'bobsfile.tex'
  634. this.ProjectEntityUpdateHandler.renameEntity = sinon.stub().yields()
  635. return this.EditorController.renameEntity(
  636. this.project_id,
  637. this.entity_id,
  638. this.entityType,
  639. this.newName,
  640. this.user_id,
  641. done
  642. )
  643. })
  644. it('should call the project handler', function() {
  645. return this.ProjectEntityUpdateHandler.renameEntity
  646. .calledWith(
  647. this.project_id,
  648. this.entity_id,
  649. this.entityType,
  650. this.newName,
  651. this.user_id
  652. )
  653. .should.equal(true)
  654. })
  655. it('should emit the update to the room', function() {
  656. return this.EditorRealTimeController.emitToRoom
  657. .calledWith(
  658. this.project_id,
  659. 'reciveEntityRename',
  660. this.entity_id,
  661. this.newName
  662. )
  663. .should.equal(true)
  664. })
  665. })
  666. describe('moveEntity', function() {
  667. beforeEach(function() {
  668. this.entity_id = 'entity_id_here'
  669. this.entityType = 'doc'
  670. this.ProjectEntityUpdateHandler.moveEntity = sinon.stub().yields()
  671. return this.EditorController.moveEntity(
  672. this.project_id,
  673. this.entity_id,
  674. this.folder_id,
  675. this.entityType,
  676. this.user_id,
  677. this.callback
  678. )
  679. })
  680. it('should call the ProjectEntityUpdateHandler', function() {
  681. return this.ProjectEntityUpdateHandler.moveEntity
  682. .calledWith(
  683. this.project_id,
  684. this.entity_id,
  685. this.folder_id,
  686. this.entityType,
  687. this.user_id
  688. )
  689. .should.equal(true)
  690. })
  691. it('should emit the update to the room', function() {
  692. return this.EditorRealTimeController.emitToRoom
  693. .calledWith(
  694. this.project_id,
  695. 'reciveEntityMove',
  696. this.entity_id,
  697. this.folder_id
  698. )
  699. .should.equal(true)
  700. })
  701. it('calls the callback', function() {
  702. return this.callback.called.should.equal(true)
  703. })
  704. })
  705. describe('renameProject', function() {
  706. beforeEach(function() {
  707. this.err = 'errro'
  708. this.newName = 'new name here'
  709. return this.EditorController.renameProject(
  710. this.project_id,
  711. this.newName,
  712. this.callback
  713. )
  714. })
  715. it('should call the EditorController', function() {
  716. return this.ProjectDetailsHandler.renameProject
  717. .calledWith(this.project_id, this.newName)
  718. .should.equal(true)
  719. })
  720. it('should emit the update to the room', function() {
  721. return this.EditorRealTimeController.emitToRoom
  722. .calledWith(this.project_id, 'projectNameUpdated', this.newName)
  723. .should.equal(true)
  724. })
  725. })
  726. describe('setCompiler', function() {
  727. beforeEach(function() {
  728. this.compiler = 'latex'
  729. return this.EditorController.setCompiler(
  730. this.project_id,
  731. this.compiler,
  732. this.callback
  733. )
  734. })
  735. it('should send the new compiler and project id to the project options handler', function() {
  736. this.ProjectOptionsHandler.setCompiler
  737. .calledWith(this.project_id, this.compiler)
  738. .should.equal(true)
  739. return this.EditorRealTimeController.emitToRoom
  740. .calledWith(this.project_id, 'compilerUpdated', this.compiler)
  741. .should.equal(true)
  742. })
  743. })
  744. describe('setImageName', function() {
  745. beforeEach(function() {
  746. this.imageName = 'texlive-1234.5'
  747. return this.EditorController.setImageName(
  748. this.project_id,
  749. this.imageName,
  750. this.callback
  751. )
  752. })
  753. it('should send the new imageName and project id to the project options handler', function() {
  754. this.ProjectOptionsHandler.setImageName
  755. .calledWith(this.project_id, this.imageName)
  756. .should.equal(true)
  757. return this.EditorRealTimeController.emitToRoom
  758. .calledWith(this.project_id, 'imageNameUpdated', this.imageName)
  759. .should.equal(true)
  760. })
  761. })
  762. describe('setSpellCheckLanguage', function() {
  763. beforeEach(function() {
  764. this.languageCode = 'fr'
  765. return this.EditorController.setSpellCheckLanguage(
  766. this.project_id,
  767. this.languageCode,
  768. this.callback
  769. )
  770. })
  771. it('should send the new languageCode and project id to the project options handler', function() {
  772. this.ProjectOptionsHandler.setSpellCheckLanguage
  773. .calledWith(this.project_id, this.languageCode)
  774. .should.equal(true)
  775. return this.EditorRealTimeController.emitToRoom
  776. .calledWith(
  777. this.project_id,
  778. 'spellCheckLanguageUpdated',
  779. this.languageCode
  780. )
  781. .should.equal(true)
  782. })
  783. })
  784. describe('setPublicAccessLevel', function() {
  785. describe('when setting to private', function() {
  786. beforeEach(function() {
  787. this.newAccessLevel = 'private'
  788. this.ProjectDetailsHandler.ensureTokensArePresent = sinon
  789. .stub()
  790. .yields(null, this.tokens)
  791. return this.EditorController.setPublicAccessLevel(
  792. this.project_id,
  793. this.newAccessLevel,
  794. this.callback
  795. )
  796. })
  797. it('should set the access level', function() {
  798. return this.ProjectDetailsHandler.setPublicAccessLevel
  799. .calledWith(this.project_id, this.newAccessLevel)
  800. .should.equal(true)
  801. })
  802. it('should broadcast the access level change', function() {
  803. return this.EditorRealTimeController.emitToRoom
  804. .calledWith(this.project_id, 'project:publicAccessLevel:changed')
  805. .should.equal(true)
  806. })
  807. it('should not ensure tokens are present for project', function() {
  808. return this.ProjectDetailsHandler.ensureTokensArePresent
  809. .calledWith(this.project_id)
  810. .should.equal(false)
  811. })
  812. it('should not broadcast a token change', function() {
  813. return this.EditorRealTimeController.emitToRoom
  814. .calledWith(this.project_id, 'project:tokens:changed', {
  815. tokens: this.tokens
  816. })
  817. .should.equal(false)
  818. })
  819. })
  820. describe('when setting to tokenBased', function() {
  821. beforeEach(function() {
  822. this.newAccessLevel = 'tokenBased'
  823. this.tokens = { readOnly: 'aaa', readAndWrite: '42bbb' }
  824. this.ProjectDetailsHandler.ensureTokensArePresent = sinon
  825. .stub()
  826. .yields(null, this.tokens)
  827. return this.EditorController.setPublicAccessLevel(
  828. this.project_id,
  829. this.newAccessLevel,
  830. this.callback
  831. )
  832. })
  833. it('should set the access level', function() {
  834. return this.ProjectDetailsHandler.setPublicAccessLevel
  835. .calledWith(this.project_id, this.newAccessLevel)
  836. .should.equal(true)
  837. })
  838. it('should broadcast the access level change', function() {
  839. return this.EditorRealTimeController.emitToRoom
  840. .calledWith(this.project_id, 'project:publicAccessLevel:changed')
  841. .should.equal(true)
  842. })
  843. it('should ensure tokens are present for project', function() {
  844. return this.ProjectDetailsHandler.ensureTokensArePresent
  845. .calledWith(this.project_id)
  846. .should.equal(true)
  847. })
  848. it('should broadcast the token change too', function() {
  849. return this.EditorRealTimeController.emitToRoom
  850. .calledWith(this.project_id, 'project:tokens:changed', {
  851. tokens: this.tokens
  852. })
  853. .should.equal(true)
  854. })
  855. })
  856. })
  857. describe('setRootDoc', function() {
  858. beforeEach(function() {
  859. this.newRootDocID = '21312321321'
  860. this.ProjectEntityUpdateHandler.setRootDoc = sinon.stub().yields()
  861. return this.EditorController.setRootDoc(
  862. this.project_id,
  863. this.newRootDocID,
  864. this.callback
  865. )
  866. })
  867. it('should call the ProjectEntityUpdateHandler', function() {
  868. return this.ProjectEntityUpdateHandler.setRootDoc
  869. .calledWith(this.project_id, this.newRootDocID)
  870. .should.equal(true)
  871. })
  872. it('should emit the update to the room', function() {
  873. return this.EditorRealTimeController.emitToRoom
  874. .calledWith(this.project_id, 'rootDocUpdated', this.newRootDocID)
  875. .should.equal(true)
  876. })
  877. })
  878. })