From 1f5b98bb53b116c6cf7d04b614e548c865d65399 Mon Sep 17 00:00:00 2001 From: blagoev Date: Tue, 12 Sep 2017 23:08:54 +0300 Subject: [PATCH] Use promisified methods for login and register to have backward compatibility testing as well --- tests/js/session-tests.js | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/tests/js/session-tests.js b/tests/js/session-tests.js index 6f61bcfd..8157a9eb 100644 --- a/tests/js/session-tests.js +++ b/tests/js/session-tests.js @@ -50,6 +50,32 @@ function uuid() { }); } +function promisifiedRegister(server, username, password) { + return new Promise((resolve, reject) => { + Realm.Sync.User.register(server, username, password, (error, user) => { + if (error) { + console.log(`promisifiedRegister ${error}`); + reject(error); + } else { + resolve(user); + } + }); + }); +} + +function promisifiedLogin(server, username, password) { + return new Promise((resolve, reject) => { + Realm.Sync.User.login(server, username, password, (error, user) => { + if (error) { + console.log(`promisifiedLogin ${error}`); + reject(error); + } else { + resolve(user); + } + }); + }); +} + function runOutOfProcess(nodeJsFilePath) { var nodeArgs = Array.prototype.slice.call(arguments); let tmpDir = tmp.dirSync(); @@ -85,7 +111,7 @@ module.exports = { }, testProperties() { - return Realm.Sync.User.login('http://localhost:9080', uuid(), 'password').then(user => { + return promisifiedRegister('http://localhost:9080', uuid(), 'password').then(user => { return new Promise((resolve, reject) => { const accessTokenRefreshed = this; @@ -136,7 +162,7 @@ module.exports = { return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH) .then(() => { - return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => { + return promisifiedLogin('http://localhost:9080', username, 'password').then(user => { const accessTokenRefreshed = this; let successCounter = 0; @@ -446,7 +472,7 @@ module.exports = { return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH) .then(() => { - return promisifiedLogin('http://localhost:9080', username, 'password').then(user => { + return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => { return new Promise((resolve, reject) => { let config = { sync: { @@ -481,7 +507,7 @@ module.exports = { return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH) .then(() => { - return promisifiedLogin('http://localhost:9080', username, 'password').then(user => { + return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => { return new Promise((resolve, reject) => { let config = { sync: { @@ -548,7 +574,7 @@ module.exports = { return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH) .then(() => { - return promisifiedLogin('http://localhost:9080', username, 'password').then(user => { + return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => { return new Promise((resolve, reject) => { let config = { sync: { @@ -587,7 +613,7 @@ module.exports = { return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH) .then(() => { - return promisifiedLogin('http://localhost:9080', username, 'password').then(user => { + return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => { return new Promise((resolve, reject) => { let config = { sync: {