add usermanager tests

This commit is contained in:
Girish Ramakrishnan
2020-02-14 14:34:29 -08:00
parent 655a740b0c
commit 00c6ad675e
3 changed files with 140 additions and 51 deletions

View File

@@ -251,24 +251,24 @@ function update(userId, user, callback) {
assert.strictEqual(typeof user, 'object');
assert.strictEqual(typeof callback, 'function');
assert(!('username' in user) || (user.username === null || typeof user.username === 'string'));
assert(!('email' in user) || (typeof user.email === 'string'));
assert(!('fallbackEmail' in user) || (typeof user.fallbackEmail === 'string'));
assert(!('twoFactorAuthenticationEnabled' in user) || (typeof user.twoFactorAuthenticationEnabled === 'boolean'));
assert(!('admin' in user) || (typeof user.admin === 'boolean'));
assert(!('active' in user) || (typeof user.active === 'boolean'));
var args = [ ];
var fields = [ ];
for (var k in user) {
fields.push(k + ' = ?');
if (k === 'username') {
assert(user.username === null || typeof user.username === 'string');
args.push(user.username);
} else if (k === 'email' || k === 'fallbackEmail') {
assert.strictEqual(typeof user[k], 'string');
args.push(user[k]);
} else if (k === 'twoFactorAuthenticationEnabled' || k === 'admin' || k === 'active') {
assert.strictEqual(typeof user[k], 'boolean');
if (k === 'twoFactorAuthenticationEnabled' || k === 'admin' || k === 'active') {
fields.push(k + ' = ?');
args.push(user[k] ? 1 : 0);
} else if (k === 'permissions') {
fields.push(`${k}Json = ?`);
args.push(JSON.stringify(user[k]));
} else {
fields.push(k + ' = ?');
args.push(user[k]);
}
}