fix DocumentUpdaterHandler.updateProjectStructure

This commit is contained in:
Hayden Faulds 2017-11-15 15:12:59 +00:00
parent 62f88402e8
commit bfd22899a0
2 changed files with 22 additions and 11 deletions

View file

@ -236,26 +236,22 @@ module.exports = DocumentUpdaterHandler =
oldEntitiesHash = _.indexBy oldEntities, (entity) -> entity[entityType]._id.toString()
newEntitiesHash = _.indexBy newEntities, (entity) -> entity[entityType]._id.toString()
for id, oldEntity of oldEntitiesHash
newEntity = newEntitiesHash[id]
# renamed entities
if newEntity.path != oldEntity.path
updates.push
id: id
pathname: oldEntity.path
newPathname: newEntity.path
for id, newEntity of newEntitiesHash
oldEntity = oldEntitiesHash[id]
# removed entities
if !oldEntity?
# entity added
updates.push
id: id
pathname: newEntity.path
docLines: newEntity.docLines
url: newEntity.url
else if newEntity.path != oldEntity.path
# entity renamed
updates.push
id: id
pathname: oldEntity.path
newPathname: newEntity.path
updates

View file

@ -483,3 +483,18 @@ describe 'DocumentUpdaterHandler', ->
.calledWith(url: @url, json: {docUpdates: [], fileUpdates, userId: @user_id})
.should.equal true
done()
describe "when a doc has been deleted", ->
it 'should do nothing', (done) ->
@docId = new ObjectId()
@oldDocs = [
{ path: '/foo', docLines: 'a\nb', doc: _id: @docId }
]
@newDocs = []
@oldFiles = []
@newFiles = []
@handler.updateProjectStructure @project_id, @user_id, @oldDocs, @newDocs, @oldFiles, @newFiles, () =>
@request.post.called.should.equal false
done()