mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-30 21:42:51 +00:00
Merge pull request #2057 from overleaf/spd-promisify-userhelper
Add promisified version of User helper in acceptance tests GitOrigin-RevId: ce2c28dd0d8ec66edaef54a260a3944f4cdd55d6
This commit is contained in:
parent
1d13f41163
commit
5b458e32ac
1 changed files with 25 additions and 0 deletions
|
@ -22,6 +22,7 @@ const { db, ObjectId } = require('../../../../app/src/infrastructure/mongojs')
|
|||
const UserModel = require('../../../../app/src/models/User').User
|
||||
const UserUpdater = require('../../../../app/src/Features/User/UserUpdater')
|
||||
const AuthenticationManager = require('../../../../app/src/Features/Authentication/AuthenticationManager')
|
||||
const { promisify } = require('util')
|
||||
|
||||
let count = 0
|
||||
|
||||
|
@ -764,6 +765,30 @@ class User {
|
|||
}
|
||||
}
|
||||
|
||||
User.promises = class extends User {
|
||||
doRequest(method, params) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.request[method.toLowerCase()](params, (err, response, body) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
} else {
|
||||
resolve({ response, body })
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// promisify User class methods - works for methods with 0-1 output parameters,
|
||||
// otherwise we will need to implement the method manually instead
|
||||
const nonPromiseMethods = ['constructor', 'setExtraAttributes']
|
||||
Object.getOwnPropertyNames(User.prototype).forEach(methodName => {
|
||||
const method = User.prototype[methodName]
|
||||
if (typeof method === 'function' && !nonPromiseMethods.includes(methodName)) {
|
||||
User.promises.prototype[methodName] = promisify(method)
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = User
|
||||
|
||||
function __guard__(value, transform) {
|
||||
|
|
Loading…
Reference in a new issue