Skip to content

Commit

Permalink
Add lines for test readability
Browse files Browse the repository at this point in the history
  • Loading branch information
cbullinger committed Dec 26, 2023
1 parent 0d15649 commit 925ad06
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions examples/dart/test/manage_sync_subscription_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,18 @@ void main() {
Credentials.emailPassword("[email protected]", "abc123");
currentUser = await app.logIn(credentials);
});

tearDownAll(() async {
await app.currentUser?.logOut();
});

setUp(() async {
final config = Configuration.flexibleSync(
currentUser,
[Plane.schema, Train.schema, Boat.schema],
path: 'flex-${generateRandomString(10)}.realm',
);

realm = Realm(config);
await realm.subscriptions.waitForSynchronization();
final planeQuery = realm.all<Plane>();
Expand All @@ -66,6 +69,7 @@ void main() {
});
await realm.subscriptions.waitForSynchronization();
});

tearDown(() async {
realm.subscriptions.update((MutableSubscriptionSet mutableSubscriptions) {
mutableSubscriptions.clear();
Expand All @@ -75,6 +79,7 @@ void main() {
await Future.delayed(Duration(milliseconds: 300));
Realm.deleteRealm(realm.config.path);
});

// Starting with 2 subscriptions from setUp: all-planes, long-trains
test('Add query to subscription set', () async {
// :snippet-start: add-subscription
Expand All @@ -87,14 +92,16 @@ void main() {
});
await realm.subscriptions.waitForSynchronization();
// :snippet-end:
expect(realm.subscriptions.length, 3); // +1 planes
expect(realm.subscriptions.length, 3); // +1 subscription
});

test('Get subscriptions', () async {
// :snippet-start: get-subscriptions
final subscriptions = realm.subscriptions;
// :snippet-end:
expect(subscriptions.length, 2); // 0
expect(subscriptions.length, 2); // +0
});

test('Wait for subscription changes to sync', () async {
// :snippet-start: wait-for-subscription-change
await realm.subscriptions.waitForSynchronization();
Expand All @@ -111,9 +118,10 @@ void main() {
name: 'long-trains', update: true);
});
// :snippet-end:
expect(realm.subscriptions.length, 2); // 0
expect(realm.subscriptions.length, 2); // +0
expect(realm.subscriptions.findByName('long-trains')?.queryString.trim(), "numCars > 10");
});

test('Remove subscription by query', () async {
// :snippet-start: remove-subscriptions-by-query
realm.subscriptions.update((MutableSubscriptionSet mutableSubscriptions) {
Expand All @@ -122,6 +130,7 @@ void main() {
// :snippet-end:
expect(realm.subscriptions.length, 1); // -1
});

test('Remove subscription by name', () async {
// :snippet-start: remove-subscriptions-by-name
realm.subscriptions.update((MutableSubscriptionSet mutableSubscriptions) {
Expand All @@ -130,6 +139,7 @@ void main() {
// :snippet-end:
expect(realm.subscriptions.length, 1); // -1
});

test('Remove all subscriptions by reference', () async {
// :snippet-start: remove-subscriptions-by-reference
final sub = realm.subscriptions[0];
Expand All @@ -139,6 +149,7 @@ void main() {
// :snippet-end:
expect(realm.subscriptions.length, 1); // -1
});

test('Remove all subscriptions by object type', () async {
// :snippet-start: remove-subscriptions-by-object-type
realm.subscriptions.update((MutableSubscriptionSet mutableSubscriptions) {
Expand All @@ -147,6 +158,7 @@ void main() {
// :snippet-end:
expect(realm.subscriptions.length, 1); // -1
});

test('Remove all subscriptions', () async {
// :snippet-start: remove-all-subscriptions
realm.subscriptions.update((MutableSubscriptionSet mutableSubscriptions) {
Expand All @@ -155,6 +167,7 @@ void main() {
// :snippet-end:
expect(realm.subscriptions, isEmpty); // clear all
});

test('Add query with subscribe api', () async {
// :snippet-start: add-subscription-subscribe-api
final boatQuery = realm.all<Boat>();
Expand All @@ -167,6 +180,7 @@ void main() {
expect(realm.subscriptions.findByName("boats")?.queryString.trim(), "TRUEPREDICATE");
expect(realm.subscriptions.findByName("big-planes")?.queryString.trim(), "numSeats > 100");
});

test('Update query with subscribe api', () async {
final planeQuery = realm.query<Plane>("numSeats > 100");
planeQuery.subscribe(name: "big-planes");
Expand All @@ -182,6 +196,7 @@ void main() {
final updatedSubscription = realm.subscriptions.findByName("big-planes");
expect(updatedSubscription?.queryString.trim(), "numSeats > 200");
});

test('Wait for query to sync with subscribe api', () async {
realm.write(() {
realm.deleteAll<Plane>();
Expand All @@ -202,6 +217,7 @@ void main() {
expect(realm.subscriptions.length, 3); // +1
expect(bigPlaneQuery.length, 1);
});

test('Wait with timeout with subscribe api', () async {
realm.write(() {
realm.deleteAll<Plane>();
Expand All @@ -223,6 +239,7 @@ void main() {
expect(bigPlaneQuery.length, 2);

});

test('Remove subscription with unsubscribe api', () async {
final planeQuery = realm.all<Plane>();
final trainSubscription = realm.subscriptions.findByName("long-trains")?.queryString;
Expand Down

0 comments on commit 925ad06

Please sign in to comment.