mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-30 05:15:20 -05:00
allow overleafId to be passed in to avoid history initialization
This commit is contained in:
parent
670b183c8e
commit
20ea9918c9
2 changed files with 37 additions and 23 deletions
|
@ -15,19 +15,28 @@ _ = require "underscore"
|
|||
|
||||
module.exports = ProjectCreationHandler =
|
||||
|
||||
createBlankProject : (owner_id, projectName, callback = (error, project) ->)->
|
||||
createBlankProject : (owner_id, projectName, overleafId, callback = (error, project) ->)->
|
||||
metrics.inc("project-creation")
|
||||
if arguments.length == 3
|
||||
callback = overleafId
|
||||
overleafId = null
|
||||
|
||||
ProjectDetailsHandler.validateProjectName projectName, (error) ->
|
||||
return callback(error) if error?
|
||||
logger.log owner_id:owner_id, projectName:projectName, "creating blank project"
|
||||
if overleafId?
|
||||
ProjectCreationHandler._createBlankProject owner_id, projectName, overleafId, callback
|
||||
else
|
||||
HistoryController.initializeProject (error, history) ->
|
||||
return callback(error) if error?
|
||||
ProjectCreationHandler._createBlankProject owner_id, projectName, history.overleaf_id, callback
|
||||
|
||||
_createBlankProject : (owner_id, projectName, overleafId, callback = (error, project) ->)->
|
||||
rootFolder = new Folder {'name':'rootFolder'}
|
||||
project = new Project
|
||||
owner_ref : new ObjectId(owner_id)
|
||||
name : projectName
|
||||
if history?.overleaf_id?
|
||||
project.overleaf.id = history.overleaf_id
|
||||
project.overleaf.id = overleafId
|
||||
if Settings.currentImageName?
|
||||
project.imageName = Settings.currentImageName
|
||||
project.rootFolder[0] = rootFolder
|
||||
|
|
|
@ -64,10 +64,11 @@ describe 'ProjectCreationHandler', ->
|
|||
|
||||
describe 'Creating a Blank project', ->
|
||||
beforeEach ->
|
||||
@overleaf_id = 1234
|
||||
@HistoryController.initializeProject = sinon.stub().callsArgWith(0, null, { @overleaf_id })
|
||||
@ProjectModel::save = sinon.stub().callsArg(0)
|
||||
|
||||
describe "successfully", ->
|
||||
|
||||
it "should save the project", (done)->
|
||||
@handler.createBlankProject ownerId, projectName, =>
|
||||
@ProjectModel::save.called.should.equal true
|
||||
|
@ -79,14 +80,18 @@ describe 'ProjectCreationHandler', ->
|
|||
(project.owner_ref + "").should.equal ownerId
|
||||
done()
|
||||
|
||||
it "should initialize the project history", (done)->
|
||||
it "should initialize the project overleaf if history id not provided", (done)->
|
||||
@handler.createBlankProject ownerId, projectName, done
|
||||
@HistoryController.initializeProject.calledWith().should.equal true
|
||||
|
||||
it "should set the overleaf id", (done)->
|
||||
overleaf_id = 1234
|
||||
@HistoryController.initializeProject = sinon.stub().callsArgWith(0, null, { overleaf_id })
|
||||
@handler.createBlankProject ownerId, projectName, (err, project)->
|
||||
it "should set the overleaf id if overleaf id not provided", (done)->
|
||||
@handler.createBlankProject ownerId, projectName, (err, project)=>
|
||||
project.overleaf.id.should.equal @overleaf_id
|
||||
done()
|
||||
|
||||
it "should set the overleaf id if overleaf id provided", (done)->
|
||||
overleaf_id = 2345
|
||||
@handler.createBlankProject ownerId, projectName, overleaf_id, (err, project)->
|
||||
project.overleaf.id.should.equal overleaf_id
|
||||
done()
|
||||
|
||||
|
|
Loading…
Reference in a new issue