mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-25 18:20:09 +02:00
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:
@@ -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)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user