Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed Jul 5, 2024
1 parent 5dd5e5e commit ce868ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
8 changes: 7 additions & 1 deletion packages/realm_dart/lib/src/handles/native/init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@ EJsonValue encodeRealmValue(RealmValue value) {
return toEJson(v);
}

RealmValue decodeRealmValue(EJsonValue ejson) => RealmValue.from(fromEJson(ejson, allowCustom: false));
RealmValue decodeRealmValue(EJsonValue ejson) {
Object? decoded = fromEJson(ejson, allowCustom: false);
if (decoded is DBRef) {
// return RealmValue.from(null);
}
return RealmValue.from(decoded);
}

/// @nodoc
// Initializes Realm library
Expand Down
20 changes: 11 additions & 9 deletions packages/realm_dart/test/serialization_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,19 @@ void main() {
expect(fromEJson<RealmValue>(r.toEJson()), r);
}
});
}

test('RealmValue with RealmObject', () {
// load custom codecs for Player and Game. This is done to test that it
// doesn't interfere with the RealmValue codecs.
Realm(Configuration.inMemory([Player.schema, Game.schema]));
test('RealmObject', () {
// load custom codecs for Player and Game. This is done to test that it
// doesn't interfere with the RealmValue codecs.
Realm(Configuration.inMemory([Player.schema, Game.schema]));

final rv = RealmValue.from(Player('Christian Eriksen'));
expect(rv.toEJson(), {'\$id': 'Christian Eriksen', '\$ref': 'Player'});
expect(fromEJson<DBRef>(rv.toEJson()), isA<DBRef>().having((r) => r.id, '\$id', 'Christian Eriksen'));
});
}
final p = Player('Christian Eriksen');
final rv = RealmValue.from(p);
expect(rv.toEJson(), {'\$id': 'Christian Eriksen', '\$ref': 'Player'});
expect(fromEJson<DBRef>(rv.toEJson()), isA<DBRef>().having((r) => r.id, '\$id', 'Christian Eriksen'));
expect((fromEJson<RealmValue>(rv.toEJson()).value as Player).name, p.name);
});
});

test('Decimal128', () {
Expand Down

0 comments on commit ce868ec

Please sign in to comment.