add test for login

This commit is contained in:
Ari Lazier 2016-11-08 14:07:04 -08:00
parent b2e71a5fb6
commit 8ce8f52105
3 changed files with 31 additions and 2 deletions

View File

@ -53,7 +53,8 @@ module.exports = function(realmConstructor) {
var options = { var options = {
url: auth_url(server), url: auth_url(server),
body: JSON.stringify(json), body: JSON.stringify(json),
headers: postHeaders headers: postHeaders,
open_timeout: 5000
}; };
post(options, function(error, response, body) { post(options, function(error, response, body) {
if (error) { if (error) {

View File

@ -33,6 +33,7 @@
#if REALM_ENABLE_SYNC #if REALM_ENABLE_SYNC
#include "js_sync.hpp" #include "js_sync.hpp"
#include "sync/sync_config.hpp" #include "sync/sync_config.hpp"
#include "sync/sync_manager.hpp"
#endif #endif
#include "shared_realm.hpp" #include "shared_realm.hpp"
@ -455,6 +456,9 @@ void RealmClass<T>::schema_version(ContextType ctx, ObjectType this_object, size
template<typename T> template<typename T>
void RealmClass<T>::clear_test_state(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { void RealmClass<T>::clear_test_state(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
validate_argument_count(argc, 0); validate_argument_count(argc, 0);
for(auto &user : SyncManager::shared().all_users()) {
user->log_out();
}
delete_all_realms(); delete_all_realms();
} }

View File

@ -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();
});
});
});
},
}; };