Merge pull request #17084 from overleaf/dp-mongoose-callback-system-message-manager

Promisify SystemMessageManager and SystemMessageManagerTests

GitOrigin-RevId: b8fafdfdba817160c1b18cf7eb0270a27adf114c
This commit is contained in:
David
2024-02-19 09:43:28 +00:00
committed by Copybot
parent 148f6d6f96
commit 0f05623e16
5 changed files with 76 additions and 80 deletions

View File

@@ -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') {

View File

@@ -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)
})
})
})
})