mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-12 15:24:18 +00:00
Eliminate some gratuitous promise nesting in tests
This commit is contained in:
parent
61126aef53
commit
302db024bf
@ -271,22 +271,21 @@ module.exports = {
|
||||
const expectedObjectsCount = 3;
|
||||
|
||||
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
||||
.then(() => {
|
||||
return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => {
|
||||
return new Promise((resolve, reject) => {
|
||||
.then(() => Realm.Sync.User.login('http://localhost:9080', username, 'password'))
|
||||
.then(user => {
|
||||
const accessTokenRefreshed = this;
|
||||
let successCounter = 0;
|
||||
|
||||
let config = {
|
||||
sync: { user, url: `realm://localhost:9080/~/${realmName}` }
|
||||
};
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
Realm.openAsync(config, (error, realm) => {
|
||||
try {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
let actualObjectsCount = realm.objects('Dog').length;
|
||||
TestCase.assertEqual(actualObjectsCount, expectedObjectsCount, "Synced realm does not contain the expected objects count");
|
||||
|
||||
@ -295,7 +294,6 @@ module.exports = {
|
||||
TestCase.assertTrue(firstDog.name, "Synced realm object's property should have a value");
|
||||
TestCase.assertTrue(firstDog.name.indexOf('Lassy') !== -1, "Synced realm object's property should contain the actual written value");
|
||||
|
||||
|
||||
const session = realm.syncSession;
|
||||
TestCase.assertInstanceOf(session, Realm.Sync.Session);
|
||||
TestCase.assertEqual(session.user.identity, user.identity);
|
||||
@ -310,15 +308,12 @@ module.exports = {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
testRealmOpenLocalRealm() {
|
||||
const username = uuid();
|
||||
const expectedObjectsCount = 3;
|
||||
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const accessTokenRefreshed = this;
|
||||
let successCounter = 0;
|
||||
|
||||
@ -326,7 +321,7 @@ module.exports = {
|
||||
schema: [{ name: 'Dog', properties: { name: 'string' } }],
|
||||
};
|
||||
|
||||
Realm.open(config).then(realm => {
|
||||
return Realm.open(config).then(realm => {
|
||||
realm.write(() => {
|
||||
for (let i = 1; i <= 3; i++) {
|
||||
realm.create('Dog', { name: `Lassy ${i}` });
|
||||
@ -335,8 +330,6 @@ module.exports = {
|
||||
|
||||
let actualObjectsCount = realm.objects('Dog').length;
|
||||
TestCase.assertEqual(actualObjectsCount, expectedObjectsCount, "Local realm does not contain the expected objects count");
|
||||
resolve();
|
||||
}).catch(error => reject(error));
|
||||
});
|
||||
},
|
||||
|
||||
@ -408,14 +401,14 @@ module.exports = {
|
||||
const realmName = uuid();
|
||||
|
||||
return runOutOfProcess(__dirname + '/nested-list-helper.js', __dirname + '/schemas.js', username, realmName, REALM_MODULE_PATH)
|
||||
.then(() => {
|
||||
return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => {
|
||||
return new Promise((resolve, reject) => {
|
||||
.then(() => Realm.Sync.User.login('http://localhost:9080', username, 'password'))
|
||||
.then(user => {
|
||||
let config = {
|
||||
schema: [schemas.ParentObject, schemas.NameObject],
|
||||
sync: { user, url: `realm://localhost:9080/~/${realmName}` }
|
||||
};
|
||||
Realm.open(config).then(realm => {
|
||||
return Realm.open(config)
|
||||
}).then(realm => {
|
||||
let objects = realm.objects('ParentObject');
|
||||
|
||||
let json = JSON.stringify(objects);
|
||||
@ -435,10 +428,6 @@ module.exports = {
|
||||
TestCase.assertEqual(objects[1].name[0].prefix.length, 0);
|
||||
TestCase.assertEqual(objects[1].name[0].given[0], 'Gurli');
|
||||
TestCase.assertEqual(objects[1].name[0].given[1], 'Margrete');
|
||||
resolve();
|
||||
}).catch(() => reject());
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
@ -606,9 +595,8 @@ module.exports = {
|
||||
const realmName = uuid();
|
||||
|
||||
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
||||
.then(() => {
|
||||
return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => {
|
||||
return new Promise((resolve, reject) => {
|
||||
.then(() => Realm.Sync.User.login('http://localhost:9080', username, 'password'))
|
||||
.then(user => {
|
||||
let config = {
|
||||
sync: {
|
||||
user,
|
||||
@ -628,6 +616,7 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
let syncFinished = false;
|
||||
let failOnCall = false;
|
||||
const progressCallback = (transferred, total) => {
|
||||
@ -661,7 +650,6 @@ module.exports = {
|
||||
writeDataFunc();
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
testProgressNotificationsForRealmOpen() {
|
||||
@ -671,11 +659,11 @@ module.exports = {
|
||||
|
||||
const username = uuid();
|
||||
const realmName = uuid();
|
||||
let progressCalled = false;
|
||||
|
||||
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
||||
.then(() => {
|
||||
return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => {
|
||||
return new Promise((resolve, reject) => {
|
||||
.then(() => Realm.Sync.User.login('http://localhost:9080', username, 'password'))
|
||||
.then(user => {
|
||||
let config = {
|
||||
sync: {
|
||||
user,
|
||||
@ -684,23 +672,11 @@ module.exports = {
|
||||
schema: [{ name: 'Dog', properties: { name: 'string' } }],
|
||||
};
|
||||
|
||||
let progressCalled = false;
|
||||
Realm.open(config)
|
||||
.progress((transferred, total) => {
|
||||
progressCalled = true;
|
||||
})
|
||||
.then(() => {
|
||||
TestCase.assertTrue(progressCalled);
|
||||
resolve();
|
||||
})
|
||||
.catch((e) => reject(e));
|
||||
|
||||
setTimeout(function() {
|
||||
reject("Progress Notifications API failed to call progress callback for Realm constructor");
|
||||
}, 5000);
|
||||
});
|
||||
});
|
||||
});
|
||||
return Promise.race([
|
||||
Realm.open(config).progress((transferred, total) => { progressCalled = true; }),
|
||||
new Promise((_, reject) => setTimeout(() => reject("Progress Notifications API failed to call progress callback for Realm constructor"), 5000))
|
||||
]);
|
||||
}).then(() => TestCase.assertTrue(progressCalled));
|
||||
},
|
||||
|
||||
testProgressNotificationsForRealmOpenAsync() {
|
||||
@ -712,8 +688,8 @@ module.exports = {
|
||||
const realmName = uuid();
|
||||
|
||||
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
||||
.then(() => {
|
||||
return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => {
|
||||
.then(() => Realm.Sync.User.login('http://localhost:9080', username, 'password'))
|
||||
.then(user => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let config = {
|
||||
sync: {
|
||||
@ -744,7 +720,6 @@ module.exports = {
|
||||
}, 5000);
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
testPartialSyncAnonymous_SubscriptionListener() {
|
||||
@ -757,8 +732,8 @@ module.exports = {
|
||||
const realmName = uuid();
|
||||
|
||||
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
||||
.then(() => {
|
||||
return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => {
|
||||
.then(() => Realm.Sync.User.login('http://localhost:9080', username, 'password'))
|
||||
.then(user => {
|
||||
let config = {
|
||||
sync: {
|
||||
user: user,
|
||||
@ -787,8 +762,7 @@ module.exports = {
|
||||
reject("listener never called");
|
||||
}, 5000);
|
||||
});
|
||||
})
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
testPartialSyncAnonymous_ResultsListener() {
|
||||
@ -801,8 +775,8 @@ module.exports = {
|
||||
const realmName = uuid();
|
||||
|
||||
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
||||
.then(() => {
|
||||
return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => {
|
||||
.then(() => Realm.Sync.User.login('http://localhost:9080', username, 'password'))
|
||||
.then(user => {
|
||||
let config = {
|
||||
sync: {
|
||||
user: user,
|
||||
@ -831,8 +805,7 @@ module.exports = {
|
||||
reject("listener never called");
|
||||
}, 5000);
|
||||
});
|
||||
})
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
testPartialSyncMultipleSubscriptions() {
|
||||
@ -845,8 +818,8 @@ module.exports = {
|
||||
const realmName = uuid();
|
||||
|
||||
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
||||
.then(() => {
|
||||
return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => {
|
||||
.then(() => Realm.Sync.User.login('http://localhost:9080', username, 'password'))
|
||||
.then(user => {
|
||||
let config = {
|
||||
sync: {
|
||||
user: user,
|
||||
@ -893,8 +866,7 @@ module.exports = {
|
||||
reject("listener never called");
|
||||
}, 5000);
|
||||
});
|
||||
})
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
testPartialSyncFailing() {
|
||||
@ -907,8 +879,8 @@ module.exports = {
|
||||
const realmName = uuid();
|
||||
|
||||
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
||||
.then(() => {
|
||||
return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => {
|
||||
.then(() => Realm.Sync.User.login('http://localhost:9080', username, 'password'))
|
||||
.then(user => {
|
||||
let config = {
|
||||
sync: {
|
||||
user: user,
|
||||
@ -924,7 +896,6 @@ module.exports = {
|
||||
TestCase.assertEqual(realm.objects('Dog').length, 0);
|
||||
TestCase.assertThrows(function () { var subscription = realm.objects('Dog').filtered("name == 'Lassy 1'").subscribe(); } );
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
testPartialSyncUnsubscribe() {
|
||||
@ -937,8 +908,8 @@ module.exports = {
|
||||
const realmName = uuid();
|
||||
|
||||
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
||||
.then(() => {
|
||||
return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => {
|
||||
.then(() => Realm.Sync.User.login('http://localhost:9080', username, 'password'))
|
||||
.then(user => {
|
||||
let config = {
|
||||
sync: {
|
||||
user: user,
|
||||
@ -968,7 +939,6 @@ module.exports = {
|
||||
}, 5000);
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
testClientReset() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user