From 14e75f12bceef3093a52e94226313ad935552291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Vind?= Date: Thu, 10 Nov 2016 18:21:57 -0800 Subject: [PATCH] Documentation for .all and .current --- docs/sync.js | 17 +++++++++++++++++ tests/js/user-tests.js | 14 ++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/docs/sync.js b/docs/sync.js index 41dd0409..4bdbe4fa 100644 --- a/docs/sync.js +++ b/docs/sync.js @@ -81,6 +81,7 @@ class User { * - `user` - a valid User object on success */ login(server, username, password, callback) {} + /** * Login a sync user using an external login provider. * @param {string} server - authentication server @@ -91,6 +92,7 @@ class User { * - `user` - a valid User object on success */ loginWithProvider(server, provider, providerToken, callback) {} + /** * Create a new user using the username/password provider * @param {string} server - authentication server @@ -101,6 +103,7 @@ class User { * - `user` - a valid User object on success */ create(server, username, password, callback) {} + /** * Create an admin user for the given authentication server with an existing token * @param {string} server - authentication server @@ -108,4 +111,18 @@ class User { * @return {User} - admin user populated with the given token and server */ adminUser(server, adminToken) {} + + /** + * A dictionary containing users that are currently logged in. + * The keys in the dictionary are user identities, values are corresponding User objects. + * @type {object} + */ + get all() {}; + + /** + * Get the currently logged in user. + * Throws error if > 1 user logged in, returns undefined if no users logged in. + * @type {User} + */ + get current() {}; } diff --git a/tests/js/user-tests.js b/tests/js/user-tests.js index 83202b62..a8f4031a 100644 --- a/tests/js/user-tests.js +++ b/tests/js/user-tests.js @@ -65,12 +65,6 @@ function assertIsAuthError(error, code, type) { } } -function rejectOnError(error, reject) { - if (error) { - reject(error); - } -} - function failOnError(error) { if (error) { throw new Error(`Error ${error} was not expected`); @@ -221,14 +215,14 @@ module.exports = { TestCase.assertArrayLength(Object.keys(all), 0); callbackTest((callback) => Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', callback), (error, user1) => { - rejectOnError(error, reject); + failOnError(error); all = Realm.Sync.User.all; TestCase.assertArrayLength(Object.keys(all), 1); assertIsSameUser(all[user1.identity], user1); Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', (error, user2) => { - rejectOnError(error, reject); + failOnError(error); all = Realm.Sync.User.all; TestCase.assertArrayLength(Object.keys(all), 2); @@ -256,11 +250,11 @@ module.exports = { TestCase.assertUndefined(Realm.Sync.User.current); callbackTest((callback) => Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', callback), (error, user1) => { - rejectOnError(error, reject); + failOnError(error); assertIsSameUser(Realm.Sync.User.current, user1); Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', (error, user2) => { - rejectOnError(error, reject); + failOnError(error); TestCase.assertThrows(() => Realm.Sync.User.current, 'We expect Realm.Sync.User.current to throw if > 1 user.'); user2.logout();