mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #20978 from overleaf/jpa-fix-unit-tests
[project-history] fix unit tests for processing updates GitOrigin-RevId: ce87296b9b97dcfd7598fbf25b3066b7c145fb6f
This commit is contained in:
parent
d711d35466
commit
663f6605d7
2 changed files with 92 additions and 51 deletions
|
@ -327,7 +327,7 @@ function _getMostRecentVersionWithDebug(projectId, projectHistoryId, callback) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function _processUpdates(
|
export function _processUpdates(
|
||||||
projectId,
|
projectId,
|
||||||
projectHistoryId,
|
projectHistoryId,
|
||||||
updates,
|
updates,
|
||||||
|
|
|
@ -23,7 +23,7 @@ describe('UpdatesProcessor', function () {
|
||||||
before(async function () {
|
before(async function () {
|
||||||
this.extendLock = sinon.stub()
|
this.extendLock = sinon.stub()
|
||||||
this.BlobManager = {
|
this.BlobManager = {
|
||||||
createBlobForUpdates: sinon.stub(),
|
createBlobsForUpdates: sinon.stub(),
|
||||||
}
|
}
|
||||||
this.HistoryStoreManager = {
|
this.HistoryStoreManager = {
|
||||||
getMostRecentVersion: sinon.stub(),
|
getMostRecentVersion: sinon.stub(),
|
||||||
|
@ -56,11 +56,28 @@ describe('UpdatesProcessor', function () {
|
||||||
record: sinon.stub().yields(),
|
record: sinon.stub().yields(),
|
||||||
}
|
}
|
||||||
this.Profiler = {
|
this.Profiler = {
|
||||||
Profiler: sinon.stub(),
|
Profiler: class {
|
||||||
|
log() {
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
wrap(label, cb) {
|
||||||
|
return cb
|
||||||
|
}
|
||||||
|
|
||||||
|
getTimeDelta() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
end() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
this.Metrics = {
|
this.Metrics = {
|
||||||
gauge: sinon.stub(),
|
gauge: sinon.stub(),
|
||||||
inc: sinon.stub(),
|
inc: sinon.stub(),
|
||||||
|
timing: sinon.stub(),
|
||||||
}
|
}
|
||||||
this.Settings = {
|
this.Settings = {
|
||||||
redis: {
|
redis: {
|
||||||
|
@ -255,14 +272,20 @@ describe('UpdatesProcessor', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('_processUpdates', function () {
|
describe('_processUpdates', function () {
|
||||||
return beforeEach(function () {
|
beforeEach(function () {
|
||||||
this.mostRecentVersionInfo = { version: 1 }
|
this.mostRecentVersionInfo = { version: 1 }
|
||||||
this.rawUpdates = ['raw updates']
|
this.rawUpdates = ['raw updates']
|
||||||
this.expandedUpdates = ['expanded updates']
|
this.expandedUpdates = ['expanded updates']
|
||||||
this.filteredUpdates = ['filtered updates']
|
this.filteredUpdates = ['filtered updates']
|
||||||
this.compressedUpdates = ['compressed updates']
|
this.compressedUpdates = ['compressed updates']
|
||||||
this.updatesWithBlobs = ['updates with blob']
|
this.updatesWithBlobs = ['updates with blob']
|
||||||
this.changes = ['changes']
|
this.changes = [
|
||||||
|
{
|
||||||
|
toRaw() {
|
||||||
|
return 'change'
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
this.newSyncState = { resyncProjectStructure: false }
|
this.newSyncState = { resyncProjectStructure: false }
|
||||||
|
|
||||||
this.extendLock = sinon.stub().yields()
|
this.extendLock = sinon.stub().yields()
|
||||||
|
@ -276,77 +299,95 @@ describe('UpdatesProcessor', function () {
|
||||||
this.filteredUpdates,
|
this.filteredUpdates,
|
||||||
this.newSyncState
|
this.newSyncState
|
||||||
)
|
)
|
||||||
this.SyncManager.expandSyncUpdates.yields(null, this.expandedUpdates)
|
this.SyncManager.expandSyncUpdates.callsArgWith(
|
||||||
|
4,
|
||||||
|
null,
|
||||||
|
this.expandedUpdates
|
||||||
|
)
|
||||||
this.UpdateCompressor.compressRawUpdates.returns(this.compressedUpdates)
|
this.UpdateCompressor.compressRawUpdates.returns(this.compressedUpdates)
|
||||||
this.BlobManager.createBlobForUpdates.yields(null, this.updatesWithBlobs)
|
this.BlobManager.createBlobsForUpdates.callsArgWith(
|
||||||
|
4,
|
||||||
|
null,
|
||||||
|
this.updatesWithBlobs
|
||||||
|
)
|
||||||
this.UpdateTranslator.convertToChanges.returns(this.changes)
|
this.UpdateTranslator.convertToChanges.returns(this.changes)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('happy path', function () {
|
||||||
|
beforeEach(function (done) {
|
||||||
this.UpdatesProcessor._processUpdates(
|
this.UpdatesProcessor._processUpdates(
|
||||||
this.project_id,
|
this.project_id,
|
||||||
|
this.ol_project_id,
|
||||||
this.rawUpdates,
|
this.rawUpdates,
|
||||||
this.extendLock,
|
this.extendLock,
|
||||||
done
|
err => {
|
||||||
|
this.callback(err)
|
||||||
|
done()
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it('should get the latest version id', function () {
|
it('should get the latest version id', function () {
|
||||||
return this.HistoryStoreManager.getMostRecentVersion
|
return this.HistoryStoreManager.getMostRecentVersion.should.have.been.calledWith(
|
||||||
.calledWith(this.project_id, this.ol_project_id)
|
this.project_id,
|
||||||
.should.equal(true)
|
this.ol_project_id
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should skip updates when resyncing', function () {
|
it('should skip updates when resyncing', function () {
|
||||||
return this.SyncManager.skipUpdatesDuringSync
|
return this.SyncManager.skipUpdatesDuringSync.should.have.been.calledWith(
|
||||||
.calledWith(this.project_id, this.rawUpdates)
|
this.project_id,
|
||||||
.should.equal(true)
|
this.rawUpdates
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should expand sync updates', function () {
|
it('should expand sync updates', function () {
|
||||||
return this.SyncManager.expandSyncUpdates
|
return this.SyncManager.expandSyncUpdates.should.have.been.calledWith(
|
||||||
.calledWith(
|
|
||||||
this.project_id,
|
this.project_id,
|
||||||
this.ol_project_id,
|
this.ol_project_id,
|
||||||
this.filteredUpdates,
|
this.filteredUpdates,
|
||||||
this.extendLock
|
this.extendLock
|
||||||
)
|
)
|
||||||
.should.equal(true)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should compress updates', function () {
|
it('should compress updates', function () {
|
||||||
return this.UpdateCompressor.compressRawUpdates
|
return this.UpdateCompressor.compressRawUpdates.should.have.been.calledWith(
|
||||||
.calledWith(this.expandedUpdates)
|
this.expandedUpdates
|
||||||
.should.equal(true)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should not create any blobs', function () {
|
it('should create any blobs for the updates', function () {
|
||||||
return this.BlobManager.createBlobForUpdates
|
return this.BlobManager.createBlobsForUpdates.should.have.been.calledWith(
|
||||||
.calledWith(this.project_id, this.compressedUpdates)
|
this.project_id,
|
||||||
.called.should.equal(false)
|
this.ol_project_id,
|
||||||
|
this.compressedUpdates
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should convert the updates into a change requests', function () {
|
it('should convert the updates into a change requests', function () {
|
||||||
return this.UpdateTranslator.convertToChanges
|
return this.UpdateTranslator.convertToChanges.should.have.been.calledWith(
|
||||||
.calledWith(
|
|
||||||
this.project_id,
|
this.project_id,
|
||||||
this.updatesWithBlobs,
|
this.updatesWithBlobs
|
||||||
this.mostRecentVersionInfo.version
|
|
||||||
)
|
)
|
||||||
.should.equal(true)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should send the change request to the history store', function () {
|
it('should send the change request to the history store', function () {
|
||||||
return this.HistoryStoreManager.sendChanges
|
return this.HistoryStoreManager.sendChanges.should.have.been.calledWith(
|
||||||
.calledWith(this.project_id, this.ol_project_id, this.changes)
|
this.project_id,
|
||||||
.should.equal(true)
|
this.ol_project_id,
|
||||||
|
['change']
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should set the sync state', function () {
|
it('should set the sync state', function () {
|
||||||
return this.SyncManager.setResyncState
|
return this.SyncManager.setResyncState.should.have.been.calledWith(
|
||||||
.calledWith(this.project_id, this.newSyncState)
|
this.project_id,
|
||||||
.should.equal(true)
|
this.newSyncState
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
return it('should call the callback with no error', function () {
|
it('should call the callback with no error', function () {
|
||||||
return this.callback.called.should.equal(true)
|
return this.callback.should.have.been.called
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue