From 50f8ba23da5a0a9062bcd981d806b58dbb905e55 Mon Sep 17 00:00:00 2001 From: "thomashii@dukefirehawk.com" Date: Wed, 5 May 2021 13:01:25 +0800 Subject: [PATCH] Update test cases --- CHANGELOG.md | 2 +- .../angel_orm_test/lib/src/has_map_test.dart | 23 ++++---- .../angel_orm_test/lib/src/has_one_test.dart | 54 ++++++++++++------- .../angel_orm_test/lib/src/models/tree.g.dart | 17 +++--- 4 files changed, 58 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d46699d1..ff7c383c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,7 +37,7 @@ * Migrated angel_orm_generator to 4.0.0 (0/0 tests passed) * Migrated angel_migration_runner to 3.0.0 (0/0 tests passed) * Migrated angel_orm_test to 3.0.0 (0/0 tests passed) -* Migrated angel_orm_postgres to 3.0.0 (27/54 tests passed) +* Migrated angel_orm_postgres to 3.0.0 (30/54 tests passed) * Update orm-sdk-2.12.x boilerplate (in progress) <= Milestone 2 diff --git a/packages/orm/angel_orm_test/lib/src/has_map_test.dart b/packages/orm/angel_orm_test/lib/src/has_map_test.dart index 223e891c..a7f231f6 100644 --- a/packages/orm/angel_orm_test/lib/src/has_map_test.dart +++ b/packages/orm/angel_orm_test/lib/src/has_map_test.dart @@ -19,9 +19,12 @@ hasMapTests(FutureOr Function() createExecutor, query.values ..value = {'foo': 'bar'} ..list = ['1', 2, 3.0]; - var model = await (query.insert(executor) as FutureOr); - print(model.toJson()); - expect(model, HasMap(value: {'foo': 'bar'}, list: ['1', 2, 3.0])); + var modelOpt = await (query.insert(executor)); + expect(modelOpt.isPresent, true); + modelOpt.ifPresent((model) { + print(model.toJson()); + expect(model, HasMap(value: {'foo': 'bar'}, list: ['1', 2, 3.0])); + }); }); test('update', () async { @@ -29,11 +32,13 @@ hasMapTests(FutureOr Function() createExecutor, query.values ..value = {'foo': 'bar'} ..list = ['1', 2, 3.0]; - var model = await (query.insert(executor) as FutureOr); - print(model.toJson()); - - query = HasMapQuery()..values.copyFrom(model); - expect(await query.updateOne(executor), model); + var modelOpt = await (query.insert(executor)); + expect(modelOpt.isPresent, true); + modelOpt.ifPresent((model) async { + print(model.toJson()); + query = HasMapQuery()..values.copyFrom(model); + expect(await query.updateOne(executor), model); + }); }); group('query', () { @@ -73,7 +78,7 @@ hasMapTests(FutureOr Function() createExecutor, }); test('property equals', () async { - var query = HasMapQuery()..where!.value['foo'].asString!.equals('bar'); + var query = HasMapQuery()..where!.value['foo'].asString?.equals('bar'); expect(await query.get(executor), [initialValue]); query = HasMapQuery()..where!.value['foo'].asString!.equals('baz'); diff --git a/packages/orm/angel_orm_test/lib/src/has_one_test.dart b/packages/orm/angel_orm_test/lib/src/has_one_test.dart index b9cc30ef..0b79fd0b 100644 --- a/packages/orm/angel_orm_test/lib/src/has_one_test.dart +++ b/packages/orm/angel_orm_test/lib/src/has_one_test.dart @@ -20,11 +20,14 @@ hasOneTests(FutureOr Function() createExecutor, test('sets to null if no child', () async { print(LegQuery().compile(Set())); var query = LegQuery()..where!.id.equals(int.parse(originalLeg!.id!)); - var leg = await (query.getOne(executor) as FutureOr); - print(leg.toJson()); - expect(leg.name, originalLeg!.name); - expect(leg.id, originalLeg!.id); - expect(leg.foot, isNull); + var legOpt = await (query.getOne(executor)); + expect(legOpt.isPresent, true); + legOpt.ifPresent((leg) { + print(leg.toJson()); + expect(leg.name, originalLeg?.name); + expect(leg.id, originalLeg?.id); + expect(leg.foot, isNull); + }); }); test('can fetch one foot', () async { @@ -32,14 +35,19 @@ hasOneTests(FutureOr Function() createExecutor, ..values.legId = int.parse(originalLeg!.id!) ..values.nToes = 5.64; var legQuery = LegQuery()..where!.id.equals(int.parse(originalLeg!.id!)); - var foot = await (footQuery.insert(executor) as FutureOr); - var leg = await (legQuery.getOne(executor) as FutureOr); - - expect(leg.name, originalLeg!.name); - expect(leg.id, originalLeg!.id); - expect(leg.foot, isNotNull); - expect(leg.foot!.id, foot.id); - expect(leg.foot!.nToes, foot.nToes); + var footOpt = await (footQuery.insert(executor)); + var legOpt = await (legQuery.getOne(executor)); + expect(footOpt.isPresent, true); + expect(legOpt.isPresent, true); + legOpt.ifPresent((leg) { + expect(leg.name, originalLeg!.name); + expect(leg.id, originalLeg!.id); + footOpt.ifPresent((foot) { + expect(leg.foot, isNotNull); + expect(leg.foot!.id, foot.id); + expect(leg.foot!.nToes, foot.nToes); + }); + }); }); test('only fetches one foot even if there are multiple', () async { @@ -47,13 +55,19 @@ hasOneTests(FutureOr Function() createExecutor, ..values.legId = int.parse(originalLeg!.id!) ..values.nToes = 24; var legQuery = LegQuery()..where!.id.equals(int.parse(originalLeg!.id!)); - var foot = await (footQuery.insert(executor) as FutureOr); - var leg = await (legQuery.getOne(executor) as FutureOr); - expect(leg.name, originalLeg!.name); - expect(leg.id, originalLeg!.id); - expect(leg.foot, isNotNull); - expect(leg.foot!.id, foot.id); - expect(leg.foot!.nToes, foot.nToes); + var footOpt = await (footQuery.insert(executor)); + var legOpt = await (legQuery.getOne(executor)); + expect(footOpt.isPresent, true); + expect(legOpt.isPresent, true); + legOpt.ifPresent((leg) { + expect(leg.name, originalLeg!.name); + expect(leg.id, originalLeg!.id); + expect(leg.foot, isNotNull); + footOpt.ifPresent((foot) { + expect(leg.foot!.id, foot.id); + expect(leg.foot!.nToes, foot.nToes); + }); + }); }); test('sets foot on update', () async { diff --git a/packages/orm/angel_orm_test/lib/src/models/tree.g.dart b/packages/orm/angel_orm_test/lib/src/models/tree.g.dart index 8e270244..43ac16b5 100644 --- a/packages/orm/angel_orm_test/lib/src/models/tree.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/tree.g.dart @@ -104,9 +104,10 @@ class TreeQuery extends Query { updatedAt: (row[2] as DateTime?), rings: (row[3] as int?)); if (row.length > 4) { - model = model.copyWith(fruits: [ - FruitQuery.parseRow(row.skip(4).take(5).toList()).firstOrNull - ]); + var modelOpt = FruitQuery.parseRow(row.skip(4).take(5).toList()); + modelOpt.ifPresent((m) { + model = model.copyWith(fruits: [m]); + }); } return Optional.ofNullable(model); } @@ -362,8 +363,8 @@ class Tree extends _Tree { this.createdAt, this.updatedAt, this.rings, - List<_Fruit?>? fruits}) - : this.fruits = List.unmodifiable(fruits ?? []); + List<_Fruit> fruits = const []}) + : this.fruits = List.unmodifiable(fruits); /// A unique identifier corresponding to this item. @override @@ -388,13 +389,13 @@ class Tree extends _Tree { DateTime? createdAt, DateTime? updatedAt, int? rings, - List<_Fruit?>? fruits}) { + List<_Fruit> fruits = const []}) { return Tree( id: id ?? this.id, createdAt: createdAt ?? this.createdAt, updatedAt: updatedAt ?? this.updatedAt, rings: rings ?? this.rings, - fruits: fruits ?? this.fruits); + fruits: fruits); } bool operator ==(other) { @@ -527,7 +528,7 @@ class TreeSerializer extends Codec { fruits: map['fruits'] is Iterable ? List.unmodifiable(((map['fruits'] as Iterable).whereType()) .map(FruitSerializer.fromMap)) - : null); + : []); } static Map toMap(_Tree model) {