Skip to content

Commit

Permalink
Add Subscription properties test
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed May 9, 2022
1 parent 12b5e56 commit 4209f77
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/subscription_test.dart
Expand Up @@ -225,4 +225,33 @@ Future<void> main([List<String>? args]) async {

await subscriptions.waitForSynchronization();
});

testSubscriptions('Subscription properties roundtrip', (realm) async {
final subscriptions = realm.subscriptions;

final before = DateTime.now().toUtc();

subscriptions.update((mutableSubscriptions) {
mutableSubscriptions.addOrUpdate(realm.all<Task>(), name: 'foobar');
});

await subscriptions.waitForStateChange(SubscriptionSetState.complete); // <-- Attempt at fixing windows

final after = DateTime.now().toUtc();
var s = subscriptions[0];

expect(s.name, 'foobar');
expect(s.objectClassName, 'Task');
expect(s.queryString, 'TRUEPREDICATE');
expect(s.createdAt.compareTo(before), isPositive); // >
expect(s.createdAt.compareTo(after), isNegative); // <
expect(s.createdAt, s.updatedAt);

subscriptions.update((mutableSubscriptions) {
mutableSubscriptions.addOrUpdate(realm.query<Task>(r'_id == $0', [ObjectId()]), name: 'foobar');
});

s = subscriptions[0]; // WARNING: Needed in order to refresh properties!
expect(s.createdAt.compareTo(s.updatedAt), isNegative); // <
});
}

0 comments on commit 4209f77

Please sign in to comment.