From 8ce8f521056671b325aa07da214e9c29a65d1306 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Tue, 8 Nov 2016 14:07:04 -0800 Subject: [PATCH] add test for login --- lib/user-methods.js | 3 ++- src/js_realm.hpp | 6 +++++- tests/js/user-tests.js | 24 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/user-methods.js b/lib/user-methods.js index 626823cb..c81853d4 100644 --- a/lib/user-methods.js +++ b/lib/user-methods.js @@ -53,7 +53,8 @@ module.exports = function(realmConstructor) { var options = { url: auth_url(server), body: JSON.stringify(json), - headers: postHeaders + headers: postHeaders, + open_timeout: 5000 }; post(options, function(error, response, body) { if (error) { diff --git a/src/js_realm.hpp b/src/js_realm.hpp index d270d953..7831419d 100644 --- a/src/js_realm.hpp +++ b/src/js_realm.hpp @@ -33,6 +33,7 @@ #if REALM_ENABLE_SYNC #include "js_sync.hpp" #include "sync/sync_config.hpp" +#include "sync/sync_manager.hpp" #endif #include "shared_realm.hpp" @@ -455,9 +456,12 @@ void RealmClass::schema_version(ContextType ctx, ObjectType this_object, size template void RealmClass::clear_test_state(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 0); + for(auto &user : SyncManager::shared().all_users()) { + user->log_out(); + } delete_all_realms(); } - + template void RealmClass::copy_bundled_realm_files(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 0); diff --git a/tests/js/user-tests.js b/tests/js/user-tests.js index b0a58c77..91e94512 100644 --- a/tests/js/user-tests.js +++ b/tests/js/user-tests.js @@ -76,5 +76,29 @@ module.exports = { }); }); }, + + testLogin() { + var username = uuid(); + return new Promise((resolve, reject) => { + Realm.Sync.User.register('http://localhost:9080', username, 'password', (error, user) => { + user.logout(); + //TestCase.assertEqual(Realm.Sync.User.all.length, 0); + + Realm.Sync.User.login('http://localhost:9080', username, 'password', (error, user) => { + TestCase.assertEqual(typeof user, 'object'); + TestCase.assertEqual(typeof user.token, 'string'); + TestCase.assertEqual(typeof user.identity, 'string'); + TestCase.assertEqual(user.isAdmin, false); + + var realm = new Realm({sync: {user: user, url: 'realm://localhost:9080/~/test'}}); + TestCase.assertNotEqual(realm instanceof Realm); + + //TestCase.assertEqual(Realm.Sync.User.all.length, 1); + + resolve(); + }); + }); + }); + }, };