From 9366de14ef3bdef8ec3102885537397b66947e5a Mon Sep 17 00:00:00 2001 From: blagoev Date: Tue, 12 Sep 2017 23:01:58 +0300 Subject: [PATCH] Revert user-tests to still use callbacks for login/register etc --- tests/js/user-tests.js | 100 ++++++++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 41 deletions(-) diff --git a/tests/js/user-tests.js b/tests/js/user-tests.js index 466f80ca..4d2a24ab 100644 --- a/tests/js/user-tests.js +++ b/tests/js/user-tests.js @@ -297,55 +297,73 @@ module.exports = { }, testRetrieveAccount() { - if (!isNodeProcess) { - return Promise.resolve() - } - if (!global.testAdminUserInfo) { - return Promise.reject("Test requires an admin user"); - } - return Realm.Sync.User.login('http://localhost:9080', global.testAdminUserInfo.username, global.testAdminUserInfo.password) - .then(user => { + return new Promise((resolve, reject) => { + if (!isNodeProcess) { + resolve(); + } + + if (!global.testAdminUserInfo) { + reject("Test requires an admin user"); + } + + Realm.Sync.User.login('http://localhost:9080', global.testAdminUserInfo.username, global.testAdminUserInfo.password, (error, user) => { + if (error) { + reject(error); + } + TestCase.assertTrue(user.isAdmin, "Test requires an admin user"); - return user.retrieveAccount() + + user.retrieveAccount('password', global.testAdminUserInfo.username) + .then(account => { + // { + // "provider_id": "admin", + // "provider": "password", + // "user": { + // "id": "07ac9a0a-a97a-4ee1-b53c-b05a6542035a", + // "isAdmin": true, + // } + // } + + TestCase.assertEqual(account.provider_id, global.testAdminUserInfo.username); + TestCase.assertEqual(account.provider, 'password'); + TestCase.assertTrue(account.user); + TestCase.assertTrue(account.user.isAdmin !== undefined); + TestCase.assertTrue(account.user.id); + resolve(); + }) + .catch(e => reject(e)); }) - .then(account => { - // { - // "provider_id": "admin", - // "provider": "password", - // "user": { - // "id": "07ac9a0a-a97a-4ee1-b53c-b05a6542035a", - // "isAdmin": true, - // } - // } - TestCase.assertEqual(account.provider_id, global.testAdminUserInfo.username); - TestCase.assertEqual(account.provider, 'password'); - TestCase.assertTrue(account.user); - TestCase.assertTrue(account.user.isAdmin !== undefined); - TestCase.assertTrue(account.user.id); - }) - .catch(e => reject(e)); + }); }, testRetrieveNotExistingAccount() { - if (!isNodeProcess) { - return Promise.resolve() - } - if (!global.testAdminUserInfo) { - return Promise.reject("Test requires an admin user"); - } - return Realm.Sync.User.login('http://localhost:9080', global.testAdminUserInfo.username, global.testAdminUserInfo.password) - .then(user => { + return new Promise((resolve, reject) => { + if (!isNodeProcess) { + resolve(); + } + + if (!global.testAdminUserInfo) { + reject("Test requires an admin user"); + } + + Realm.Sync.User.login('http://localhost:9080', global.testAdminUserInfo.username, global.testAdminUserInfo.password, (error, user) => { + if (error) { + reject(error); + } + TestCase.assertTrue(user.isAdmin, "Test requires an admin user"); + let notExistingUsername = uuid(); - return user.retrieveAccount('password', notExistingUsername) + user.retrieveAccount('password', notExistingUsername) + .then(account => { + reject("Retrieving not existing account should fail"); + }) + .catch(e => { + TestCase.assertEqual(e.code, 404); + resolve() + }); }) - .then(account => { - reject("Retrieving not existing account should fail"); - }) - .catch(e => { - TestCase.assertEqual(e.code, 404); - resolve() - }); + }); }, /* This test fails because of realm-object-store #243 . We should use 2 users.