Merge pull request #2328 from overleaf/em-project-imports
Move ProjectEntityMongoUpdateHandler to async/await GitOrigin-RevId: e5c0d4a7ece34c3ded89b6eae3673135061f375a
This commit is contained in:
committed by
sharelatex
parent
e3c8de035a
commit
3bd15b1a47
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,8 @@
|
||||
const { expect } = require('chai')
|
||||
const { promisifyAll } = require('../../../../app/src/util/promises')
|
||||
const {
|
||||
promisifyAll,
|
||||
callbackifyMultiResult
|
||||
} = require('../../../../app/src/util/promises')
|
||||
|
||||
describe('promisifyAll', function() {
|
||||
describe('basic functionality', function() {
|
||||
@@ -57,4 +60,64 @@ describe('promisifyAll', function() {
|
||||
expect(sum).to.equal(101)
|
||||
})
|
||||
})
|
||||
|
||||
describe('multiResult option', function() {
|
||||
before(function() {
|
||||
this.module = {
|
||||
asyncAdd(a, b, callback) {
|
||||
callback(null, a + b)
|
||||
},
|
||||
asyncArithmetic(a, b, callback) {
|
||||
callback(null, a + b, a * b)
|
||||
}
|
||||
}
|
||||
this.promisified = promisifyAll(this.module, {
|
||||
multiResult: { asyncArithmetic: ['sum', 'product'] }
|
||||
})
|
||||
})
|
||||
|
||||
it('promisifies multi-result functions', async function() {
|
||||
const result = await this.promisified.asyncArithmetic(3, 6)
|
||||
expect(result).to.deep.equal({ sum: 9, product: 18 })
|
||||
})
|
||||
|
||||
it('promisifies other functions normally', async function() {
|
||||
const sum = await this.promisified.asyncAdd(6, 1)
|
||||
expect(sum).to.equal(7)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('callbackifyMultiResult', function() {
|
||||
it('callbackifies a multi-result function', function(done) {
|
||||
async function asyncArithmetic(a, b) {
|
||||
return { sum: a + b, product: a * b }
|
||||
}
|
||||
const callbackified = callbackifyMultiResult(asyncArithmetic, [
|
||||
'sum',
|
||||
'product'
|
||||
])
|
||||
callbackified(3, 11, (err, sum, product) => {
|
||||
if (err != null) {
|
||||
return done(err)
|
||||
}
|
||||
expect(sum).to.equal(14)
|
||||
expect(product).to.equal(33)
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('propagates errors', function(done) {
|
||||
async function asyncBomb() {
|
||||
throw new Error('BOOM!')
|
||||
}
|
||||
const callbackified = callbackifyMultiResult(asyncBomb, [
|
||||
'explosives',
|
||||
'dynamite'
|
||||
])
|
||||
callbackified(err => {
|
||||
expect(err).to.exist
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user