Merge pull request #3571 from overleaf/jpa-ask-docstore-is-doc-deleted

[ProjectEntityUpdateHandler] ask docstore whether a doc exists/isDeleted

GitOrigin-RevId: 54c6666b514b466b908b9ed57a26bc6cf66037d7
This commit is contained in:
Jakob Ackermann
2021-02-09 14:55:41 +00:00
committed by Copybot
parent a351265175
commit 7f6d439302
5 changed files with 404 additions and 82 deletions

View File

@@ -71,6 +71,7 @@ describe('ProjectEntityUpdateHandler', function() {
this.DocstoreManager = {
getDoc: sinon.stub(),
isDocDeleted: sinon.stub(),
updateDoc: sinon.stub(),
deleteDoc: sinon.stub()
}
@@ -82,6 +83,7 @@ describe('ProjectEntityUpdateHandler', function() {
deleteDoc: sinon.stub().yields()
}
this.logger = {
info: sinon.stub(),
log: sinon.stub(),
warn: sinon.stub(),
error: sinon.stub(),
@@ -188,7 +190,8 @@ describe('ProjectEntityUpdateHandler', function() {
this.ranges = { mock: 'ranges' }
this.lastUpdatedAt = new Date().getTime()
this.lastUpdatedBy = 'fake-last-updater-id'
this.ProjectGetter.getProjectWithoutDocLines.yields(null, this.project)
this.DocstoreManager.isDocDeleted.yields(null, false)
this.ProjectGetter.getProject.yields(null, this.project)
this.ProjectLocator.findElement.yields(null, this.doc, {
fileSystem: this.path
})
@@ -210,9 +213,12 @@ describe('ProjectEntityUpdateHandler', function() {
)
})
it('should get the project without doc lines', function() {
this.ProjectGetter.getProjectWithoutDocLines
.calledWith(projectId)
it('should get the project with very few fields', function() {
this.ProjectGetter.getProject
.calledWith(projectId, {
name: true,
rootFolder: true
})
.should.equal(true)
})
@@ -294,9 +300,56 @@ describe('ProjectEntityUpdateHandler', function() {
describe('when the doc has been deleted', function() {
beforeEach(function() {
this.project.deletedDocs = [{ _id: docId }]
this.ProjectGetter.getProjectWithoutDocLines.yields(null, this.project)
this.ProjectGetter.getProject.yields(null, this.project)
this.ProjectLocator.findElement.yields(new Errors.NotFoundError())
this.DocstoreManager.isDocDeleted.yields(null, true)
this.DocstoreManager.updateDoc.yields()
this.ProjectEntityUpdateHandler.updateDocLines(
projectId,
docId,
this.docLines,
this.version,
this.ranges,
this.lastUpdatedAt,
this.lastUpdatedBy,
this.callback
)
})
it('should update the doc in the docstore', function() {
this.DocstoreManager.updateDoc
.calledWith(
projectId,
docId,
this.docLines,
this.version,
this.ranges
)
.should.equal(true)
})
it('should not mark the project as updated', function() {
this.ProjectUpdater.markAsUpdated.called.should.equal(false)
})
it('should not send the doc the to the TPDS', function() {
this.TpdsUpdateSender.addDoc.called.should.equal(false)
})
it('should call the callback', function() {
this.callback.called.should.equal(true)
})
})
describe('when projects and docs collection are de-synced', function() {
beforeEach(function() {
this.ProjectGetter.getProject.yields(null, this.project)
// The doc is not in the file-tree, but also not marked as deleted.
// This should not happen, but web should handle it.
this.ProjectLocator.findElement.yields(new Errors.NotFoundError())
this.DocstoreManager.isDocDeleted.yields(null, false)
this.DocstoreManager.updateDoc.yields()
this.ProjectEntityUpdateHandler.updateDocLines(
projectId,
@@ -337,7 +390,9 @@ describe('ProjectEntityUpdateHandler', function() {
describe('when the doc is not related to the project', function() {
beforeEach(function() {
this.ProjectLocator.findElement.yields()
this.ProjectGetter.getProject.yields(null, this.project)
this.ProjectLocator.findElement.yields(new Errors.NotFoundError())
this.DocstoreManager.isDocDeleted.yields(new Errors.NotFoundError())
this.ProjectEntityUpdateHandler.updateDocLines(
projectId,
docId,
@@ -355,11 +410,19 @@ describe('ProjectEntityUpdateHandler', function() {
.calledWith(sinon.match.instanceOf(Errors.NotFoundError))
.should.equal(true)
})
it('should not update the doc', function() {
this.DocstoreManager.updateDoc.called.should.equal(false)
})
it('should not send the doc the to the TPDS', function() {
this.TpdsUpdateSender.addDoc.called.should.equal(false)
})
})
describe('when the project is not found', function() {
beforeEach(function() {
this.ProjectGetter.getProjectWithoutDocLines.yields()
this.ProjectGetter.getProject.yields(new Errors.NotFoundError())
this.ProjectEntityUpdateHandler.updateDocLines(
projectId,
docId,
@@ -377,6 +440,14 @@ describe('ProjectEntityUpdateHandler', function() {
.calledWith(sinon.match.instanceOf(Errors.NotFoundError))
.should.equal(true)
})
it('should not update the doc', function() {
this.DocstoreManager.updateDoc.called.should.equal(false)
})
it('should not send the doc the to the TPDS', function() {
this.TpdsUpdateSender.addDoc.called.should.equal(false)
})
})
})