move project duplicator to mongojs

This commit is contained in:
Henry Oswald 2016-02-26 08:32:00 +00:00
parent 6ca69f88ac
commit eedaa43b58
2 changed files with 7 additions and 2 deletions

View file

@ -4,6 +4,7 @@ projectLocator = require('./ProjectLocator')
projectOptionsHandler = require('./ProjectOptionsHandler') projectOptionsHandler = require('./ProjectOptionsHandler')
DocumentUpdaterHandler = require("../DocumentUpdater/DocumentUpdaterHandler") DocumentUpdaterHandler = require("../DocumentUpdater/DocumentUpdaterHandler")
DocstoreManager = require "../Docstore/DocstoreManager" DocstoreManager = require "../Docstore/DocstoreManager"
ProjectGetter = require("./ProjectGetter")
Project = require("../../models/Project").Project Project = require("../../models/Project").Project
_ = require('underscore') _ = require('underscore')
async = require('async') async = require('async')
@ -12,7 +13,7 @@ module.exports =
duplicate: (owner, originalProjectId, newProjectName, callback)-> duplicate: (owner, originalProjectId, newProjectName, callback)->
DocumentUpdaterHandler.flushProjectToMongo originalProjectId, (err) -> DocumentUpdaterHandler.flushProjectToMongo originalProjectId, (err) ->
return callback(err) if err? return callback(err) if err?
Project.findById originalProjectId, (err, originalProject) -> ProjectGetter.getProject originalProjectId, (err, originalProject) ->
return callback(err) if err? return callback(err) if err?
projectCreationHandler.createBlankProject owner._id, newProjectName, (err, newProject)-> projectCreationHandler.createBlankProject owner._id, newProjectName, (err, newProject)->
return callback(err) if err? return callback(err) if err?

View file

@ -75,6 +75,9 @@ describe 'ProjectDuplicator', ->
@Project = @Project =
findById: sinon.stub().callsArgWith(1, null, @project) findById: sinon.stub().callsArgWith(1, null, @project)
@ProjectGetter =
getProject: sinon.stub().callsArgWith(1, null, @project)
@duplicator = SandboxedModule.require modulePath, requires: @duplicator = SandboxedModule.require modulePath, requires:
'../../models/Project':{Project:@Project} '../../models/Project':{Project:@Project}
"../DocumentUpdater/DocumentUpdaterHandler": @DocumentUpdaterHandler "../DocumentUpdater/DocumentUpdaterHandler": @DocumentUpdaterHandler
@ -83,12 +86,13 @@ describe 'ProjectDuplicator', ->
'./ProjectLocator': @locator './ProjectLocator': @locator
'./ProjectOptionsHandler': @projectOptionsHandler './ProjectOptionsHandler': @projectOptionsHandler
"../Docstore/DocstoreManager": @DocstoreManager "../Docstore/DocstoreManager": @DocstoreManager
"./ProjectGetter":@ProjectGetter
'logger-sharelatex':{log:->} 'logger-sharelatex':{log:->}
it "should look up the original project", (done) -> it "should look up the original project", (done) ->
newProjectName = "someProj" newProjectName = "someProj"
@duplicator.duplicate @owner, @project_id, newProjectName, (err, newProject)=> @duplicator.duplicate @owner, @project_id, newProjectName, (err, newProject)=>
@Project.findById.calledWith(@project_id).should.equal true @ProjectGetter.getProject.calledWith(@project_id).should.equal true
done() done()
it "should flush the original project to mongo", (done) -> it "should flush the original project to mongo", (done) ->