| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082 |
- /* eslint-disable
- n/handle-callback-err,
- max-len,
- no-return-assign,
- no-unused-vars,
- */
- // TODO: This file was created by bulk-decaffeinate.
- // Fix any style issues and re-enable lint.
- /*
- * decaffeinate suggestions:
- * DS102: Remove unnecessary code created because of implicit returns
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
- */
- const SandboxedModule = require('sandboxed-module')
- const sinon = require('sinon')
- const { expect } = require('chai')
- const OError = require('@overleaf/o-error')
- const modulePath = require('path').join(
- __dirname,
- '../../../../app/src/Features/Editor/EditorController'
- )
- const MockClient = require('../helpers/MockClient')
- const assert = require('assert')
- const { ObjectId } = require('mongodb-legacy')
- describe('EditorController', function () {
- beforeEach(function () {
- this.project_id = 'test-project-id'
- this.source = 'dropbox'
- this.user_id = new ObjectId()
- this.doc = { _id: (this.doc_id = 'test-doc-id') }
- this.docName = 'doc.tex'
- this.docLines = ['1234', 'dskl']
- this.file = { _id: (this.file_id = 'dasdkjk') }
- this.fileName = 'file.png'
- this.fsPath = '/folder/file.png'
- this.linkedFileData = { provider: 'url' }
- this.newFile = { _id: 'new-file-id' }
- this.folder_id = '123ksajdn'
- this.folder = { _id: this.folder_id }
- this.folderName = 'folder'
- this.callback = sinon.stub()
- return (this.EditorController = SandboxedModule.require(modulePath, {
- requires: {
- '../Project/ProjectEntityUpdateHandler':
- (this.ProjectEntityUpdateHandler = {}),
- '../Project/ProjectOptionsHandler': (this.ProjectOptionsHandler = {
- setCompiler: sinon.stub().yields(),
- setImageName: sinon.stub().yields(),
- setSpellCheckLanguage: sinon.stub().yields(),
- }),
- '../Project/ProjectDetailsHandler': (this.ProjectDetailsHandler = {
- setProjectDescription: sinon.stub().yields(),
- renameProject: sinon.stub().yields(),
- setPublicAccessLevel: sinon.stub().yields(),
- }),
- '../Project/ProjectDeleter': (this.ProjectDeleter = {}),
- '../DocumentUpdater/DocumentUpdaterHandler':
- (this.DocumentUpdaterHandler = {
- flushDocToMongo: sinon.stub().yields(),
- setDocument: sinon.stub().yields(),
- }),
- './EditorRealTimeController': (this.EditorRealTimeController = {
- emitToRoom: sinon.stub(),
- }),
- '@overleaf/metrics': (this.Metrics = { inc: sinon.stub() }),
- },
- }))
- })
- describe('addDoc', function () {
- beforeEach(function () {
- this.ProjectEntityUpdateHandler.addDocWithRanges = sinon
- .stub()
- .yields(null, this.doc, this.folder_id)
- return this.EditorController.addDoc(
- this.project_id,
- this.folder_id,
- this.docName,
- this.docLines,
- this.source,
- this.user_id,
- this.callback
- )
- })
- it('should add the doc using the project entity handler', function () {
- return this.ProjectEntityUpdateHandler.addDocWithRanges
- .calledWith(
- this.project_id,
- this.folder_id,
- this.docName,
- this.docLines,
- {},
- this.user_id,
- this.source
- )
- .should.equal(true)
- })
- it('should send the update out to the users in the project', function () {
- return this.EditorRealTimeController.emitToRoom
- .calledWith(
- this.project_id,
- 'reciveNewDoc',
- this.folder_id,
- this.doc,
- this.source,
- this.user_id
- )
- .should.equal(true)
- })
- it('calls the callback', function () {
- return this.callback.calledWith(null, this.doc).should.equal(true)
- })
- })
- describe('addFile', function () {
- beforeEach(function () {
- this.ProjectEntityUpdateHandler.addFile = sinon
- .stub()
- .yields(null, this.file, this.folder_id)
- return this.EditorController.addFile(
- this.project_id,
- this.folder_id,
- this.fileName,
- this.fsPath,
- this.linkedFileData,
- this.source,
- this.user_id,
- this.callback
- )
- })
- it('should add the folder using the project entity handler', function () {
- return this.ProjectEntityUpdateHandler.addFile
- .calledWith(
- this.project_id,
- this.folder_id,
- this.fileName,
- this.fsPath,
- this.linkedFileData,
- this.user_id,
- this.source
- )
- .should.equal(true)
- })
- it('should send the update of a new folder out to the users in the project', function () {
- return this.EditorRealTimeController.emitToRoom
- .calledWith(
- this.project_id,
- 'reciveNewFile',
- this.folder_id,
- this.file,
- this.source,
- this.linkedFileData,
- this.user_id
- )
- .should.equal(true)
- })
- it('calls the callback', function () {
- return this.callback.calledWith(null, this.file).should.equal(true)
- })
- })
- describe('upsertDoc', function () {
- beforeEach(function () {
- this.ProjectEntityUpdateHandler.upsertDoc = sinon
- .stub()
- .yields(null, this.doc, false)
- return this.EditorController.upsertDoc(
- this.project_id,
- this.folder_id,
- this.docName,
- this.docLines,
- this.source,
- this.user_id,
- this.callback
- )
- })
- it('upserts the doc using the project entity handler', function () {
- return this.ProjectEntityUpdateHandler.upsertDoc
- .calledWith(
- this.project_id,
- this.folder_id,
- this.docName,
- this.docLines,
- this.source
- )
- .should.equal(true)
- })
- it('returns the doc', function () {
- return this.callback.calledWith(null, this.doc).should.equal(true)
- })
- describe('doc does not exist', function () {
- beforeEach(function () {
- this.ProjectEntityUpdateHandler.upsertDoc = sinon
- .stub()
- .yields(null, this.doc, true)
- return this.EditorController.upsertDoc(
- this.project_id,
- this.folder_id,
- this.docName,
- this.docLines,
- this.source,
- this.user_id,
- this.callback
- )
- })
- it('sends an update out to users in the project', function () {
- return this.EditorRealTimeController.emitToRoom
- .calledWith(
- this.project_id,
- 'reciveNewDoc',
- this.folder_id,
- this.doc,
- this.source,
- this.user_id
- )
- .should.equal(true)
- })
- })
- })
- describe('upsertFile', function () {
- beforeEach(function () {
- this.ProjectEntityUpdateHandler.upsertFile = sinon
- .stub()
- .yields(null, this.newFile, false, this.file)
- return this.EditorController.upsertFile(
- this.project_id,
- this.folder_id,
- this.fileName,
- this.fsPath,
- this.linkedFileData,
- this.source,
- this.user_id,
- this.callback
- )
- })
- it('upserts the file using the project entity handler', function () {
- return this.ProjectEntityUpdateHandler.upsertFile
- .calledWith(
- this.project_id,
- this.folder_id,
- this.fileName,
- this.fsPath,
- this.linkedFileData,
- this.user_id,
- this.source
- )
- .should.equal(true)
- })
- it('returns the file', function () {
- return this.callback.calledWith(null, this.newFile).should.equal(true)
- })
- describe('file does not exist', function () {
- beforeEach(function () {
- this.ProjectEntityUpdateHandler.upsertFile = sinon
- .stub()
- .yields(null, this.file, true)
- return this.EditorController.upsertFile(
- this.project_id,
- this.folder_id,
- this.fileName,
- this.fsPath,
- this.linkedFileData,
- this.source,
- this.user_id,
- this.callback
- )
- })
- it('should send the update out to users in the project', function () {
- return this.EditorRealTimeController.emitToRoom
- .calledWith(
- this.project_id,
- 'reciveNewFile',
- this.folder_id,
- this.file,
- this.source,
- this.linkedFileData,
- this.user_id
- )
- .should.equal(true)
- })
- })
- })
- describe('upsertDocWithPath', function () {
- beforeEach(function () {
- this.docPath = '/folder/doc'
- this.ProjectEntityUpdateHandler.upsertDocWithPath = sinon
- .stub()
- .yields(null, this.doc, false, [], this.folder)
- return this.EditorController.upsertDocWithPath(
- this.project_id,
- this.docPath,
- this.docLines,
- this.source,
- this.user_id,
- this.callback
- )
- })
- it('upserts the doc using the project entity handler', function () {
- return this.ProjectEntityUpdateHandler.upsertDocWithPath
- .calledWith(this.project_id, this.docPath, this.docLines, this.source)
- .should.equal(true)
- })
- describe('doc does not exist', function () {
- beforeEach(function () {
- this.ProjectEntityUpdateHandler.upsertDocWithPath = sinon
- .stub()
- .yields(null, this.doc, true, [], this.folder)
- return this.EditorController.upsertDocWithPath(
- this.project_id,
- this.docPath,
- this.docLines,
- this.source,
- this.user_id,
- this.callback
- )
- })
- it('should send the update for the doc out to users in the project', function () {
- return this.EditorRealTimeController.emitToRoom
- .calledWith(
- this.project_id,
- 'reciveNewDoc',
- this.folder_id,
- this.doc,
- this.source,
- this.user_id
- )
- .should.equal(true)
- })
- })
- describe('folders required for doc do not exist', function () {
- beforeEach(function () {
- const folders = [
- (this.folderA = { _id: 2, parentFolder_id: 1 }),
- (this.folderB = { _id: 3, parentFolder_id: 2 }),
- ]
- this.ProjectEntityUpdateHandler.upsertDocWithPath = sinon
- .stub()
- .yields(null, this.doc, true, folders, this.folderB)
- return this.EditorController.upsertDocWithPath(
- this.project_id,
- this.docPath,
- this.docLines,
- this.source,
- this.user_id,
- this.callback
- )
- })
- it('should send the update for each folder to users in the project', function () {
- this.EditorRealTimeController.emitToRoom
- .calledWith(
- this.project_id,
- 'reciveNewFolder',
- this.folderA.parentFolder_id,
- this.folderA
- )
- .should.equal(true)
- return this.EditorRealTimeController.emitToRoom
- .calledWith(
- this.project_id,
- 'reciveNewFolder',
- this.folderB.parentFolder_id,
- this.folderB
- )
- .should.equal(true)
- })
- })
- })
- describe('upsertFileWithPath', function () {
- beforeEach(function () {
- this.filePath = '/folder/file'
- this.ProjectEntityUpdateHandler.upsertFileWithPath = sinon
- .stub()
- .yields(null, this.newFile, false, this.file, [], this.folder)
- return this.EditorController.upsertFileWithPath(
- this.project_id,
- this.filePath,
- this.fsPath,
- this.linkedFileData,
- this.source,
- this.user_id,
- this.callback
- )
- })
- it('upserts the file using the project entity handler', function () {
- return this.ProjectEntityUpdateHandler.upsertFileWithPath
- .calledWith(
- this.project_id,
- this.filePath,
- this.fsPath,
- this.linkedFileData,
- this.user_id,
- this.source
- )
- .should.equal(true)
- })
- describe('file does not exist', function () {
- beforeEach(function () {
- this.ProjectEntityUpdateHandler.upsertFileWithPath = sinon
- .stub()
- .yields(null, this.file, true, undefined, [], this.folder)
- return this.EditorController.upsertFileWithPath(
- this.project_id,
- this.filePath,
- this.fsPath,
- this.linkedFileData,
- this.source,
- this.user_id,
- this.callback
- )
- })
- it('should send the update for the file out to users in the project', function () {
- return this.EditorRealTimeController.emitToRoom
- .calledWith(
- this.project_id,
- 'reciveNewFile',
- this.folder_id,
- this.file,
- this.source,
- this.linkedFileData,
- this.user_id
- )
- .should.equal(true)
- })
- })
- describe('folders required for file do not exist', function () {
- beforeEach(function () {
- const folders = [
- (this.folderA = { _id: 2, parentFolder_id: 1 }),
- (this.folderB = { _id: 3, parentFolder_id: 2 }),
- ]
- this.ProjectEntityUpdateHandler.upsertFileWithPath = sinon
- .stub()
- .yields(null, this.file, true, undefined, folders, this.folderB)
- return this.EditorController.upsertFileWithPath(
- this.project_id,
- this.filePath,
- this.fsPath,
- this.linkedFileData,
- this.source,
- this.user_id,
- this.callback
- )
- })
- it('should send the update for each folder to users in the project', function () {
- this.EditorRealTimeController.emitToRoom
- .calledWith(
- this.project_id,
- 'reciveNewFolder',
- this.folderA.parentFolder_id,
- this.folderA
- )
- .should.equal(true)
- return this.EditorRealTimeController.emitToRoom
- .calledWith(
- this.project_id,
- 'reciveNewFolder',
- this.folderB.parentFolder_id,
- this.folderB
- )
- .should.equal(true)
- })
- })
- })
- describe('addFolder', function () {
- beforeEach(function () {
- this.EditorController._notifyProjectUsersOfNewFolder = sinon
- .stub()
- .yields()
- this.ProjectEntityUpdateHandler.addFolder = sinon
- .stub()
- .yields(null, this.folder, this.folder_id)
- return this.EditorController.addFolder(
- this.project_id,
- this.folder_id,
- this.folderName,
- this.source,
- this.user_id,
- this.callback
- )
- })
- it('should add the folder using the project entity handler', function () {
- return this.ProjectEntityUpdateHandler.addFolder
- .calledWith(this.project_id, this.folder_id, this.folderName)
- .should.equal(true)
- })
- it('should notifyProjectUsersOfNewFolder', function () {
- return this.EditorController._notifyProjectUsersOfNewFolder
- .calledWith(this.project_id, this.folder_id, this.folder, this.user_id)
- .should.equal(true)
- })
- it('should return the folder in the callback', function () {
- return this.callback.calledWith(null, this.folder).should.equal(true)
- })
- })
- describe('mkdirp', function () {
- beforeEach(function () {
- this.path = 'folder1/folder2'
- this.folders = [
- (this.folderA = { _id: 2, parentFolder_id: 1 }),
- (this.folderB = { _id: 3, parentFolder_id: 2 }),
- ]
- this.EditorController._notifyProjectUsersOfNewFolders = sinon
- .stub()
- .yields()
- this.ProjectEntityUpdateHandler.mkdirp = sinon
- .stub()
- .yields(null, this.folders, this.folder)
- return this.EditorController.mkdirp(
- this.project_id,
- this.path,
- this.callback
- )
- })
- it('should create the folder using the project entity handler', function () {
- return this.ProjectEntityUpdateHandler.mkdirp
- .calledWith(this.project_id, this.path)
- .should.equal(true)
- })
- it('should notifyProjectUsersOfNewFolder', function () {
- return this.EditorController._notifyProjectUsersOfNewFolders.calledWith(
- this.project_id,
- this.folders
- )
- })
- it('should return the folder in the callback', function () {
- return this.callback
- .calledWith(null, this.folders, this.folder)
- .should.equal(true)
- })
- })
- describe('deleteEntity', function () {
- beforeEach(function () {
- this.entity_id = 'entity_id_here'
- this.type = 'doc'
- this.ProjectEntityUpdateHandler.deleteEntity = sinon.stub().yields()
- return this.EditorController.deleteEntity(
- this.project_id,
- this.entity_id,
- this.type,
- this.source,
- this.user_id,
- this.callback
- )
- })
- it('should delete the folder using the project entity handler', function () {
- return this.ProjectEntityUpdateHandler.deleteEntity
- .calledWith(
- this.project_id,
- this.entity_id,
- this.type,
- this.user_id,
- this.source
- )
- .should.equal(true)
- })
- it('notify users an entity has been deleted', function () {
- return this.EditorRealTimeController.emitToRoom
- .calledWith(
- this.project_id,
- 'removeEntity',
- this.entity_id,
- this.source
- )
- .should.equal(true)
- })
- })
- describe('deleteEntityWithPath', function () {
- beforeEach(function () {
- this.entity_id = 'entity_id_here'
- this.ProjectEntityUpdateHandler.deleteEntityWithPath = sinon
- .stub()
- .yields(null, this.entity_id)
- this.path = 'folder1/folder2'
- return this.EditorController.deleteEntityWithPath(
- this.project_id,
- this.path,
- this.source,
- this.user_id,
- this.callback
- )
- })
- it('should delete the folder using the project entity handler', function () {
- return this.ProjectEntityUpdateHandler.deleteEntityWithPath
- .calledWith(this.project_id, this.path, this.user_id, this.source)
- .should.equal(true)
- })
- it('notify users an entity has been deleted', function () {
- return this.EditorRealTimeController.emitToRoom
- .calledWith(
- this.project_id,
- 'removeEntity',
- this.entity_id,
- this.source
- )
- .should.equal(true)
- })
- })
- describe('updateProjectDescription', function () {
- beforeEach(function () {
- this.description = 'new description'
- return this.EditorController.updateProjectDescription(
- this.project_id,
- this.description,
- this.callback
- )
- })
- it('should send the new description to the project details handler', function () {
- return this.ProjectDetailsHandler.setProjectDescription
- .calledWith(this.project_id, this.description)
- .should.equal(true)
- })
- it('should notify the other clients about the updated description', function () {
- return this.EditorRealTimeController.emitToRoom
- .calledWith(
- this.project_id,
- 'projectDescriptionUpdated',
- this.description
- )
- .should.equal(true)
- })
- })
- describe('deleteProject', function () {
- beforeEach(function () {
- this.err = 'errro'
- return (this.ProjectDeleter.deleteProject = sinon
- .stub()
- .callsArgWith(1, this.err))
- })
- it('should call the project handler', function (done) {
- return this.EditorController.deleteProject(this.project_id, err => {
- err.should.equal(this.err)
- this.ProjectDeleter.deleteProject
- .calledWith(this.project_id)
- .should.equal(true)
- return done()
- })
- })
- })
- describe('renameEntity', function () {
- beforeEach(function (done) {
- this.entity_id = 'entity_id_here'
- this.entityType = 'doc'
- this.newName = 'bobsfile.tex'
- this.ProjectEntityUpdateHandler.renameEntity = sinon.stub().yields()
- return this.EditorController.renameEntity(
- this.project_id,
- this.entity_id,
- this.entityType,
- this.newName,
- this.user_id,
- this.source,
- done
- )
- })
- it('should call the project handler', function () {
- return this.ProjectEntityUpdateHandler.renameEntity
- .calledWith(
- this.project_id,
- this.entity_id,
- this.entityType,
- this.newName,
- this.user_id,
- this.source
- )
- .should.equal(true)
- })
- it('should emit the update to the room', function () {
- return this.EditorRealTimeController.emitToRoom
- .calledWith(
- this.project_id,
- 'reciveEntityRename',
- this.entity_id,
- this.newName
- )
- .should.equal(true)
- })
- })
- describe('moveEntity', function () {
- beforeEach(function () {
- this.entity_id = 'entity_id_here'
- this.entityType = 'doc'
- this.ProjectEntityUpdateHandler.moveEntity = sinon.stub().yields()
- return this.EditorController.moveEntity(
- this.project_id,
- this.entity_id,
- this.folder_id,
- this.entityType,
- this.user_id,
- this.source,
- this.callback
- )
- })
- it('should call the ProjectEntityUpdateHandler', function () {
- return this.ProjectEntityUpdateHandler.moveEntity
- .calledWith(
- this.project_id,
- this.entity_id,
- this.folder_id,
- this.entityType,
- this.user_id,
- this.source
- )
- .should.equal(true)
- })
- it('should emit the update to the room', function () {
- return this.EditorRealTimeController.emitToRoom
- .calledWith(
- this.project_id,
- 'reciveEntityMove',
- this.entity_id,
- this.folder_id
- )
- .should.equal(true)
- })
- it('calls the callback', function () {
- return this.callback.called.should.equal(true)
- })
- })
- describe('renameProject', function () {
- beforeEach(function () {
- this.err = 'errro'
- this.newName = 'new name here'
- return this.EditorController.renameProject(
- this.project_id,
- this.newName,
- this.callback
- )
- })
- it('should call the EditorController', function () {
- return this.ProjectDetailsHandler.renameProject
- .calledWith(this.project_id, this.newName)
- .should.equal(true)
- })
- it('should emit the update to the room', function () {
- return this.EditorRealTimeController.emitToRoom
- .calledWith(this.project_id, 'projectNameUpdated', this.newName)
- .should.equal(true)
- })
- })
- describe('setCompiler', function () {
- beforeEach(function () {
- this.compiler = 'latex'
- return this.EditorController.setCompiler(
- this.project_id,
- this.compiler,
- this.callback
- )
- })
- it('should send the new compiler and project id to the project options handler', function () {
- this.ProjectOptionsHandler.setCompiler
- .calledWith(this.project_id, this.compiler)
- .should.equal(true)
- return this.EditorRealTimeController.emitToRoom
- .calledWith(this.project_id, 'compilerUpdated', this.compiler)
- .should.equal(true)
- })
- })
- describe('setImageName', function () {
- beforeEach(function () {
- this.imageName = 'texlive-1234.5'
- return this.EditorController.setImageName(
- this.project_id,
- this.imageName,
- this.callback
- )
- })
- it('should send the new imageName and project id to the project options handler', function () {
- this.ProjectOptionsHandler.setImageName
- .calledWith(this.project_id, this.imageName)
- .should.equal(true)
- return this.EditorRealTimeController.emitToRoom
- .calledWith(this.project_id, 'imageNameUpdated', this.imageName)
- .should.equal(true)
- })
- })
- describe('setSpellCheckLanguage', function () {
- beforeEach(function () {
- this.languageCode = 'fr'
- return this.EditorController.setSpellCheckLanguage(
- this.project_id,
- this.languageCode,
- this.callback
- )
- })
- it('should send the new languageCode and project id to the project options handler', function () {
- this.ProjectOptionsHandler.setSpellCheckLanguage
- .calledWith(this.project_id, this.languageCode)
- .should.equal(true)
- return this.EditorRealTimeController.emitToRoom
- .calledWith(
- this.project_id,
- 'spellCheckLanguageUpdated',
- this.languageCode
- )
- .should.equal(true)
- })
- })
- describe('setPublicAccessLevel', function () {
- describe('when setting to private', function () {
- beforeEach(function () {
- this.newAccessLevel = 'private'
- this.ProjectDetailsHandler.ensureTokensArePresent = sinon
- .stub()
- .yields()
- return this.EditorController.setPublicAccessLevel(
- this.project_id,
- this.newAccessLevel,
- this.callback
- )
- })
- it('should set the access level', function () {
- return this.ProjectDetailsHandler.setPublicAccessLevel
- .calledWith(this.project_id, this.newAccessLevel)
- .should.equal(true)
- })
- it('should broadcast the access level change', function () {
- return this.EditorRealTimeController.emitToRoom
- .calledWith(this.project_id, 'project:publicAccessLevel:changed')
- .should.equal(true)
- })
- it('should not ensure tokens are present for project', function () {
- return this.ProjectDetailsHandler.ensureTokensArePresent
- .calledWith(this.project_id)
- .should.equal(false)
- })
- })
- describe('when setting to tokenBased', function () {
- beforeEach(function () {
- this.newAccessLevel = 'tokenBased'
- this.tokens = { readOnly: 'aaa', readAndWrite: '42bbb' }
- this.ProjectDetailsHandler.ensureTokensArePresent = sinon
- .stub()
- .yields()
- return this.EditorController.setPublicAccessLevel(
- this.project_id,
- this.newAccessLevel,
- this.callback
- )
- })
- it('should set the access level', function () {
- return this.ProjectDetailsHandler.setPublicAccessLevel
- .calledWith(this.project_id, this.newAccessLevel)
- .should.equal(true)
- })
- it('should broadcast the access level change', function () {
- return this.EditorRealTimeController.emitToRoom
- .calledWith(this.project_id, 'project:publicAccessLevel:changed')
- .should.equal(true)
- })
- it('should ensure tokens are present for project', function () {
- return this.ProjectDetailsHandler.ensureTokensArePresent
- .calledWith(this.project_id)
- .should.equal(true)
- })
- })
- })
- describe('setRootDoc', function () {
- beforeEach(function () {
- this.newRootDocID = '21312321321'
- this.ProjectEntityUpdateHandler.setRootDoc = sinon.stub().yields()
- return this.EditorController.setRootDoc(
- this.project_id,
- this.newRootDocID,
- this.callback
- )
- })
- it('should call the ProjectEntityUpdateHandler', function () {
- return this.ProjectEntityUpdateHandler.setRootDoc
- .calledWith(this.project_id, this.newRootDocID)
- .should.equal(true)
- })
- it('should emit the update to the room', function () {
- return this.EditorRealTimeController.emitToRoom
- .calledWith(this.project_id, 'rootDocUpdated', this.newRootDocID)
- .should.equal(true)
- })
- })
- describe('setMainBibliographyDoc', function () {
- describe('on success', function () {
- beforeEach(function (done) {
- this.mainBibliographyId = 'bib-doc-id'
- this.ProjectEntityUpdateHandler.setMainBibliographyDoc = sinon
- .stub()
- .yields()
- this.callback = sinon.stub().callsFake(done)
- this.EditorController.setMainBibliographyDoc(
- this.project_id,
- this.mainBibliographyId,
- this.callback
- )
- })
- it('should forward the call to the ProjectEntityUpdateHandler', function () {
- expect(
- this.ProjectEntityUpdateHandler.setMainBibliographyDoc
- ).to.have.been.calledWith(this.project_id, this.mainBibliographyId)
- })
- it('should emit the update to the room', function () {
- expect(
- this.EditorRealTimeController.emitToRoom
- ).to.have.been.calledWith(
- this.project_id,
- 'mainBibliographyDocUpdated',
- this.mainBibliographyId
- )
- })
- it('should return nothing', function () {
- expect(this.callback).to.have.been.calledWithExactly()
- })
- })
- describe('on error', function () {
- beforeEach(function (done) {
- this.mainBibliographyId = 'bib-doc-id'
- this.error = new Error('oh no')
- this.ProjectEntityUpdateHandler.setMainBibliographyDoc = sinon
- .stub()
- .yields(this.error)
- this.callback = sinon.stub().callsFake(() => done())
- this.EditorController.setMainBibliographyDoc(
- this.project_id,
- this.mainBibliographyId,
- this.callback
- )
- })
- it('should forward the call to the ProjectEntityUpdateHandler', function () {
- expect(
- this.ProjectEntityUpdateHandler.setMainBibliographyDoc
- ).to.have.been.calledWith(this.project_id, this.mainBibliographyId)
- })
- it('should return the error', function () {
- expect(this.callback).to.have.been.calledWithExactly(this.error)
- })
- it('should not emit the update to the room', function () {
- expect(this.EditorRealTimeController.emitToRoom).to.not.have.been.called
- })
- })
- })
- describe('appendToDoc', function () {
- describe('on success', function () {
- beforeEach(function () {
- this.docId = 'doc-1'
- this.ProjectEntityUpdateHandler.appendToDoc = sinon
- .stub()
- .yields(null, { rev: '1' })
- this.EditorController.appendToDoc(
- this.project_id,
- this.docId,
- this.docLines,
- this.source,
- this.user_id,
- this.callback
- )
- })
- it('appends to the doc using the project entity handler', function () {
- this.ProjectEntityUpdateHandler.appendToDoc
- .calledWith(this.project_id, this.docId, this.docLines, this.source)
- .should.equal(true)
- })
- })
- describe('on error', function () {
- beforeEach(function () {
- this.docId = 'doc-1'
- this.ProjectEntityUpdateHandler.appendToDoc = sinon
- .stub()
- .yields(new Error('foo'))
- this.EditorController.appendToDoc(
- this.project_id,
- this.docId,
- this.docLines,
- this.source,
- this.user_id,
- this.callback
- )
- })
- it('tries to append to the doc using the project entity handler', function () {
- this.ProjectEntityUpdateHandler.appendToDoc
- .calledWith(this.project_id, this.docId, this.docLines, this.source)
- .should.equal(true)
- })
- it('tags the error', function () {
- this.callback.calledWith(sinon.match.instanceOf(OError))
- })
- })
- })
- })
|