mirror of
https://github.com/status-im/realm-js.git
synced 2025-02-17 09:06:26 +00:00
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
|
* - `user` - a valid User object on success
|
||||||
*/
|
*/
|
||||||
login(server, username, password, callback) {}
|
login(server, username, password, callback) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Login a sync user using an external login provider.
|
* Login a sync user using an external login provider.
|
||||||
* @param {string} server - authentication server
|
* @param {string} server - authentication server
|
||||||
@ -91,6 +92,7 @@ class User {
|
|||||||
* - `user` - a valid User object on success
|
* - `user` - a valid User object on success
|
||||||
*/
|
*/
|
||||||
loginWithProvider(server, provider, providerToken, callback) {}
|
loginWithProvider(server, provider, providerToken, callback) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new user using the username/password provider
|
* Create a new user using the username/password provider
|
||||||
* @param {string} server - authentication server
|
* @param {string} server - authentication server
|
||||||
@ -101,6 +103,7 @@ class User {
|
|||||||
* - `user` - a valid User object on success
|
* - `user` - a valid User object on success
|
||||||
*/
|
*/
|
||||||
create(server, username, password, callback) {}
|
create(server, username, password, callback) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an admin user for the given authentication server with an existing token
|
* Create an admin user for the given authentication server with an existing token
|
||||||
* @param {string} server - authentication server
|
* @param {string} server - authentication server
|
||||||
@ -108,4 +111,18 @@ class User {
|
|||||||
* @return {User} - admin user populated with the given token and server
|
* @return {User} - admin user populated with the given token and server
|
||||||
*/
|
*/
|
||||||
adminUser(server, adminToken) {}
|
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) {
|
function failOnError(error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
throw new Error(`Error ${error} was not expected`);
|
throw new Error(`Error ${error} was not expected`);
|
||||||
@ -221,14 +215,14 @@ module.exports = {
|
|||||||
TestCase.assertArrayLength(Object.keys(all), 0);
|
TestCase.assertArrayLength(Object.keys(all), 0);
|
||||||
|
|
||||||
callbackTest((callback) => Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', callback), (error, user1) => {
|
callbackTest((callback) => Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', callback), (error, user1) => {
|
||||||
rejectOnError(error, reject);
|
failOnError(error);
|
||||||
|
|
||||||
all = Realm.Sync.User.all;
|
all = Realm.Sync.User.all;
|
||||||
TestCase.assertArrayLength(Object.keys(all), 1);
|
TestCase.assertArrayLength(Object.keys(all), 1);
|
||||||
assertIsSameUser(all[user1.identity], 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) => {
|
||||||
rejectOnError(error, reject);
|
failOnError(error);
|
||||||
|
|
||||||
all = Realm.Sync.User.all;
|
all = Realm.Sync.User.all;
|
||||||
TestCase.assertArrayLength(Object.keys(all), 2);
|
TestCase.assertArrayLength(Object.keys(all), 2);
|
||||||
@ -256,11 +250,11 @@ module.exports = {
|
|||||||
TestCase.assertUndefined(Realm.Sync.User.current);
|
TestCase.assertUndefined(Realm.Sync.User.current);
|
||||||
|
|
||||||
callbackTest((callback) => Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', callback), (error, user1) => {
|
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);
|
assertIsSameUser(Realm.Sync.User.current, user1);
|
||||||
|
|
||||||
Realm.Sync.User.register('http://localhost:9080', uuid(), 'password', (error, user2) => {
|
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.');
|
TestCase.assertThrows(() => Realm.Sync.User.current, 'We expect Realm.Sync.User.current to throw if > 1 user.');
|
||||||
user2.logout();
|
user2.logout();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user