Fix tests

This commit is contained in:
James Allen 2018-02-20 12:52:57 +00:00
parent 6848e97a82
commit cae09028ff
8 changed files with 42 additions and 33 deletions

View file

@ -18,6 +18,7 @@ describe "EditorController", ->
@file = _id: @file_id ="dasdkjk"
@fileName = "file.png"
@fsPath = "/folder/file.png"
@linkedFileData = {provider: 'url'}
@folder_id = "123ksajdn"
@folder = _id: @folder_id
@ -66,16 +67,16 @@ describe "EditorController", ->
describe 'addFile', ->
beforeEach ->
@ProjectEntityUpdateHandler.addFile = sinon.stub().yields(null, @file, @folder_id)
@EditorController.addFile @project_id, @folder_id, @fileName, @fsPath, @source, @user_id, @callback
@EditorController.addFile @project_id, @folder_id, @fileName, @fsPath, @linkedFileData, @source, @user_id, @callback
it 'should add the folder using the project entity handler', ->
@ProjectEntityUpdateHandler.addFile
.calledWith(@project_id, @folder_id, @fileName, @fsPath, @user_id)
.calledWith(@project_id, @folder_id, @fileName, @fsPath, @linkedFileData, @user_id)
.should.equal true
it 'should send the update of a new folder out to the users in the project', ->
@EditorRealTimeController.emitToRoom
.calledWith(@project_id, "reciveNewFile", @folder_id, @file, @source)
.calledWith(@project_id, "reciveNewFile", @folder_id, @file, @source, @linkedFileData)
.should.equal true
it 'calls the callback', ->
@ -107,11 +108,11 @@ describe "EditorController", ->
describe 'upsertFile', ->
beforeEach ->
@ProjectEntityUpdateHandler.upsertFile = sinon.stub().yields(null, @file, false)
@EditorController.upsertFile @project_id, @folder_id, @fileName, @fsPath, @source, @user_id, @callback
@EditorController.upsertFile @project_id, @folder_id, @fileName, @fsPath, @linkedFileData, @source, @user_id, @callback
it 'upserts the file using the project entity handler', ->
@ProjectEntityUpdateHandler.upsertFile
.calledWith(@project_id, @folder_id, @fileName, @fsPath, @user_id)
.calledWith(@project_id, @folder_id, @fileName, @fsPath, @linkedFileData, @user_id)
.should.equal true
it 'returns the file', ->
@ -120,11 +121,11 @@ describe "EditorController", ->
describe 'file does not exist', ->
beforeEach ->
@ProjectEntityUpdateHandler.upsertFile = sinon.stub().yields(null, @file, true)
@EditorController.upsertFile @project_id, @folder_id, @fileName, @fsPath, @source, @user_id, @callback
@EditorController.upsertFile @project_id, @folder_id, @fileName, @fsPath, @linkedFileData, @source, @user_id, @callback
it 'should send the update out to users in the project', ->
@EditorRealTimeController.emitToRoom
.calledWith(@project_id, "reciveNewFile", @folder_id, @file, @source)
.calledWith(@project_id, "reciveNewFile", @folder_id, @file, @source, @linkedFileData)
.should.equal true
describe "upsertDocWithPath", ->
@ -171,21 +172,21 @@ describe "EditorController", ->
@filePath = '/folder/file'
@ProjectEntityUpdateHandler.upsertFileWithPath = sinon.stub().yields(null, @file, false, [], @folder)
@EditorController.upsertFileWithPath @project_id, @filePath, @fsPath, @source, @user_id, @callback
@EditorController.upsertFileWithPath @project_id, @filePath, @fsPath, @linkedFileData, @source, @user_id, @callback
it 'upserts the file using the project entity handler', ->
@ProjectEntityUpdateHandler.upsertFileWithPath
.calledWith(@project_id, @filePath, @fsPath)
.calledWith(@project_id, @filePath, @fsPath, @linkedFileData)
.should.equal true
describe 'file does not exist', ->
beforeEach ->
@ProjectEntityUpdateHandler.upsertFileWithPath = sinon.stub().yields(null, @file, true, [], @folder)
@EditorController.upsertFileWithPath @project_id, @filePath, @fsPath, @source, @user_id, @callback
@EditorController.upsertFileWithPath @project_id, @filePath, @fsPath, @linkedFileData, @source, @user_id, @callback
it 'should send the update for the file out to users in the project', ->
@EditorRealTimeController.emitToRoom
.calledWith(@project_id, "reciveNewFile", @folder_id, @file, @source)
.calledWith(@project_id, "reciveNewFile", @folder_id, @file, @source, @linkedFileData)
.should.equal true
describe 'folders required for file do not exist', ->
@ -195,7 +196,7 @@ describe "EditorController", ->
@folderB = { _id: 3, parentFolder_id: 2}
]
@ProjectEntityUpdateHandler.upsertFileWithPath = sinon.stub().yields(null, @file, true, folders, @folderB)
@EditorController.upsertFileWithPath @project_id, @filePath, @fsPath, @source, @user_id, @callback
@EditorController.upsertFileWithPath @project_id, @filePath, @fsPath, @linkedFileData, @source, @user_id, @callback
it 'should send the update for each folder to users in the project', ->
@EditorRealTimeController.emitToRoom

View file

@ -34,7 +34,7 @@ describe 'ProjectCreationHandler', ->
{@name} = options
@ProjectEntityUpdateHandler =
addDoc: sinon.stub().callsArgWith(5, null, {_id: docId})
addFile: sinon.stub().callsArg(5)
addFile: sinon.stub().callsArg(6)
setRootDoc: sinon.stub().callsArg(2)
@ProjectDetailsHandler =
validateProjectName: sinon.stub().yields()
@ -208,6 +208,7 @@ describe 'ProjectCreationHandler', ->
.calledWith(
project_id, rootFolderId, "universe.jpg",
Path.resolve(__dirname + "/../../../../app/templates/project_files/universe.jpg"),
null,
ownerId
)
.should.equal true

View file

@ -33,7 +33,7 @@ describe "ProjectEditorHandler", ->
fileRefs : [{
_id : "file-id"
name : "image.png"
created : new Date()
created : @created = new Date()
size : 1234
}]
folders : []
@ -141,7 +141,7 @@ describe "ProjectEditorHandler", ->
it "should include files in the project", ->
@result.rootFolder[0].folders[0].fileRefs[0]._id.should.equal "file-id"
@result.rootFolder[0].folders[0].fileRefs[0].name.should.equal "image.png"
should.not.exist @result.rootFolder[0].folders[0].fileRefs[0].created
@result.rootFolder[0].folders[0].fileRefs[0].created.should.equal @created
should.not.exist @result.rootFolder[0].folders[0].fileRefs[0].size
it "should include docs in the project but not the lines", ->

View file

@ -97,10 +97,11 @@ describe 'ProjectEntityMongoUpdateHandler', ->
beforeEach ->
@file = _id: file_id
@path = mongo: 'file.png'
@linkedFileData = {provider: 'url'}
@ProjectLocator.findElement = sinon.stub().yields(null, @file, @path)
@ProjectModel.update = sinon.stub().yields()
@subject.replaceFile project_id, file_id, @callback
@subject.replaceFile project_id, file_id, @linkedFileData, @callback
it 'gets the project', ->
@ProjectGetter.getProjectWithoutLock
@ -118,7 +119,7 @@ describe 'ProjectEntityMongoUpdateHandler', ->
{ _id: project_id },
{
'$inc': { 'file.png.rev': 1, 'version': 1 }
'$set': { 'file.png.created': new Date() }
'$set': { 'file.png.created': new Date(), 'file.png.linkedFileData': @linkedFileData }
}
{}
)

View file

@ -40,6 +40,8 @@ describe 'ProjectEntityUpdateHandler', ->
@fileName = "something.jpg"
@fileSystemPath = "somehintg"
@linkedFileData = {provider: 'url'}
@source = 'editor'
@callback = sinon.stub()
@ProjectEntityUpdateHandler = SandboxedModule.require modulePath, requires:
@ -296,11 +298,11 @@ describe 'ProjectEntityUpdateHandler', ->
@newFile = _id: file_id
@ProjectEntityUpdateHandler.addFileWithoutUpdatingHistory =
withoutLock: sinon.stub().yields(null, @newFile, folder_id, @path, @fileUrl)
@ProjectEntityUpdateHandler.addFile project_id, folder_id, @docName, @fileSystemPath, userId, @callback
@ProjectEntityUpdateHandler.addFile project_id, folder_id, @docName, @fileSystemPath, @linkedFileData, userId, @callback
it "creates the doc without history", () ->
@ProjectEntityUpdateHandler.addFileWithoutUpdatingHistory.withoutLock
.calledWith(project_id, folder_id, @docName, @fileSystemPath, userId)
.calledWith(project_id, folder_id, @docName, @fileSystemPath, @linkedFileData, userId)
.should.equal true
it "sends the change in project structure to the doc updater", () ->
@ -320,7 +322,7 @@ describe 'ProjectEntityUpdateHandler', ->
@project = _id: project_id, name: 'some project'
@ProjectEntityMongoUpdateHandler.replaceFile = sinon.stub().yields(null, @newFile, @project, fileSystem: @path)
@ProjectEntityUpdateHandler.replaceFile project_id, file_id, @fileSystemPath, userId, @callback
@ProjectEntityUpdateHandler.replaceFile project_id, file_id, @fileSystemPath, @linkedFileData, userId, @callback
it 'uploads a new version of the file', ->
@FileStoreHandler.uploadFileFromDisk
@ -329,7 +331,7 @@ describe 'ProjectEntityUpdateHandler', ->
it 'replaces the file in mongo', ->
@ProjectEntityMongoUpdateHandler.replaceFile
.calledWith(project_id, file_id)
.calledWith(project_id, file_id, @linkedFileData)
.should.equal true
it 'notifies the tpds', ->
@ -497,7 +499,7 @@ describe 'ProjectEntityUpdateHandler', ->
describe 'upserting into an invalid folder', ->
beforeEach ->
@ProjectLocator.findElement = sinon.stub().yields()
@ProjectEntityUpdateHandler.upsertFile project_id, folder_id, @fileName, @fileSystemPath, userId, @callback
@ProjectEntityUpdateHandler.upsertFile project_id, folder_id, @fileName, @fileSystemPath, @linkedFileData, userId, @callback
it 'returns an error', ->
errorMatcher = sinon.match.instanceOf(Error)
@ -511,11 +513,11 @@ describe 'ProjectEntityUpdateHandler', ->
@ProjectLocator.findElement = sinon.stub().yields(null, @folder)
@ProjectEntityUpdateHandler.replaceFile = withoutLock: sinon.stub().yields(null, @newFile)
@ProjectEntityUpdateHandler.upsertFile project_id, folder_id, @fileName, @fileSystemPath, userId, @callback
@ProjectEntityUpdateHandler.upsertFile project_id, folder_id, @fileName, @fileSystemPath, @linkedFileData, userId, @callback
it 'replaces the file', ->
@ProjectEntityUpdateHandler.replaceFile.withoutLock
.calledWith(project_id, file_id, @fileSystemPath, userId)
.calledWith(project_id, file_id, @fileSystemPath, @linkedFileData, userId)
.should.equal true
it 'returns the file', ->
@ -528,7 +530,7 @@ describe 'ProjectEntityUpdateHandler', ->
@ProjectLocator.findElement = sinon.stub().yields(null, @folder)
@ProjectEntityUpdateHandler.addFile = withoutLock: sinon.stub().yields(null, @newFile)
@ProjectEntityUpdateHandler.upsertFile project_id, folder_id, @fileName, @fileSystemPath, userId, @callback
@ProjectEntityUpdateHandler.upsertFile project_id, folder_id, @fileName, @fileSystemPath, @linkedFileData, userId, @callback
it 'tries to find the folder', ->
@ProjectLocator.findElement
@ -537,7 +539,7 @@ describe 'ProjectEntityUpdateHandler', ->
it 'adds the file', ->
@ProjectEntityUpdateHandler.addFile.withoutLock
.calledWith(project_id, folder_id, @fileName, @fileSystemPath, userId)
.calledWith(project_id, folder_id, @fileName, @fileSystemPath, @linkedFileData, userId)
.should.equal true
it 'returns the file', ->
@ -584,7 +586,7 @@ describe 'ProjectEntityUpdateHandler', ->
@ProjectEntityUpdateHandler.upsertFile =
withoutLock: sinon.stub().yields(null, @file, @isNewFile)
@ProjectEntityUpdateHandler.upsertFileWithPath project_id, @path, @fileSystemPath, userId, @callback
@ProjectEntityUpdateHandler.upsertFileWithPath project_id, @path, @fileSystemPath, @linkedFileData, userId, @callback
it 'creates any necessary folders', ->
@ProjectEntityUpdateHandler.mkdirp.withoutLock
@ -593,7 +595,7 @@ describe 'ProjectEntityUpdateHandler', ->
it 'upserts the file', ->
@ProjectEntityUpdateHandler.upsertFile.withoutLock
.calledWith(project_id, @folder._id, 'file.png', @fileSystemPath, userId)
.calledWith(project_id, @folder._id, 'file.png', @fileSystemPath, @linkedFileData, userId)
.should.equal true
it 'calls the callback', ->

View file

@ -74,6 +74,7 @@ describe "SubscriptionController", ->
"settings-sharelatex": @settings
"./SubscriptionDomainHandler":@SubscriptionDomainHandler
"../User/UserGetter": @UserGetter
"./RecurlyWrapper": @RecurlyWrapper = {}
@res = new MockResponse()
@ -117,6 +118,7 @@ describe "SubscriptionController", ->
describe "paymentPage", ->
beforeEach ->
@req.headers = {}
@RecurlyWrapper.sign = sinon.stub().yields(null, @signature = "signature")
@SubscriptionHandler.validateNoSubscriptionInRecurly = sinon.stub().yields(null, true)
@GeoIpLookup.getCurrencyCode.callsArgWith(1, null, @stubbedCurrencyCode)

View file

@ -15,18 +15,20 @@ describe 'UpdateMerger :', ->
err: ->
'../Editor/EditorController': @EditorController = {}
'../Uploads/FileTypeManager':@FileTypeManager = {}
'../../infrastructure/FileWriter': @FileWriter = {}
'settings-sharelatex':{path:{dumpPath:"dump_here"}}
@project_id = "project_id_here"
@user_id = "mock-user-id"
@docPath = "/folder/doc.tex"
@filePath = "/folder/file.png"
@linkedFileData = {provider: 'url'}
@fsPath = "/tmp/file/path"
@source = "dropbox"
@updateRequest = new BufferedStream()
@updateMerger.p.writeStreamToDisk = sinon.stub().yields(null, @fsPath)
@FileWriter.writeStreamToDisk = sinon.stub().yields(null, @fsPath)
@callback = sinon.stub()
describe 'mergeUpdate', ->
@ -94,5 +96,5 @@ describe 'UpdateMerger :', ->
it 'should upsert the file in the editor controller', ->
@EditorController.upsertFileWithPath
.calledWith(@project_id, @filePath, @fsPath, @source, @user_id)
.calledWith(@project_id, @filePath, @fsPath, null, @source, @user_id)
.should.equal true

View file

@ -78,12 +78,12 @@ describe "FileSystemImportManager", ->
describe "addFile with replace set to false", ->
beforeEach ->
@EditorController.addFile = sinon.stub().callsArg(6)
@EditorController.addFile = sinon.stub().yields()
@FileSystemImportManager._isSafeOnFileSystem = sinon.stub().callsArgWith(1, null, true)
@FileSystemImportManager.addFile @user_id, @project_id, @folder_id, @name, @path_on_disk, false, @callback
it "should add the file", ->
@EditorController.addFile.calledWith(@project_id, @folder_id, @name, @path_on_disk, "upload", @user_id)
@EditorController.addFile.calledWith(@project_id, @folder_id, @name, @path_on_disk, null, "upload", @user_id)
.should.equal true
describe "addFile with symlink", ->
@ -105,7 +105,7 @@ describe "FileSystemImportManager", ->
it "should add the file", ->
@EditorController.upsertFile
.calledWith(@project_id, @folder_id, @name, @path_on_disk, "upload", @user_id)
.calledWith(@project_id, @folder_id, @name, @path_on_disk, null, "upload", @user_id)
.should.equal true
describe "addFolder", ->