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,43 +271,40 @@ module.exports = {
|
|||||||
const expectedObjectsCount = 3;
|
const expectedObjectsCount = 3;
|
||||||
|
|
||||||
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
||||||
.then(() => {
|
.then(() => Realm.Sync.User.login('http://localhost:9080', username, 'password'))
|
||||||
return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => {
|
.then(user => {
|
||||||
return new Promise((resolve, reject) => {
|
const accessTokenRefreshed = this;
|
||||||
const accessTokenRefreshed = this;
|
let successCounter = 0;
|
||||||
let successCounter = 0;
|
|
||||||
|
|
||||||
let config = {
|
let config = {
|
||||||
sync: { user, url: `realm://localhost:9080/~/${realmName}` }
|
sync: { user, url: `realm://localhost:9080/~/${realmName}` }
|
||||||
};
|
};
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
Realm.openAsync(config, (error, realm) => {
|
||||||
|
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");
|
||||||
|
|
||||||
Realm.openAsync(config, (error, realm) => {
|
let firstDog = realm.objects('Dog')[0];
|
||||||
try {
|
TestCase.assertTrue(({}).hasOwnProperty.call(firstDog, 'name'), "Synced realm does not have an inffered schema");
|
||||||
if (error) {
|
TestCase.assertTrue(firstDog.name, "Synced realm object's property should have a value");
|
||||||
reject(error);
|
TestCase.assertTrue(firstDog.name.indexOf('Lassy') !== -1, "Synced realm object's property should contain the actual written value");
|
||||||
}
|
|
||||||
|
|
||||||
let actualObjectsCount = realm.objects('Dog').length;
|
const session = realm.syncSession;
|
||||||
TestCase.assertEqual(actualObjectsCount, expectedObjectsCount, "Synced realm does not contain the expected objects count");
|
TestCase.assertInstanceOf(session, Realm.Sync.Session);
|
||||||
|
TestCase.assertEqual(session.user.identity, user.identity);
|
||||||
let firstDog = realm.objects('Dog')[0];
|
TestCase.assertEqual(session.config.url, config.sync.url);
|
||||||
TestCase.assertTrue(({}).hasOwnProperty.call(firstDog, 'name'), "Synced realm does not have an inffered schema");
|
TestCase.assertEqual(session.config.user.identity, config.sync.user.identity);
|
||||||
TestCase.assertTrue(firstDog.name, "Synced realm object's property should have a value");
|
TestCase.assertEqual(session.state, 'active');
|
||||||
TestCase.assertTrue(firstDog.name.indexOf('Lassy') !== -1, "Synced realm object's property should contain the actual written value");
|
resolve();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
const session = realm.syncSession;
|
reject(e);
|
||||||
TestCase.assertInstanceOf(session, Realm.Sync.Session);
|
}
|
||||||
TestCase.assertEqual(session.user.identity, user.identity);
|
|
||||||
TestCase.assertEqual(session.config.url, config.sync.url);
|
|
||||||
TestCase.assertEqual(session.config.user.identity, config.sync.user.identity);
|
|
||||||
TestCase.assertEqual(session.state, 'active');
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
reject(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -317,26 +314,22 @@ module.exports = {
|
|||||||
const username = uuid();
|
const username = uuid();
|
||||||
const expectedObjectsCount = 3;
|
const expectedObjectsCount = 3;
|
||||||
|
|
||||||
|
const accessTokenRefreshed = this;
|
||||||
|
let successCounter = 0;
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
let config = {
|
||||||
const accessTokenRefreshed = this;
|
schema: [{ name: 'Dog', properties: { name: 'string' } }],
|
||||||
let successCounter = 0;
|
};
|
||||||
|
|
||||||
let config = {
|
return Realm.open(config).then(realm => {
|
||||||
schema: [{ name: 'Dog', properties: { name: 'string' } }],
|
realm.write(() => {
|
||||||
};
|
for (let i = 1; i <= 3; i++) {
|
||||||
|
realm.create('Dog', { name: `Lassy ${i}` });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Realm.open(config).then(realm => {
|
let actualObjectsCount = realm.objects('Dog').length;
|
||||||
realm.write(() => {
|
TestCase.assertEqual(actualObjectsCount, expectedObjectsCount, "Local realm does not contain the expected objects count");
|
||||||
for (let i = 1; i <= 3; i++) {
|
|
||||||
realm.create('Dog', { name: `Lassy ${i}` });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
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,37 +401,33 @@ module.exports = {
|
|||||||
const realmName = uuid();
|
const realmName = uuid();
|
||||||
|
|
||||||
return runOutOfProcess(__dirname + '/nested-list-helper.js', __dirname + '/schemas.js', username, realmName, REALM_MODULE_PATH)
|
return runOutOfProcess(__dirname + '/nested-list-helper.js', __dirname + '/schemas.js', username, realmName, REALM_MODULE_PATH)
|
||||||
.then(() => {
|
.then(() => Realm.Sync.User.login('http://localhost:9080', username, 'password'))
|
||||||
return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => {
|
.then(user => {
|
||||||
return new Promise((resolve, reject) => {
|
let config = {
|
||||||
let config = {
|
schema: [schemas.ParentObject, schemas.NameObject],
|
||||||
schema: [schemas.ParentObject, schemas.NameObject],
|
sync: { user, url: `realm://localhost:9080/~/${realmName}` }
|
||||||
sync: { user, url: `realm://localhost:9080/~/${realmName}` }
|
};
|
||||||
};
|
return Realm.open(config)
|
||||||
Realm.open(config).then(realm => {
|
}).then(realm => {
|
||||||
let objects = realm.objects('ParentObject');
|
let objects = realm.objects('ParentObject');
|
||||||
|
|
||||||
let json = JSON.stringify(objects);
|
let json = JSON.stringify(objects);
|
||||||
TestCase.assertEqual(json, '{"0":{"id":1,"name":{"0":{"family":"Larsen","given":{"0":"Hans","1":"Jørgen"},"prefix":{}},"1":{"family":"Hansen","given":{"0":"Ib"},"prefix":{}}}},"1":{"id":2,"name":{"0":{"family":"Petersen","given":{"0":"Gurli","1":"Margrete"},"prefix":{}}}}}');
|
TestCase.assertEqual(json, '{"0":{"id":1,"name":{"0":{"family":"Larsen","given":{"0":"Hans","1":"Jørgen"},"prefix":{}},"1":{"family":"Hansen","given":{"0":"Ib"},"prefix":{}}}},"1":{"id":2,"name":{"0":{"family":"Petersen","given":{"0":"Gurli","1":"Margrete"},"prefix":{}}}}}');
|
||||||
TestCase.assertEqual(objects.length, 2);
|
TestCase.assertEqual(objects.length, 2);
|
||||||
TestCase.assertEqual(objects[0].name.length, 2);
|
TestCase.assertEqual(objects[0].name.length, 2);
|
||||||
TestCase.assertEqual(objects[0].name[0].given.length, 2);
|
TestCase.assertEqual(objects[0].name[0].given.length, 2);
|
||||||
TestCase.assertEqual(objects[0].name[0].prefix.length, 0);
|
TestCase.assertEqual(objects[0].name[0].prefix.length, 0);
|
||||||
TestCase.assertEqual(objects[0].name[0].given[0], 'Hans');
|
TestCase.assertEqual(objects[0].name[0].given[0], 'Hans');
|
||||||
TestCase.assertEqual(objects[0].name[0].given[1], 'Jørgen')
|
TestCase.assertEqual(objects[0].name[0].given[1], 'Jørgen')
|
||||||
TestCase.assertEqual(objects[0].name[1].given.length, 1);
|
TestCase.assertEqual(objects[0].name[1].given.length, 1);
|
||||||
TestCase.assertEqual(objects[0].name[1].given[0], 'Ib');
|
TestCase.assertEqual(objects[0].name[1].given[0], 'Ib');
|
||||||
TestCase.assertEqual(objects[0].name[1].prefix.length, 0);
|
TestCase.assertEqual(objects[0].name[1].prefix.length, 0);
|
||||||
|
|
||||||
TestCase.assertEqual(objects[1].name.length, 1);
|
TestCase.assertEqual(objects[1].name.length, 1);
|
||||||
TestCase.assertEqual(objects[1].name[0].given.length, 2);
|
TestCase.assertEqual(objects[1].name[0].given.length, 2);
|
||||||
TestCase.assertEqual(objects[1].name[0].prefix.length, 0);
|
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[0], 'Gurli');
|
||||||
TestCase.assertEqual(objects[1].name[0].given[1], 'Margrete');
|
TestCase.assertEqual(objects[1].name[0].given[1], 'Margrete');
|
||||||
resolve();
|
|
||||||
}).catch(() => reject());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -606,60 +595,59 @@ module.exports = {
|
|||||||
const realmName = uuid();
|
const realmName = uuid();
|
||||||
|
|
||||||
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
||||||
.then(() => {
|
.then(() => Realm.Sync.User.login('http://localhost:9080', username, 'password'))
|
||||||
return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => {
|
.then(user => {
|
||||||
return new Promise((resolve, reject) => {
|
let config = {
|
||||||
let config = {
|
sync: {
|
||||||
sync: {
|
user,
|
||||||
user,
|
url: `realm://localhost:9080/~/${realmName}`
|
||||||
url: `realm://localhost:9080/~/${realmName}`
|
},
|
||||||
},
|
schema: [{ name: 'Dog', properties: { name: 'string' } }],
|
||||||
schema: [{ name: 'Dog', properties: { name: 'string' } }],
|
};
|
||||||
};
|
|
||||||
|
|
||||||
let realm = new Realm(config);
|
let realm = new Realm(config);
|
||||||
let unregisterFunc;
|
let unregisterFunc;
|
||||||
|
|
||||||
let writeDataFunc = () => {
|
let writeDataFunc = () => {
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
for (let i = 1; i <= 3; i++) {
|
for (let i = 1; i <= 3; i++) {
|
||||||
realm.create('Dog', { name: `Lassy ${i}` });
|
realm.create('Dog', { name: `Lassy ${i}` });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let syncFinished = false;
|
||||||
|
let failOnCall = false;
|
||||||
|
const progressCallback = (transferred, total) => {
|
||||||
|
if (failOnCall) {
|
||||||
|
reject(new Error("Progress callback should not be called after removeProgressNotification"));
|
||||||
}
|
}
|
||||||
|
|
||||||
let syncFinished = false;
|
syncFinished = transferred === total;
|
||||||
let failOnCall = false;
|
|
||||||
const progressCallback = (transferred, total) => {
|
|
||||||
if (failOnCall) {
|
|
||||||
reject(new Error("Progress callback should not be called after removeProgressNotification"));
|
|
||||||
}
|
|
||||||
|
|
||||||
syncFinished = transferred === total;
|
//unregister and write some new data.
|
||||||
|
if (syncFinished) {
|
||||||
|
failOnCall = true;
|
||||||
|
unregisterFunc();
|
||||||
|
|
||||||
//unregister and write some new data.
|
//use second callback to wait for sync finished
|
||||||
if (syncFinished) {
|
realm.syncSession.addProgressNotification('upload', 'reportIndefinitely', (transferred, transferable) => {
|
||||||
failOnCall = true;
|
if (transferred === transferable) {
|
||||||
unregisterFunc();
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
writeDataFunc();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
//use second callback to wait for sync finished
|
realm.syncSession.addProgressNotification('upload', 'reportIndefinitely', progressCallback);
|
||||||
realm.syncSession.addProgressNotification('upload', 'reportIndefinitely', (transferred, transferable) => {
|
|
||||||
if (transferred === transferable) {
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
writeDataFunc();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
realm.syncSession.addProgressNotification('upload', 'reportIndefinitely', progressCallback);
|
unregisterFunc = () => {
|
||||||
|
realm.syncSession.removeProgressNotification(progressCallback);
|
||||||
|
};
|
||||||
|
|
||||||
unregisterFunc = () => {
|
writeDataFunc();
|
||||||
realm.syncSession.removeProgressNotification(progressCallback);
|
|
||||||
};
|
|
||||||
|
|
||||||
writeDataFunc();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -671,36 +659,24 @@ module.exports = {
|
|||||||
|
|
||||||
const username = uuid();
|
const username = uuid();
|
||||||
const realmName = uuid();
|
const realmName = uuid();
|
||||||
|
let progressCalled = false;
|
||||||
|
|
||||||
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
||||||
.then(() => {
|
.then(() => Realm.Sync.User.login('http://localhost:9080', username, 'password'))
|
||||||
return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => {
|
.then(user => {
|
||||||
return new Promise((resolve, reject) => {
|
let config = {
|
||||||
let config = {
|
sync: {
|
||||||
sync: {
|
user,
|
||||||
user,
|
url: `realm://localhost:9080/~/${realmName}`
|
||||||
url: `realm://localhost:9080/~/${realmName}`
|
},
|
||||||
},
|
schema: [{ name: 'Dog', properties: { name: 'string' } }],
|
||||||
schema: [{ name: 'Dog', properties: { name: 'string' } }],
|
};
|
||||||
};
|
|
||||||
|
|
||||||
let progressCalled = false;
|
return Promise.race([
|
||||||
Realm.open(config)
|
Realm.open(config).progress((transferred, total) => { progressCalled = true; }),
|
||||||
.progress((transferred, total) => {
|
new Promise((_, reject) => setTimeout(() => reject("Progress Notifications API failed to call progress callback for Realm constructor"), 5000))
|
||||||
progressCalled = true;
|
]);
|
||||||
})
|
}).then(() => TestCase.assertTrue(progressCalled));
|
||||||
.then(() => {
|
|
||||||
TestCase.assertTrue(progressCalled);
|
|
||||||
resolve();
|
|
||||||
})
|
|
||||||
.catch((e) => reject(e));
|
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
reject("Progress Notifications API failed to call progress callback for Realm constructor");
|
|
||||||
}, 5000);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
testProgressNotificationsForRealmOpenAsync() {
|
testProgressNotificationsForRealmOpenAsync() {
|
||||||
@ -712,37 +688,36 @@ module.exports = {
|
|||||||
const realmName = uuid();
|
const realmName = uuid();
|
||||||
|
|
||||||
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
||||||
.then(() => {
|
.then(() => Realm.Sync.User.login('http://localhost:9080', username, 'password'))
|
||||||
return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => {
|
.then(user => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let config = {
|
let config = {
|
||||||
sync: {
|
sync: {
|
||||||
user,
|
user,
|
||||||
url: `realm://localhost:9080/~/${realmName}`
|
url: `realm://localhost:9080/~/${realmName}`
|
||||||
},
|
},
|
||||||
schema: [{ name: 'Dog', properties: { name: 'string' } }],
|
schema: [{ name: 'Dog', properties: { name: 'string' } }],
|
||||||
};
|
};
|
||||||
|
|
||||||
let progressCalled = false;
|
let progressCalled = false;
|
||||||
|
|
||||||
Realm.openAsync(config,
|
Realm.openAsync(config,
|
||||||
(error, realm) => {
|
(error, realm) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TestCase.assertTrue(progressCalled);
|
TestCase.assertTrue(progressCalled);
|
||||||
resolve();
|
resolve();
|
||||||
},
|
},
|
||||||
(transferred, total) => {
|
(transferred, total) => {
|
||||||
progressCalled = true;
|
progressCalled = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
reject("Progress Notifications API failed to call progress callback for Realm constructor");
|
reject("Progress Notifications API failed to call progress callback for Realm constructor");
|
||||||
}, 5000);
|
}, 5000);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -757,38 +732,37 @@ module.exports = {
|
|||||||
const realmName = uuid();
|
const realmName = uuid();
|
||||||
|
|
||||||
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
||||||
.then(() => {
|
.then(() => Realm.Sync.User.login('http://localhost:9080', username, 'password'))
|
||||||
return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => {
|
.then(user => {
|
||||||
let config = {
|
let config = {
|
||||||
sync: {
|
sync: {
|
||||||
user: user,
|
user: user,
|
||||||
url: `realm://localhost:9080/~/${realmName}`,
|
url: `realm://localhost:9080/~/${realmName}`,
|
||||||
partial: true,
|
partial: true,
|
||||||
error: (session, error) => console.log(error)
|
error: (session, error) => console.log(error)
|
||||||
},
|
},
|
||||||
schema: [{ name: 'Dog', properties: { name: 'string' } }]
|
schema: [{ name: 'Dog', properties: { name: 'string' } }]
|
||||||
};
|
};
|
||||||
|
|
||||||
Realm.deleteFile(config);
|
Realm.deleteFile(config);
|
||||||
const realm = new Realm(config);
|
const realm = new Realm(config);
|
||||||
TestCase.assertEqual(realm.objects('Dog').length, 0);
|
TestCase.assertEqual(realm.objects('Dog').length, 0);
|
||||||
var results = realm.objects('Dog').filtered("name == 'Lassy 1'");
|
var results = realm.objects('Dog').filtered("name == 'Lassy 1'");
|
||||||
var subscription = results.subscribe();
|
var subscription = results.subscribe();
|
||||||
TestCase.assertEqual(subscription.state, Realm.Sync.SubscriptionState.Creating);
|
TestCase.assertEqual(subscription.state, Realm.Sync.SubscriptionState.Creating);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
subscription.addListener((subscription, state) => {
|
subscription.addListener((subscription, state) => {
|
||||||
if (state == Realm.Sync.SubscriptionState.Complete) {
|
if (state == Realm.Sync.SubscriptionState.Complete) {
|
||||||
TestCase.assertEqual(results.length, 1);
|
TestCase.assertEqual(results.length, 1);
|
||||||
TestCase.assertTrue(results[0].name === 'Lassy 1', "The object is not synced correctly");
|
TestCase.assertTrue(results[0].name === 'Lassy 1', "The object is not synced correctly");
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
setTimeout(function() {
|
|
||||||
reject("listener never called");
|
|
||||||
}, 5000);
|
|
||||||
});
|
});
|
||||||
})
|
setTimeout(function() {
|
||||||
})
|
reject("listener never called");
|
||||||
|
}, 5000);
|
||||||
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
testPartialSyncAnonymous_ResultsListener() {
|
testPartialSyncAnonymous_ResultsListener() {
|
||||||
@ -801,38 +775,37 @@ module.exports = {
|
|||||||
const realmName = uuid();
|
const realmName = uuid();
|
||||||
|
|
||||||
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
||||||
.then(() => {
|
.then(() => Realm.Sync.User.login('http://localhost:9080', username, 'password'))
|
||||||
return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => {
|
.then(user => {
|
||||||
let config = {
|
let config = {
|
||||||
sync: {
|
sync: {
|
||||||
user: user,
|
user: user,
|
||||||
url: `realm://localhost:9080/~/${realmName}`,
|
url: `realm://localhost:9080/~/${realmName}`,
|
||||||
partial: true,
|
partial: true,
|
||||||
error: (session, error) => console.log(error)
|
error: (session, error) => console.log(error)
|
||||||
},
|
},
|
||||||
schema: [{ name: 'Dog', properties: { name: 'string' } }]
|
schema: [{ name: 'Dog', properties: { name: 'string' } }]
|
||||||
};
|
};
|
||||||
|
|
||||||
Realm.deleteFile(config);
|
Realm.deleteFile(config);
|
||||||
const realm = new Realm(config);
|
const realm = new Realm(config);
|
||||||
TestCase.assertEqual(realm.objects('Dog').length, 0);
|
TestCase.assertEqual(realm.objects('Dog').length, 0);
|
||||||
var results = realm.objects('Dog').filtered("name == 'Lassy 1'");
|
var results = realm.objects('Dog').filtered("name == 'Lassy 1'");
|
||||||
var subscription = results.subscribe();
|
var subscription = results.subscribe();
|
||||||
TestCase.assertEqual(subscription.state, Realm.Sync.SubscriptionState.Creating);
|
TestCase.assertEqual(subscription.state, Realm.Sync.SubscriptionState.Creating);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
results.addListener((collection, changes) => {
|
results.addListener((collection, changes) => {
|
||||||
if (subscription.state === Realm.Sync.SubscriptionState.Complete) {
|
if (subscription.state === Realm.Sync.SubscriptionState.Complete) {
|
||||||
TestCase.assertEqual(collection.length, 1);
|
TestCase.assertEqual(collection.length, 1);
|
||||||
TestCase.assertTrue(collection[0].name === 'Lassy 1', "The object is not synced correctly");
|
TestCase.assertTrue(collection[0].name === 'Lassy 1', "The object is not synced correctly");
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
setTimeout(function() {
|
|
||||||
reject("listener never called");
|
|
||||||
}, 5000);
|
|
||||||
});
|
});
|
||||||
})
|
setTimeout(function() {
|
||||||
})
|
reject("listener never called");
|
||||||
|
}, 5000);
|
||||||
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
testPartialSyncMultipleSubscriptions() {
|
testPartialSyncMultipleSubscriptions() {
|
||||||
@ -845,56 +818,55 @@ module.exports = {
|
|||||||
const realmName = uuid();
|
const realmName = uuid();
|
||||||
|
|
||||||
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
||||||
.then(() => {
|
.then(() => Realm.Sync.User.login('http://localhost:9080', username, 'password'))
|
||||||
return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => {
|
.then(user => {
|
||||||
let config = {
|
let config = {
|
||||||
sync: {
|
sync: {
|
||||||
user: user,
|
user: user,
|
||||||
url: `realm://localhost:9080/~/${realmName}`,
|
url: `realm://localhost:9080/~/${realmName}`,
|
||||||
partial: true,
|
partial: true,
|
||||||
error: (session, error) => console.log(error)
|
error: (session, error) => console.log(error)
|
||||||
},
|
},
|
||||||
schema: [{ name: 'Dog', properties: { name: 'string' } }]
|
schema: [{ name: 'Dog', properties: { name: 'string' } }]
|
||||||
};
|
};
|
||||||
|
|
||||||
Realm.deleteFile(config);
|
Realm.deleteFile(config);
|
||||||
const realm = new Realm(config);
|
const realm = new Realm(config);
|
||||||
TestCase.assertEqual(realm.objects('Dog').length, 0);
|
TestCase.assertEqual(realm.objects('Dog').length, 0);
|
||||||
var results1 = realm.objects('Dog').filtered("name == 'Lassy 1'");
|
var results1 = realm.objects('Dog').filtered("name == 'Lassy 1'");
|
||||||
var results2 = realm.objects('Dog').filtered("name == 'Lassy 2'");
|
var results2 = realm.objects('Dog').filtered("name == 'Lassy 2'");
|
||||||
var subscription1 = results1.subscribe();
|
var subscription1 = results1.subscribe();
|
||||||
var subscription2 = results2.subscribe();
|
var subscription2 = results2.subscribe();
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let called1 = false;
|
let called1 = false;
|
||||||
let called2 = false;
|
let called2 = false;
|
||||||
results1.addListener((collection, changeset) => {
|
results1.addListener((collection, changeset) => {
|
||||||
if (subscription1.state == Realm.Sync.SubscriptionState.Complete) {
|
if (subscription1.state == Realm.Sync.SubscriptionState.Complete) {
|
||||||
TestCase.assertEqual(collection.length, 1);
|
TestCase.assertEqual(collection.length, 1);
|
||||||
TestCase.assertTrue(collection[0].name === 'Lassy 1', "The object is not synced correctly");
|
TestCase.assertTrue(collection[0].name === 'Lassy 1', "The object is not synced correctly");
|
||||||
called1 = true;
|
called1 = true;
|
||||||
if (called1 && called2) {
|
if (called1 && called2) {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
results2.addListener((collection, changeset) => {
|
|
||||||
if (subscription2.state == Realm.Sync.SubscriptionState.Complete) {
|
|
||||||
TestCase.assertEqual(collection.length, 1);
|
|
||||||
TestCase.assertTrue(collection[0].name === 'Lassy 2', "The object is not synced correctly");
|
|
||||||
called2 = true;
|
|
||||||
if (called1 && called2) {
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
reject("listener never called");
|
|
||||||
}, 5000);
|
|
||||||
});
|
});
|
||||||
})
|
results2.addListener((collection, changeset) => {
|
||||||
})
|
if (subscription2.state == Realm.Sync.SubscriptionState.Complete) {
|
||||||
|
TestCase.assertEqual(collection.length, 1);
|
||||||
|
TestCase.assertTrue(collection[0].name === 'Lassy 2', "The object is not synced correctly");
|
||||||
|
called2 = true;
|
||||||
|
if (called1 && called2) {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
reject("listener never called");
|
||||||
|
}, 5000);
|
||||||
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
testPartialSyncFailing() {
|
testPartialSyncFailing() {
|
||||||
@ -907,23 +879,22 @@ module.exports = {
|
|||||||
const realmName = uuid();
|
const realmName = uuid();
|
||||||
|
|
||||||
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
||||||
.then(() => {
|
.then(() => Realm.Sync.User.login('http://localhost:9080', username, 'password'))
|
||||||
return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => {
|
.then(user => {
|
||||||
let config = {
|
let config = {
|
||||||
sync: {
|
sync: {
|
||||||
user: user,
|
user: user,
|
||||||
url: `realm://localhost:9080/~/${realmName}`,
|
url: `realm://localhost:9080/~/${realmName}`,
|
||||||
partial: false, // <---- calling subscribe should fail
|
partial: false, // <---- calling subscribe should fail
|
||||||
error: (session, error) => console.log(error)
|
error: (session, error) => console.log(error)
|
||||||
},
|
},
|
||||||
schema: [{ name: 'Dog', properties: { name: 'string' } }]
|
schema: [{ name: 'Dog', properties: { name: 'string' } }]
|
||||||
};
|
};
|
||||||
|
|
||||||
Realm.deleteFile(config);
|
Realm.deleteFile(config);
|
||||||
const realm = new Realm(config);
|
const realm = new Realm(config);
|
||||||
TestCase.assertEqual(realm.objects('Dog').length, 0);
|
TestCase.assertEqual(realm.objects('Dog').length, 0);
|
||||||
TestCase.assertThrows(function () { var subscription = realm.objects('Dog').filtered("name == 'Lassy 1'").subscribe(); } );
|
TestCase.assertThrows(function () { var subscription = realm.objects('Dog').filtered("name == 'Lassy 1'").subscribe(); } );
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -937,36 +908,35 @@ module.exports = {
|
|||||||
const realmName = uuid();
|
const realmName = uuid();
|
||||||
|
|
||||||
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
return runOutOfProcess(__dirname + '/download-api-helper.js', username, realmName, REALM_MODULE_PATH)
|
||||||
.then(() => {
|
.then(() => Realm.Sync.User.login('http://localhost:9080', username, 'password'))
|
||||||
return Realm.Sync.User.login('http://localhost:9080', username, 'password').then(user => {
|
.then(user => {
|
||||||
let config = {
|
let config = {
|
||||||
sync: {
|
sync: {
|
||||||
user: user,
|
user: user,
|
||||||
url: `realm://localhost:9080/~/${realmName}`,
|
url: `realm://localhost:9080/~/${realmName}`,
|
||||||
partial: true,
|
partial: true,
|
||||||
error: (session, error) => console.log(error)
|
error: (session, error) => console.log(error)
|
||||||
},
|
},
|
||||||
schema: [{ name: 'Dog', properties: { name: 'string' } }]
|
schema: [{ name: 'Dog', properties: { name: 'string' } }]
|
||||||
};
|
};
|
||||||
|
|
||||||
Realm.deleteFile(config);
|
Realm.deleteFile(config);
|
||||||
const realm = new Realm(config);
|
const realm = new Realm(config);
|
||||||
var results = realm.objects('Dog').filtered("name == 'Lassy 1'");
|
var results = realm.objects('Dog').filtered("name == 'Lassy 1'");
|
||||||
var subscription = results.subscribe();
|
var subscription = results.subscribe();
|
||||||
TestCase.assertEqual(subscription.state, Realm.Sync.SubscriptionState.Creating);
|
TestCase.assertEqual(subscription.state, Realm.Sync.SubscriptionState.Creating);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
results.addListener((collection, changes) => {
|
results.addListener((collection, changes) => {
|
||||||
if (subscription.state === Realm.Sync.SubscriptionState.Complete) {
|
if (subscription.state === Realm.Sync.SubscriptionState.Complete) {
|
||||||
subscription.unsubscribe();
|
subscription.unsubscribe();
|
||||||
}
|
}
|
||||||
if (subscription.state === Realm.Sync.SubscriptionState.Invalidated) {
|
if (subscription.state === Realm.Sync.SubscriptionState.Invalidated) {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
setTimeout(function() {
|
|
||||||
reject("listener never called");
|
|
||||||
}, 5000);
|
|
||||||
});
|
});
|
||||||
|
setTimeout(function() {
|
||||||
|
reject("listener never called");
|
||||||
|
}, 5000);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user