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

View file

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