update DocumentUpdaterHandler.updateProjectStructure to support entity deletions

This commit is contained in:
Hayden Faulds 2017-12-14 13:06:27 +00:00
parent 7aaf08da48
commit e5e75a8ccb
2 changed files with 22 additions and 6 deletions

View file

@ -207,8 +207,8 @@ module.exports = DocumentUpdaterHandler =
updateProjectStructure : (project_id, userId, changes, callback = (error) ->)->
return callback() if !settings.apis.project_history?.enabled
docUpdates = DocumentUpdaterHandler._getRenameUpdates('doc', changes.oldDocs, changes.newDocs)
fileUpdates = DocumentUpdaterHandler._getRenameUpdates('file', changes.oldFiles, changes.newFiles)
docUpdates = DocumentUpdaterHandler._getUpdates('doc', changes.oldDocs, changes.newDocs)
fileUpdates = DocumentUpdaterHandler._getUpdates('file', changes.oldFiles, changes.newFiles)
timer = new metrics.Timer("set-document")
url = "#{settings.apis.documentupdater.url}/project/#{project_id}"
@ -230,7 +230,7 @@ module.exports = DocumentUpdaterHandler =
logger.error {project_id, url}, "doc updater returned a non-success status code: #{res.statusCode}"
callback new Error("doc updater returned a non-success status code: #{res.statusCode}")
_getRenameUpdates: (entityType, oldEntities, newEntities) ->
_getUpdates: (entityType, oldEntities, newEntities) ->
oldEntities ||= []
newEntities ||= []
updates = []
@ -255,6 +255,15 @@ module.exports = DocumentUpdaterHandler =
pathname: oldEntity.path
newPathname: newEntity.path
for id, oldEntity of oldEntitiesHash
newEntity = newEntitiesHash[id]
if !newEntity?
# entity deleted
updates.push
id: id
pathname: oldEntity.path
updates
PENDINGUPDATESKEY = "PendingUpdates"

View file

@ -478,14 +478,21 @@ describe 'DocumentUpdaterHandler', ->
.should.equal true
done()
describe "when a doc has been deleted", ->
it 'should do nothing', (done) ->
describe "when an entity has been deleted", ->
it 'should end the structure update to the document updater', (done) ->
@docId = new ObjectId()
@changes = oldDocs: [
{ path: '/foo', docLines: 'a\nb', doc: _id: @docId }
]
docUpdates = [
id: @docId.toString(),
pathname: "/foo",
]
@handler.updateProjectStructure @project_id, @user_id, @changes, () =>
@request.post.called.should.equal false
@request.post
.calledWith(url: @url, json: {docUpdates, fileUpdates: [], userId: @user_id})
.should.equal true
done()