Skip to content

Commit

Permalink
Add test case for default values (local realm only)
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed Sep 14, 2022
1 parent ace3c42 commit 45bd665
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/realm_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,28 @@ Future<void> main([List<String>? args]) async {
expect(dan.friends, [alice, bob, carol]);
expect(danAgain.isManaged, isFalse); // dan wasn't updated
});

test('Default value corner cases', () {
final realm = getRealm(Configuration.local([Friend.schema, Party.schema]));

final f1 = Friend('Ben', age: 50);
realm.write(() => realm.add(f1));
expect(realm.all<Friend>().first.age, 50);

final f2 = Friend('Ben', age: 42); // will skip setValue, since default is 42
realm.write(() => realm.add(f2, update: true));
expect(realm.all<Friend>().first.age, 42);

final f3 = Friend('Ben', age: 30);
realm.write(() => realm.add(f3, update: true));
expect(realm.all<Friend>().first.age, 30);

final f4 = Friend('Ben')..age = 42; // will not skip setValue, since set after construction
realm.write(() => realm.add(f4, update: true));
expect(realm.all<Friend>().first.age, 42);

expect([f1, f2, f3, f4], [f4, f3, f2, f1]);
});
}

extension _IterableEx<T> on Iterable<T> {
Expand Down

0 comments on commit 45bd665

Please sign in to comment.