From 7adeff9a63b4cd15e6dc9bd158639940e22ed6af Mon Sep 17 00:00:00 2001 From: "thomashii@dukefirehawk.com" Date: Thu, 6 May 2021 13:30:08 +0800 Subject: [PATCH] Updated test cases --- CHANGELOG.md | 2 +- .../angel_orm_test/lib/src/models/book.g.dart | 15 ++++--- .../angel_orm_test/lib/src/models/car.g.dart | 2 +- .../lib/src/models/custom_expr.g.dart | 10 +++-- .../lib/src/models/email_indexed.g.dart | 33 +++++++-------- .../lib/src/models/has_car.g.dart | 2 +- .../lib/src/models/has_map.g.dart | 33 ++++++++------- .../angel_orm_test/lib/src/models/leg.g.dart | 10 +++-- .../lib/src/models/order.g.dart | 10 +++-- .../angel_orm_test/lib/src/models/tree.g.dart | 4 +- .../lib/src/models/unorthodox.g.dart | 40 +++++++++++-------- .../angel_orm_test/lib/src/models/user.g.dart | 8 ++-- 12 files changed, 92 insertions(+), 77 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79650303..551ca807 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 (50/54 tests passed) +* Migrated angel_orm_postgres to 3.0.0 (51/54 tests passed) * Update orm-sdk-2.12.x boilerplate (in progress) <= Milestone 2 diff --git a/packages/orm/angel_orm_test/lib/src/models/book.g.dart b/packages/orm/angel_orm_test/lib/src/models/book.g.dart index 2bf69058..0b810270 100644 --- a/packages/orm/angel_orm_test/lib/src/models/book.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/book.g.dart @@ -116,15 +116,18 @@ class BookQuery extends Query { updatedAt: (row[2] as DateTime?), name: (row[5] as String?)); if (row.length > 6) { - model = model.copyWith( - author: AuthorQuery.parseRow(row.skip(6).take(4).toList()).value); + var modelOpt = AuthorQuery.parseRow(row.skip(6).take(4).toList()); + modelOpt.ifPresent((m) { + model = model.copyWith(author: m); + }); } if (row.length > 10) { - model = model.copyWith( - partnerAuthor: - AuthorQuery.parseRow(row.skip(10).take(4).toList()).value); + var modelOpt = AuthorQuery.parseRow(row.skip(10).take(4).toList()); + modelOpt.ifPresent((m) { + model = model.copyWith(partnerAuthor: m); + }); } - return Optional.ofNullable(model); + return Optional.of(model); } @override diff --git a/packages/orm/angel_orm_test/lib/src/models/car.g.dart b/packages/orm/angel_orm_test/lib/src/models/car.g.dart index 4e9900e5..0c3dddff 100644 --- a/packages/orm/angel_orm_test/lib/src/models/car.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/car.g.dart @@ -87,7 +87,7 @@ class CarQuery extends Query { description: (row[4] as String?), familyFriendly: (row[5] as bool?), recalledAt: (row[6] as DateTime?)); - return Optional.ofNullable(model); + return Optional.of(model); } @override diff --git a/packages/orm/angel_orm_test/lib/src/models/custom_expr.g.dart b/packages/orm/angel_orm_test/lib/src/models/custom_expr.g.dart index a3807a19..94886c9a 100644 --- a/packages/orm/angel_orm_test/lib/src/models/custom_expr.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/custom_expr.g.dart @@ -94,7 +94,7 @@ class NumbersQuery extends Query { createdAt: (row[1] as DateTime?), updatedAt: (row[2] as DateTime?), two: (row[3] as int?)); - return Optional.ofNullable(model); + return Optional.of(model); } @override @@ -202,10 +202,12 @@ class AlphabetQuery extends Query { updatedAt: (row[2] as DateTime?), value: (row[3] as String?)); if (row.length > 5) { - model = model.copyWith( - numbers: NumbersQuery.parseRow(row.skip(5).take(4).toList()).value); + var modelOpt = NumbersQuery.parseRow(row.skip(5).take(4).toList()); + modelOpt.ifPresent((m) { + model = model.copyWith(numbers: m); + }); } - return Optional.ofNullable(model); + return Optional.of(model); } @override diff --git a/packages/orm/angel_orm_test/lib/src/models/email_indexed.g.dart b/packages/orm/angel_orm_test/lib/src/models/email_indexed.g.dart index f8ecb1b3..49f2dce9 100644 --- a/packages/orm/angel_orm_test/lib/src/models/email_indexed.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/email_indexed.g.dart @@ -108,10 +108,10 @@ class RoleQuery extends Query { } var model = Role(role: (row[0] as String?)); if (row.length > 1) { - var rowData = UserQuery.parseRow(row.skip(1).take(3).toList()); - if (rowData.isPresent) { - model = model.copyWith(users: [rowData.value]); - } + var rowDataOpt = UserQuery.parseRow(row.skip(1).take(3).toList()); + rowDataOpt.ifPresent((m) { + model = model.copyWith(users: [m]); + }); } return Optional.ofNullable(model); } @@ -265,17 +265,16 @@ class RoleUserQuery extends Query { } var model = RoleUser(); if (row.length > 2) { - var r = RoleQuery.parseRow(row.skip(2).take(1).toList()); - if (r.isPresent) { - model = model.copyWith(role: r.value); - } + var modelOpt = RoleQuery.parseRow(row.skip(2).take(1).toList()); + modelOpt.ifPresent((m) { + model = model.copyWith(role: m); + }); } if (row.length > 3) { - var u = UserQuery.parseRow(row.skip(3).take(3).toList()); - if (u.isPresent) { - model = model.copyWith( - user: UserQuery.parseRow(row.skip(3).take(3).toList()).value); - } + var modelOpt = UserQuery.parseRow(row.skip(3).take(3).toList()); + modelOpt.ifPresent((m) { + model = model.copyWith(user: m); + }); } return Optional.ofNullable(model); } @@ -387,14 +386,16 @@ class UserQuery extends Query { name: (row[1] as String?), password: (row[2] as String?)); if (row.length > 3) { - var d = RoleQuery.parseRow(row.skip(3).take(1).toList()); + var modelOpt = RoleQuery.parseRow(row.skip(3).take(1).toList()); + modelOpt.ifPresent((m) { + model = model.copyWith(roles: [m]); + }); - model = model.copyWith(roles: [d.value]); // roles: [RoleQuery.parseRow(row.skip(3).take(1).toList())] // .where((x) => x != null) // .toList()); } - return Optional.ofNullable(model); + return Optional.of(model); } @override diff --git a/packages/orm/angel_orm_test/lib/src/models/has_car.g.dart b/packages/orm/angel_orm_test/lib/src/models/has_car.g.dart index 09a7192e..c28f3fee 100644 --- a/packages/orm/angel_orm_test/lib/src/models/has_car.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/has_car.g.dart @@ -74,7 +74,7 @@ class HasCarQuery extends Query { createdAt: (row[1] as DateTime?), updatedAt: (row[2] as DateTime?), type: row[3] == null ? null : CarType.values[(row[3] as int)]); - return Optional.ofNullable(model); + return Optional.of(model); } @override diff --git a/packages/orm/angel_orm_test/lib/src/models/has_map.g.dart b/packages/orm/angel_orm_test/lib/src/models/has_map.g.dart index 23183e8b..cde41fb2 100644 --- a/packages/orm/angel_orm_test/lib/src/models/has_map.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/has_map.g.dart @@ -67,10 +67,8 @@ class HasMapQuery extends Query { if (row.every((x) => x == null)) { return Optional.empty(); } - var model = HasMap( - value: (row[0] as Map?), - list: (row[1] as List?)); - return Optional.ofNullable(model); + var model = HasMap(value: (row[0]), list: (row[1])); + return Optional.of(model); } @override @@ -100,16 +98,16 @@ class HasMapQueryValues extends MapQueryValues { return {'list': 'jsonb'}; } - Map? get value { - return (values['value'] as Map?); + Map get value { + return (values['value'] as Map); } - set value(Map? value) => values['value'] = value; - List? get list { - return (json.decode((values['list'] as String)) as List?); + set value(Map value) => values['value'] = value; + List get list { + return (json.decode((values['list'] as String)) as List); } - set list(List? value) => values['list'] = json.encode(value); + set list(List value) => values['list'] = json.encode(value); void copyFrom(HasMap model) { value = model.value; list = model.list; @@ -122,16 +120,17 @@ class HasMapQueryValues extends MapQueryValues { @generatedSerializable class HasMap implements _HasMap { - const HasMap({this.value, this.list}); + const HasMap({this.value = const {}, this.list = const []}); @override - final Map? value; + final Map value; @override - final List? list; + final List list; - HasMap copyWith({Map? value, List? list}) { - return HasMap(value: value ?? this.value, list: list ?? this.list); + HasMap copyWith( + {Map value = const {}, List list = const []}) { + return HasMap(value: value, list: list); } bool operator ==(other) { @@ -188,10 +187,10 @@ class HasMapSerializer extends Codec { return HasMap( value: map['value'] is Map ? (map['value'] as Map).cast() - : null, + : {}, list: map['list'] is Iterable ? (map['list'] as Iterable).cast().toList() - : null); + : []); } static Map toMap(_HasMap model) { diff --git a/packages/orm/angel_orm_test/lib/src/models/leg.g.dart b/packages/orm/angel_orm_test/lib/src/models/leg.g.dart index f4c6d690..c1fde06f 100644 --- a/packages/orm/angel_orm_test/lib/src/models/leg.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/leg.g.dart @@ -104,10 +104,12 @@ class LegQuery extends Query { updatedAt: (row[2] as DateTime?), name: (row[3] as String?)); if (row.length > 4) { - model = model.copyWith( - foot: FootQuery.parseRow(row.skip(4).take(5).toList()).firstOrNull); + var modelOpt = FootQuery.parseRow(row.skip(4).take(5).toList()); + modelOpt.ifPresent((m) { + model = model.copyWith(foot: m); + }); } - return Optional.ofNullable(model); + return Optional.of(model); } @override @@ -221,7 +223,7 @@ class FootQuery extends Query { updatedAt: (row[2] as DateTime?), legId: (row[3] as int?), nToes: double.tryParse(row[4].toString())); - return Optional.ofNullable(model); + return Optional.of(model); } @override diff --git a/packages/orm/angel_orm_test/lib/src/models/order.g.dart b/packages/orm/angel_orm_test/lib/src/models/order.g.dart index 774f53b6..3a852b34 100644 --- a/packages/orm/angel_orm_test/lib/src/models/order.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/order.g.dart @@ -111,10 +111,12 @@ class OrderQuery extends Query { orderDate: (row[5] as DateTime?), shipperId: (row[6] as int?)); if (row.length > 7) { - model = model.copyWith( - customer: CustomerQuery.parseRow(row.skip(7).take(3).toList()).value); + var modelOpt = CustomerQuery.parseRow(row.skip(7).take(3).toList()); + modelOpt.ifPresent((m) { + model = model.copyWith(customer: m); + }); } - return Optional.ofNullable(model); + return Optional.of(model); } @override @@ -264,7 +266,7 @@ class CustomerQuery extends Query { id: row[0].toString(), createdAt: (row[1] as DateTime?), updatedAt: (row[2] as DateTime?)); - return Optional.ofNullable(model); + return Optional.of(model); } @override 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 43ac16b5..aeb46054 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 @@ -109,7 +109,7 @@ class TreeQuery extends Query { model = model.copyWith(fruits: [m]); }); } - return Optional.ofNullable(model); + return Optional.of(model); } @override @@ -280,7 +280,7 @@ class FruitQuery extends Query { updatedAt: (row[2] as DateTime?), treeId: (row[3] as int?), commonName: (row[4] as String?)); - return Optional.ofNullable(model); + return Optional.of(model); } @override diff --git a/packages/orm/angel_orm_test/lib/src/models/unorthodox.g.dart b/packages/orm/angel_orm_test/lib/src/models/unorthodox.g.dart index 5753407a..20c8baed 100644 --- a/packages/orm/angel_orm_test/lib/src/models/unorthodox.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/unorthodox.g.dart @@ -148,7 +148,7 @@ class UnorthodoxQuery extends Query { return Optional.empty(); } var model = Unorthodox(name: (row[0] as String?)); - return Optional.ofNullable(model); + return Optional.of(model); } @override @@ -260,24 +260,30 @@ class WeirdJoinQuery extends Query { } var model = WeirdJoin(id: (row[0] as int?)); if (row.length > 2) { - model = model.copyWith( - unorthodox: UnorthodoxQuery.parseRow(row.skip(2).take(1).toList()) - .firstOrNull); + var modelOpt = UnorthodoxQuery.parseRow(row.skip(2).take(1).toList()); + modelOpt.ifPresent((m) { + model = model.copyWith(unorthodox: m); + }); } if (row.length > 3) { - model = model.copyWith( - song: SongQuery.parseRow(row.skip(3).take(5).toList()).firstOrNull); + var modelOpt = SongQuery.parseRow(row.skip(3).take(5).toList()); + modelOpt.ifPresent((m) { + model = model.copyWith(song: m); + }); } if (row.length > 8) { - model = model.copyWith(numbas: [ - NumbaQuery.parseRow(row.skip(8).take(2).toList()).firstOrNull - ]); + var modelOpt = NumbaQuery.parseRow(row.skip(8).take(2).toList()); + modelOpt.ifPresent((m) { + model = model.copyWith(numbas: [m]); + }); } if (row.length > 10) { - model = model.copyWith( - foos: [FooQuery.parseRow(row.skip(10).take(1).toList()).firstOrNull]); + var modelOpt = FooQuery.parseRow(row.skip(10).take(1).toList()); + modelOpt.ifPresent((m) { + model = model.copyWith(foos: [m]); + }); } - return Optional.ofNullable(model); + return Optional.of(model); } @override @@ -450,7 +456,7 @@ class SongQuery extends Query { updatedAt: (row[2] as DateTime?), weirdJoinId: (row[3] as int?), title: (row[4] as String?)); - return Optional.ofNullable(model); + return Optional.of(model); } @override @@ -564,7 +570,7 @@ class NumbaQuery extends Query { return Optional.empty(); } var model = Numba(i: (row[0] as int?), parent: (row[1] as int?)); - return Optional.ofNullable(model); + return Optional.of(model); } @override @@ -659,9 +665,9 @@ class FooQuery extends Query { } var model = Foo(bar: (row[0] as String?)); if (row.length > 1) { - var weirdOpt = WeirdJoinQuery.parseRow(row.skip(1).take(2).toList()); - weirdOpt.ifPresent((value) { - model = model.copyWith(weirdJoins: [value]); + var modelOpt = WeirdJoinQuery.parseRow(row.skip(1).take(2).toList()); + modelOpt.ifPresent((m) { + model = model.copyWith(weirdJoins: [m]); }); } return Optional.ofNullable(model); diff --git a/packages/orm/angel_orm_test/lib/src/models/user.g.dart b/packages/orm/angel_orm_test/lib/src/models/user.g.dart index 10e612fa..b5498622 100644 --- a/packages/orm/angel_orm_test/lib/src/models/user.g.dart +++ b/packages/orm/angel_orm_test/lib/src/models/user.g.dart @@ -461,12 +461,12 @@ class RoleQuery extends Query { updatedAt: (row[2] as DateTime?), name: (row[3] as String?)); if (row.length > 4) { - var userOpt = UserQuery.parseRow(row.skip(4).take(6).toList()); - userOpt.ifPresent((user) { - model = model.copyWith(users: [user]); + var modelOpt = UserQuery.parseRow(row.skip(4).take(6).toList()); + modelOpt.ifPresent((m) { + model = model.copyWith(users: [m]); }); } - return Optional.ofNullable(model); + return Optional.of(model); } @override