Merge branch 'al-sync-user-tests' of https://github.com/realm/realm-js into al-sync-user-tests
This commit is contained in:
commit
e5ac11bb14
17
docs/sync.js
17
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() {};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue