Don't error if the rootDoc_id no longer exists in the project when copying

This commit is contained in:
James Allen 2016-05-23 14:58:28 +01:00
parent a24f635531
commit 887631e661
3 changed files with 15 additions and 2 deletions

View file

@ -75,7 +75,7 @@ module.exports = ProjectDuplicator =
return callback(err)
{originalProject, newProject, originalRootDoc, docContentsArray} = results
originalRootDoc = originalRootDoc[0]
originalRootDoc = originalRootDoc?[0]
docContents = {}
for docContent in docContentsArray

View file

@ -61,7 +61,13 @@ module.exports = ProjectLocator =
findRootDoc : (opts, callback)->
getRootDoc = (project)=>
if project.rootDoc_id?
@findElement {project:project, element_id:project.rootDoc_id, type:"docs"}, callback
@findElement {project:project, element_id:project.rootDoc_id, type:"docs"}, (error, args...) ->
if error?
if error instanceof Errors.NotFoundError
return callback null, null
else
return callback error
return callback null, args...
else
callback null, null
{project, project_id} = opts

View file

@ -169,6 +169,13 @@ describe 'ProjectLocator', ->
assert !err?
expect(doc).to.equal null
done()
it 'should return null when the rootDoc_id no longer exists', (done) ->
project.rootDoc_id = "doesntexist"
@locator.findRootDoc project, (err, doc)->
assert !err?
expect(doc).to.equal null
done()
describe 'findElementByPath', ->