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>
void UserClass<T>::all_users(ContextType ctx, ObjectType object, ReturnValue &return_value) {
std::vector<ValueType> user_vector;
// TODO: This method should return a dictionary of shape {userid->user}
auto users = Object::create_empty(ctx);
for (auto user : SyncManager::shared().all_users()) {
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>

View File

@ -199,19 +199,19 @@ module.exports = {
return new Promise((resolve, reject) => {
let 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) => {
all = Realm.Sync.User.all;
TestCase.assertArrayLength(all, 1);
assertIsSameUser(all[0], user1);
TestCase.assertArrayLength(Object.keys(all), 1);
assertIsSameUser(all[user1.identity], user1);
Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', (error, user2) => {
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.
assertIsSameUser(all[0], user2);
assertIsSameUser(all[1], user1);
assertIsSameUser(all[user2.identity], user2);
assertIsSameUser(all[user1.identity], user1);
resolve();
});
});

View File

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