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:
committed by
sharelatex
parent
e51893ffb1
commit
3da8413156
@@ -117,6 +117,9 @@ describe('ProjectController', function() {
|
||||
.stub()
|
||||
.callsArgWith(1, null, this.brandVariationDetails)
|
||||
}
|
||||
this.TpdsProjectFlusher = {
|
||||
flushProjectToTpdsIfNeeded: sinon.stub().yields()
|
||||
}
|
||||
this.getUserAffiliations = sinon.stub().callsArgWith(1, null, [
|
||||
{
|
||||
email: 'test@overleaf.com',
|
||||
@@ -154,9 +157,7 @@ describe('ProjectController', function() {
|
||||
'../Subscription/LimitationsManager': this.LimitationsManager,
|
||||
'../Tags/TagsHandler': this.TagsHandler,
|
||||
'../Notifications/NotificationsHandler': this.NotificationsHandler,
|
||||
'../../models/User': {
|
||||
User: this.UserModel
|
||||
},
|
||||
'../../models/User': { User: this.UserModel },
|
||||
'../Authorization/AuthorizationManager': this.AuthorizationManager,
|
||||
'../InactiveData/InactiveProjectManager': this.InactiveProjectManager,
|
||||
'./ProjectUpdateHandler': this.ProjectUpdateHandler,
|
||||
@@ -180,6 +181,7 @@ describe('ProjectController', function() {
|
||||
'../Institutions/InstitutionsAPI': {
|
||||
getUserAffiliations: this.getUserAffiliations
|
||||
},
|
||||
'../ThirdPartyDataStore/TpdsProjectFlusher': this.TpdsProjectFlusher,
|
||||
'../V1/V1Handler': {},
|
||||
'../../models/Project': {}
|
||||
}
|
||||
@@ -1105,6 +1107,16 @@ describe('ProjectController', function() {
|
||||
}
|
||||
this.ProjectController.loadEditor(this.req, this.res)
|
||||
})
|
||||
|
||||
it('flushes the project to TPDS if a flush is pending', function(done) {
|
||||
this.res.render = () => {
|
||||
this.TpdsProjectFlusher.flushProjectToTpdsIfNeeded.should.have.been.calledWith(
|
||||
this.project_id
|
||||
)
|
||||
done()
|
||||
}
|
||||
this.ProjectController.loadEditor(this.req, this.res)
|
||||
})
|
||||
})
|
||||
|
||||
describe('userProjectsJson', function() {
|
||||
|
||||
@@ -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']
|
||||
|
||||
Reference in New Issue
Block a user