all users should return a dictionary

This commit is contained in:
Ari Lazier 2016-11-10 13:55:22 -08:00
parent 87b30fb4ec
commit 6d485866f6
3 changed files with 12 additions and 12 deletions

View File

@ -126,14 +126,13 @@ void UserClass<T>::create_user(ContextType ctx, ObjectType this_object, size_t a
template<typename T> template<typename T>
void UserClass<T>::all_users(ContextType ctx, ObjectType object, ReturnValue &return_value) { void UserClass<T>::all_users(ContextType ctx, ObjectType object, ReturnValue &return_value) {
std::vector<ValueType> user_vector; auto users = Object::create_empty(ctx);
// TODO: This method should return a dictionary of shape {userid->user}
for (auto user : SyncManager::shared().all_users()) { for (auto user : SyncManager::shared().all_users()) {
if (user->state() == SyncUser::State::Active) { if (user->state() == SyncUser::State::Active) {
user_vector.push_back(create_object<T, UserClass<T>>(ctx, new SharedUser(user))); Object::set_property(ctx, users, user->identity(), create_object<T, UserClass<T>>(ctx, new SharedUser(user)), ReadOnly | DontDelete);
} }
} }
return_value.set(Object::create_array(ctx, user_vector)); return_value.set(users);
} }
template<typename T> template<typename T>

View File

@ -199,19 +199,19 @@ module.exports = {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let all; let all;
all = Realm.Sync.User.all; all = Realm.Sync.User.all;
TestCase.assertArrayLength(all, 0); TestCase.assertArrayLength(Object.keys(all), 0);
Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', (error, user1) => { Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', (error, user1) => {
all = Realm.Sync.User.all; all = Realm.Sync.User.all;
TestCase.assertArrayLength(all, 1); TestCase.assertArrayLength(Object.keys(all), 1);
assertIsSameUser(all[0], user1); assertIsSameUser(all[user1.identity], user1);
Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', (error, user2) => { Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', (error, user2) => {
all = Realm.Sync.User.all; all = Realm.Sync.User.all;
TestCase.assertArrayLength(all, 2); TestCase.assertArrayLength(Object.keys(all), 2);
// NOTE: the list of users is in latest-first order. // NOTE: the list of users is in latest-first order.
assertIsSameUser(all[0], user2); assertIsSameUser(all[user2.identity], user2);
assertIsSameUser(all[1], user1); assertIsSameUser(all[user1.identity], user1);
resolve(); resolve();
}); });
}); });

View File

@ -29,8 +29,9 @@ describe('SyncTests', () => {
beforeEach(() => Realm.clearTestState()); beforeEach(() => Realm.clearTestState());
afterEach(() => { afterEach(() => {
Realm.clearTestState(); Realm.clearTestState();
Realm.Sync.User.all.forEach((user) => { let users = Realm.Sync.User.all;
user.logout(); Object.keys(users).forEach((identity) => {
users[identity].logout();
}); });
}); });