Merge pull request #2369 from overleaf/em-imports-tpds

Defer flushing to TPDS on project import from v1

GitOrigin-RevId: f2782326716999c37565b3e527b54444bbc53711
This commit is contained in:
Eric Mc Sween
2019-11-26 13:30:46 +00:00
committed by sharelatex
parent e51893ffb1
commit 3da8413156
14 changed files with 442 additions and 306 deletions
@@ -306,101 +306,6 @@ describe('ProjectEntityHandler', function() {
})
})
describe('flushProjectToThirdPartyDataStore', function() {
beforeEach(function(done) {
this.project = {
_id: project_id,
name: 'Mock project name'
}
this.DocumentUpdaterHandler.flushProjectToMongo = sinon.stub().yields()
this.docs = {
'/doc/one': (this.doc1 = { _id: 'mock-doc-1', lines: ['one'], rev: 5 }),
'/doc/two': (this.doc2 = { _id: 'mock-doc-2', lines: ['two'], rev: 6 })
}
this.files = {
'/file/one': (this.file1 = { _id: 'mock-file-1', rev: 7 }),
'/file/two': (this.file2 = { _id: 'mock-file-2', rev: 8 })
}
this.ProjectEntityHandler.getAllDocs = sinon
.stub()
.yields(null, this.docs)
this.ProjectEntityHandler.getAllFiles = sinon
.stub()
.yields(null, this.files)
this.ProjectGetter.getProject = sinon.stub().yields(null, this.project)
this.ProjectEntityHandler.flushProjectToThirdPartyDataStore(
project_id,
() => done()
)
})
it('should flush the project from the doc updater', function() {
this.DocumentUpdaterHandler.flushProjectToMongo
.calledWith(project_id)
.should.equal(true)
})
it('should look up the project in mongo', function() {
this.ProjectGetter.getProject.calledWith(project_id).should.equal(true)
})
it('should get all the docs in the project', function() {
this.ProjectEntityHandler.getAllDocs
.calledWith(project_id)
.should.equal(true)
})
it('should get all the files in the project', function() {
this.ProjectEntityHandler.getAllFiles
.calledWith(project_id)
.should.equal(true)
})
it('should flush each doc to the TPDS', function() {
return (() => {
const result = []
for (let path in this.docs) {
const doc = this.docs[path]
result.push(
this.TpdsUpdateSender.addDoc
.calledWith({
project_id,
doc_id: doc._id,
project_name: this.project.name,
rev: doc.rev,
path
})
.should.equal(true)
)
}
return result
})()
})
it('should flush each file to the TPDS', function() {
return (() => {
const result = []
for (let path in this.files) {
const file = this.files[path]
result.push(
this.TpdsUpdateSender.addFile
.calledWith({
project_id,
file_id: file._id,
project_name: this.project.name,
rev: file.rev,
path
})
.should.equal(true)
)
}
return result
})()
})
})
describe('getDoc', function() {
beforeEach(function() {
this.lines = ['mock', 'doc', 'lines']