mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 09:09:36 +02:00
Merge pull request #17084 from overleaf/dp-mongoose-callback-system-message-manager
Promisify SystemMessageManager and SystemMessageManagerTests GitOrigin-RevId: b8fafdfdba817160c1b18cf7eb0270a27adf114c
This commit is contained in:
@@ -143,13 +143,18 @@ function promisifyMultiResult(fn, resultNames) {
|
||||
*
|
||||
* @param {Object} module - The module to callbackify
|
||||
* @param {Object} opts - Options
|
||||
* @param {Array<string>} opts.without - Array of method names to exclude from
|
||||
* being callbackified
|
||||
* @param {Object} opts.multiResult - Spec of methods to be callbackified with
|
||||
* callbackifyMultiResult()
|
||||
*/
|
||||
function callbackifyAll(module, opts = {}) {
|
||||
const { multiResult = {} } = opts
|
||||
const { without = [], multiResult = {} } = opts
|
||||
const callbacks = {}
|
||||
for (const propName of Object.getOwnPropertyNames(module)) {
|
||||
if (without.includes(propName)) {
|
||||
continue
|
||||
}
|
||||
const propValue = module[propName]
|
||||
if (typeof propValue === 'function') {
|
||||
if (propValue.constructor.name === 'AsyncFunction') {
|
||||
|
||||
@@ -295,4 +295,32 @@ describe('callbackifyAll', function () {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('without option', function () {
|
||||
before(function () {
|
||||
this.module = {
|
||||
async asyncAdd(a, b) {
|
||||
return a + b
|
||||
},
|
||||
async asyncArithmetic(a, b) {
|
||||
return { sum: a + b, product: a * b }
|
||||
},
|
||||
}
|
||||
this.callbackified = callbackifyAll(this.module, {
|
||||
without: ['asyncAdd'],
|
||||
})
|
||||
})
|
||||
|
||||
it('does not callbackify excluded functions', function () {
|
||||
expect(this.callbackified.asyncAdd).not.to.exist
|
||||
})
|
||||
|
||||
it('callbackifies other functions', async function () {
|
||||
this.callbackified.asyncArithmetic(5, 6, (err, { sum, product }) => {
|
||||
expect(err).not.to.exist
|
||||
expect(sum).to.equal(11)
|
||||
expect(product).to.equal(30)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user