EditorControllerTests.js 28 KB

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