mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
Merge pull request #15648 from overleaf/em-promisify-doc-manager
Promisify DocManager GitOrigin-RevId: c9ab368086492900e1617d5d96943d405f25883d
This commit is contained in:
@@ -3,6 +3,7 @@ const sinon = require('sinon')
|
||||
const sinonChai = require('sinon-chai')
|
||||
const chaiAsPromised = require('chai-as-promised')
|
||||
const SandboxedModule = require('sandboxed-module')
|
||||
const timersPromises = require('timers/promises')
|
||||
|
||||
process.env.BACKEND = 'gcs'
|
||||
|
||||
@@ -29,6 +30,7 @@ const stubs = {
|
||||
SandboxedModule.configure({
|
||||
requires: {
|
||||
'@overleaf/logger': stubs.logger,
|
||||
'timers/promises': timersPromises,
|
||||
},
|
||||
globals: { Buffer, JSON, Math, console, process },
|
||||
})
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -403,60 +403,42 @@ describe('MongoManager', function () {
|
||||
})
|
||||
})
|
||||
|
||||
describe('withRevCheck', function () {
|
||||
describe('checkRevUnchanged', function () {
|
||||
this.beforeEach(function () {
|
||||
this.doc = { _id: ObjectId(), name: 'mock-doc', rev: 1 }
|
||||
this.testFunction = sinon.stub().yields(null, 'foo')
|
||||
})
|
||||
|
||||
it('should call the callback when the rev has not changed', function (done) {
|
||||
this.db.docs.findOne = sinon.stub().callsArgWith(2, null, { rev: 1 })
|
||||
this.MongoManager.withRevCheck(
|
||||
this.doc,
|
||||
this.testFunction,
|
||||
(err, result) => {
|
||||
result.should.equal('foo')
|
||||
assert.isNull(err)
|
||||
done()
|
||||
}
|
||||
)
|
||||
this.MongoManager.checkRevUnchanged(this.doc, err => {
|
||||
assert.isUndefined(err)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should return an error when the rev has changed', function (done) {
|
||||
this.db.docs.findOne = sinon.stub().callsArgWith(2, null, { rev: 2 })
|
||||
this.MongoManager.withRevCheck(
|
||||
this.doc,
|
||||
this.testFunction,
|
||||
(err, result) => {
|
||||
err.should.be.instanceof(Errors.DocModifiedError)
|
||||
done()
|
||||
}
|
||||
)
|
||||
this.MongoManager.checkRevUnchanged(this.doc, err => {
|
||||
err.should.be.instanceof(Errors.DocModifiedError)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should return a value error if incoming rev is NaN', function (done) {
|
||||
this.db.docs.findOne = sinon.stub().callsArgWith(2, null, { rev: 2 })
|
||||
this.doc = { _id: ObjectId(), name: 'mock-doc', rev: NaN }
|
||||
this.MongoManager.withRevCheck(
|
||||
this.doc,
|
||||
this.testFunction,
|
||||
(err, result) => {
|
||||
err.should.be.instanceof(Errors.DocRevValueError)
|
||||
done()
|
||||
}
|
||||
)
|
||||
this.MongoManager.checkRevUnchanged(this.doc, err => {
|
||||
err.should.be.instanceof(Errors.DocRevValueError)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should return a value error if checked doc rev is NaN', function (done) {
|
||||
this.db.docs.findOne = sinon.stub().callsArgWith(2, null, { rev: NaN })
|
||||
this.MongoManager.withRevCheck(
|
||||
this.doc,
|
||||
this.testFunction,
|
||||
(err, result) => {
|
||||
err.should.be.instanceof(Errors.DocRevValueError)
|
||||
done()
|
||||
}
|
||||
)
|
||||
this.MongoManager.checkRevUnchanged(this.doc, err => {
|
||||
err.should.be.instanceof(Errors.DocRevValueError)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user