Skip to content

Commit

Permalink
Remove some pointless promises in subscription tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tgoyne committed May 15, 2019
1 parent 891aaef commit 1d22afd
Showing 1 changed file with 31 additions and 42 deletions.
73 changes: 31 additions & 42 deletions tests/js/subscription-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,32 @@ function uuid() {
function getRealm() {
const AUTH_URL = 'http://127.0.0.1:9080';
const REALM_URL = 'realm://127.0.0.1:9080/~/' + uuid().replace("-", "_");
return new Promise((resolve, reject) => {
Realm.Sync.User.login(AUTH_URL, Realm.Sync.Credentials.nickname("admin", true))
.then((user) => {
const schemas = [
{
name: 'Parent',
properties: {
name: { type: 'string' },
child: 'ObjectA',
}
},
{
name: 'ObjectA',
properties: {
name: { type: 'string' },
parents: { type: 'linkingObjects', objectType: 'Parent', property: 'child' },
}
},
];

const config = user.createConfiguration({
schema: schemas,
sync: {
url: REALM_URL,
return Realm.Sync.User.login(AUTH_URL, Realm.Sync.Credentials.nickname("admin", true))
.then((user) => {
const schemas = [
{
name: 'Parent',
properties: {
name: { type: 'string' },
child: 'ObjectA',
}
});
resolve(new Realm(config));
},
{
name: 'ObjectA',
properties: {
name: { type: 'string' },
parents: { type: 'linkingObjects', objectType: 'Parent', property: 'child' },
}
},
];

const config = user.createConfiguration({
schema: schemas,
sync: {
url: REALM_URL,
}
});
return new Realm(config);
});
}

Expand Down Expand Up @@ -126,12 +124,9 @@ module.exports = {

testSubscriptionWrapperProperties() {
return getRealm().then(realm => {
return new Promise((resolve, reject) => {
const subscription = realm.objects("ObjectA").subscribe("test");
TestCase.assertEqual(subscription.name, "test");
TestCase.assertEqual(subscription.state, Realm.Sync.SubscriptionState.Creating);
resolve();
});
const subscription = realm.objects("ObjectA").subscribe("test");
TestCase.assertEqual(subscription.name, "test");
TestCase.assertEqual(subscription.state, Realm.Sync.SubscriptionState.Creating);
});
},

Expand Down Expand Up @@ -328,21 +323,15 @@ module.exports = {

testSubscribeWithoutName() {
return getRealm().then(realm => {
return new Promise((resolve, reject) => {
let query = realm.objects("ObjectA");
query.subscribe({ update: true, timeToLive: 1000}); // Missing name, doesn't throw
resolve();
});
let query = realm.objects("ObjectA");
query.subscribe({ update: true, timeToLive: 1000}); // Missing name, doesn't throw
});
},

testSubscribeWithMisspelledConfigParameter() {
return getRealm().then(realm => {
return new Promise((resolve, reject) => {
let query = realm.objects("ObjectA");
TestCase.assertThrowsContaining(() => query.subscribe({ naem: "myName" }), "Unexpected property in subscription options: 'naem'");
resolve();
});
let query = realm.objects("ObjectA");
TestCase.assertThrowsContaining(() => query.subscribe({ naem: "myName" }), "Unexpected property in subscription options: 'naem'");
});
},

Expand Down

0 comments on commit 1d22afd

Please sign in to comment.