Updated test cases

This commit is contained in:
thomashii@dukefirehawk.com 2021-05-06 13:30:08 +08:00
parent 05bea04db7
commit 7adeff9a63
12 changed files with 92 additions and 77 deletions

View file

@ -37,7 +37,7 @@
* Migrated angel_orm_generator to 4.0.0 (0/0 tests passed) * 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_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_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 * Update orm-sdk-2.12.x boilerplate (in progress) <= Milestone 2

View file

@ -116,15 +116,18 @@ class BookQuery extends Query<Book, BookQueryWhere> {
updatedAt: (row[2] as DateTime?), updatedAt: (row[2] as DateTime?),
name: (row[5] as String?)); name: (row[5] as String?));
if (row.length > 6) { if (row.length > 6) {
model = model.copyWith( var modelOpt = AuthorQuery.parseRow(row.skip(6).take(4).toList());
author: AuthorQuery.parseRow(row.skip(6).take(4).toList()).value); modelOpt.ifPresent((m) {
model = model.copyWith(author: m);
});
} }
if (row.length > 10) { if (row.length > 10) {
model = model.copyWith( var modelOpt = AuthorQuery.parseRow(row.skip(10).take(4).toList());
partnerAuthor: modelOpt.ifPresent((m) {
AuthorQuery.parseRow(row.skip(10).take(4).toList()).value); model = model.copyWith(partnerAuthor: m);
});
} }
return Optional.ofNullable(model); return Optional.of(model);
} }
@override @override

View file

@ -87,7 +87,7 @@ class CarQuery extends Query<Car, CarQueryWhere> {
description: (row[4] as String?), description: (row[4] as String?),
familyFriendly: (row[5] as bool?), familyFriendly: (row[5] as bool?),
recalledAt: (row[6] as DateTime?)); recalledAt: (row[6] as DateTime?));
return Optional.ofNullable(model); return Optional.of(model);
} }
@override @override

View file

@ -94,7 +94,7 @@ class NumbersQuery extends Query<Numbers, NumbersQueryWhere> {
createdAt: (row[1] as DateTime?), createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?), updatedAt: (row[2] as DateTime?),
two: (row[3] as int?)); two: (row[3] as int?));
return Optional.ofNullable(model); return Optional.of(model);
} }
@override @override
@ -202,10 +202,12 @@ class AlphabetQuery extends Query<Alphabet, AlphabetQueryWhere> {
updatedAt: (row[2] as DateTime?), updatedAt: (row[2] as DateTime?),
value: (row[3] as String?)); value: (row[3] as String?));
if (row.length > 5) { if (row.length > 5) {
model = model.copyWith( var modelOpt = NumbersQuery.parseRow(row.skip(5).take(4).toList());
numbers: NumbersQuery.parseRow(row.skip(5).take(4).toList()).value); modelOpt.ifPresent((m) {
model = model.copyWith(numbers: m);
});
} }
return Optional.ofNullable(model); return Optional.of(model);
} }
@override @override

View file

@ -108,10 +108,10 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
} }
var model = Role(role: (row[0] as String?)); var model = Role(role: (row[0] as String?));
if (row.length > 1) { if (row.length > 1) {
var rowData = UserQuery.parseRow(row.skip(1).take(3).toList()); var rowDataOpt = UserQuery.parseRow(row.skip(1).take(3).toList());
if (rowData.isPresent) { rowDataOpt.ifPresent((m) {
model = model.copyWith(users: [rowData.value]); model = model.copyWith(users: [m]);
} });
} }
return Optional.ofNullable(model); return Optional.ofNullable(model);
} }
@ -265,17 +265,16 @@ class RoleUserQuery extends Query<RoleUser, RoleUserQueryWhere> {
} }
var model = RoleUser(); var model = RoleUser();
if (row.length > 2) { if (row.length > 2) {
var r = RoleQuery.parseRow(row.skip(2).take(1).toList()); var modelOpt = RoleQuery.parseRow(row.skip(2).take(1).toList());
if (r.isPresent) { modelOpt.ifPresent((m) {
model = model.copyWith(role: r.value); model = model.copyWith(role: m);
} });
} }
if (row.length > 3) { if (row.length > 3) {
var u = UserQuery.parseRow(row.skip(3).take(3).toList()); var modelOpt = UserQuery.parseRow(row.skip(3).take(3).toList());
if (u.isPresent) { modelOpt.ifPresent((m) {
model = model.copyWith( model = model.copyWith(user: m);
user: UserQuery.parseRow(row.skip(3).take(3).toList()).value); });
}
} }
return Optional.ofNullable(model); return Optional.ofNullable(model);
} }
@ -387,14 +386,16 @@ class UserQuery extends Query<User, UserQueryWhere> {
name: (row[1] as String?), name: (row[1] as String?),
password: (row[2] as String?)); password: (row[2] as String?));
if (row.length > 3) { 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())] // roles: [RoleQuery.parseRow(row.skip(3).take(1).toList())]
// .where((x) => x != null) // .where((x) => x != null)
// .toList()); // .toList());
} }
return Optional.ofNullable(model); return Optional.of(model);
} }
@override @override

View file

@ -74,7 +74,7 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
createdAt: (row[1] as DateTime?), createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?), updatedAt: (row[2] as DateTime?),
type: row[3] == null ? null : CarType.values[(row[3] as int)]); type: row[3] == null ? null : CarType.values[(row[3] as int)]);
return Optional.ofNullable(model); return Optional.of(model);
} }
@override @override

View file

@ -67,10 +67,8 @@ class HasMapQuery extends Query<HasMap, HasMapQueryWhere> {
if (row.every((x) => x == null)) { if (row.every((x) => x == null)) {
return Optional.empty(); return Optional.empty();
} }
var model = HasMap( var model = HasMap(value: (row[0]), list: (row[1]));
value: (row[0] as Map<dynamic, dynamic>?), return Optional.of(model);
list: (row[1] as List<dynamic>?));
return Optional.ofNullable(model);
} }
@override @override
@ -100,16 +98,16 @@ class HasMapQueryValues extends MapQueryValues {
return {'list': 'jsonb'}; return {'list': 'jsonb'};
} }
Map<dynamic, dynamic>? get value { Map<dynamic, dynamic> get value {
return (values['value'] as Map<dynamic, dynamic>?); return (values['value'] as Map<dynamic, dynamic>);
} }
set value(Map<dynamic, dynamic>? value) => values['value'] = value; set value(Map<dynamic, dynamic> value) => values['value'] = value;
List<dynamic>? get list { List<dynamic> get list {
return (json.decode((values['list'] as String)) as List?); return (json.decode((values['list'] as String)) as List);
} }
set list(List<dynamic>? value) => values['list'] = json.encode(value); set list(List<dynamic> value) => values['list'] = json.encode(value);
void copyFrom(HasMap model) { void copyFrom(HasMap model) {
value = model.value; value = model.value;
list = model.list; list = model.list;
@ -122,16 +120,17 @@ class HasMapQueryValues extends MapQueryValues {
@generatedSerializable @generatedSerializable
class HasMap implements _HasMap { class HasMap implements _HasMap {
const HasMap({this.value, this.list}); const HasMap({this.value = const {}, this.list = const []});
@override @override
final Map<dynamic, dynamic>? value; final Map<dynamic, dynamic> value;
@override @override
final List<dynamic>? list; final List<dynamic> list;
HasMap copyWith({Map<dynamic, dynamic>? value, List<dynamic>? list}) { HasMap copyWith(
return HasMap(value: value ?? this.value, list: list ?? this.list); {Map<dynamic, dynamic> value = const {}, List<dynamic> list = const []}) {
return HasMap(value: value, list: list);
} }
bool operator ==(other) { bool operator ==(other) {
@ -188,10 +187,10 @@ class HasMapSerializer extends Codec<HasMap, Map> {
return HasMap( return HasMap(
value: map['value'] is Map value: map['value'] is Map
? (map['value'] as Map).cast<dynamic, dynamic>() ? (map['value'] as Map).cast<dynamic, dynamic>()
: null, : {},
list: map['list'] is Iterable list: map['list'] is Iterable
? (map['list'] as Iterable).cast<dynamic>().toList() ? (map['list'] as Iterable).cast<dynamic>().toList()
: null); : []);
} }
static Map<String, dynamic> toMap(_HasMap model) { static Map<String, dynamic> toMap(_HasMap model) {

View file

@ -104,10 +104,12 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
updatedAt: (row[2] as DateTime?), updatedAt: (row[2] as DateTime?),
name: (row[3] as String?)); name: (row[3] as String?));
if (row.length > 4) { if (row.length > 4) {
model = model.copyWith( var modelOpt = FootQuery.parseRow(row.skip(4).take(5).toList());
foot: FootQuery.parseRow(row.skip(4).take(5).toList()).firstOrNull); modelOpt.ifPresent((m) {
model = model.copyWith(foot: m);
});
} }
return Optional.ofNullable(model); return Optional.of(model);
} }
@override @override
@ -221,7 +223,7 @@ class FootQuery extends Query<Foot, FootQueryWhere> {
updatedAt: (row[2] as DateTime?), updatedAt: (row[2] as DateTime?),
legId: (row[3] as int?), legId: (row[3] as int?),
nToes: double.tryParse(row[4].toString())); nToes: double.tryParse(row[4].toString()));
return Optional.ofNullable(model); return Optional.of(model);
} }
@override @override

View file

@ -111,10 +111,12 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
orderDate: (row[5] as DateTime?), orderDate: (row[5] as DateTime?),
shipperId: (row[6] as int?)); shipperId: (row[6] as int?));
if (row.length > 7) { if (row.length > 7) {
model = model.copyWith( var modelOpt = CustomerQuery.parseRow(row.skip(7).take(3).toList());
customer: CustomerQuery.parseRow(row.skip(7).take(3).toList()).value); modelOpt.ifPresent((m) {
model = model.copyWith(customer: m);
});
} }
return Optional.ofNullable(model); return Optional.of(model);
} }
@override @override
@ -264,7 +266,7 @@ class CustomerQuery extends Query<Customer, CustomerQueryWhere> {
id: row[0].toString(), id: row[0].toString(),
createdAt: (row[1] as DateTime?), createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?)); updatedAt: (row[2] as DateTime?));
return Optional.ofNullable(model); return Optional.of(model);
} }
@override @override

View file

@ -109,7 +109,7 @@ class TreeQuery extends Query<Tree, TreeQueryWhere> {
model = model.copyWith(fruits: [m]); model = model.copyWith(fruits: [m]);
}); });
} }
return Optional.ofNullable(model); return Optional.of(model);
} }
@override @override
@ -280,7 +280,7 @@ class FruitQuery extends Query<Fruit, FruitQueryWhere> {
updatedAt: (row[2] as DateTime?), updatedAt: (row[2] as DateTime?),
treeId: (row[3] as int?), treeId: (row[3] as int?),
commonName: (row[4] as String?)); commonName: (row[4] as String?));
return Optional.ofNullable(model); return Optional.of(model);
} }
@override @override

View file

@ -148,7 +148,7 @@ class UnorthodoxQuery extends Query<Unorthodox, UnorthodoxQueryWhere> {
return Optional.empty(); return Optional.empty();
} }
var model = Unorthodox(name: (row[0] as String?)); var model = Unorthodox(name: (row[0] as String?));
return Optional.ofNullable(model); return Optional.of(model);
} }
@override @override
@ -260,24 +260,30 @@ class WeirdJoinQuery extends Query<WeirdJoin, WeirdJoinQueryWhere> {
} }
var model = WeirdJoin(id: (row[0] as int?)); var model = WeirdJoin(id: (row[0] as int?));
if (row.length > 2) { if (row.length > 2) {
model = model.copyWith( var modelOpt = UnorthodoxQuery.parseRow(row.skip(2).take(1).toList());
unorthodox: UnorthodoxQuery.parseRow(row.skip(2).take(1).toList()) modelOpt.ifPresent((m) {
.firstOrNull); model = model.copyWith(unorthodox: m);
});
} }
if (row.length > 3) { if (row.length > 3) {
model = model.copyWith( var modelOpt = SongQuery.parseRow(row.skip(3).take(5).toList());
song: SongQuery.parseRow(row.skip(3).take(5).toList()).firstOrNull); modelOpt.ifPresent((m) {
model = model.copyWith(song: m);
});
} }
if (row.length > 8) { if (row.length > 8) {
model = model.copyWith(numbas: [ var modelOpt = NumbaQuery.parseRow(row.skip(8).take(2).toList());
NumbaQuery.parseRow(row.skip(8).take(2).toList()).firstOrNull modelOpt.ifPresent((m) {
]); model = model.copyWith(numbas: [m]);
});
} }
if (row.length > 10) { if (row.length > 10) {
model = model.copyWith( var modelOpt = FooQuery.parseRow(row.skip(10).take(1).toList());
foos: [FooQuery.parseRow(row.skip(10).take(1).toList()).firstOrNull]); modelOpt.ifPresent((m) {
model = model.copyWith(foos: [m]);
});
} }
return Optional.ofNullable(model); return Optional.of(model);
} }
@override @override
@ -450,7 +456,7 @@ class SongQuery extends Query<Song, SongQueryWhere> {
updatedAt: (row[2] as DateTime?), updatedAt: (row[2] as DateTime?),
weirdJoinId: (row[3] as int?), weirdJoinId: (row[3] as int?),
title: (row[4] as String?)); title: (row[4] as String?));
return Optional.ofNullable(model); return Optional.of(model);
} }
@override @override
@ -564,7 +570,7 @@ class NumbaQuery extends Query<Numba, NumbaQueryWhere> {
return Optional.empty(); return Optional.empty();
} }
var model = Numba(i: (row[0] as int?), parent: (row[1] as int?)); var model = Numba(i: (row[0] as int?), parent: (row[1] as int?));
return Optional.ofNullable(model); return Optional.of(model);
} }
@override @override
@ -659,9 +665,9 @@ class FooQuery extends Query<Foo, FooQueryWhere> {
} }
var model = Foo(bar: (row[0] as String?)); var model = Foo(bar: (row[0] as String?));
if (row.length > 1) { if (row.length > 1) {
var weirdOpt = WeirdJoinQuery.parseRow(row.skip(1).take(2).toList()); var modelOpt = WeirdJoinQuery.parseRow(row.skip(1).take(2).toList());
weirdOpt.ifPresent((value) { modelOpt.ifPresent((m) {
model = model.copyWith(weirdJoins: [value]); model = model.copyWith(weirdJoins: [m]);
}); });
} }
return Optional.ofNullable(model); return Optional.ofNullable(model);

View file

@ -461,12 +461,12 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
updatedAt: (row[2] as DateTime?), updatedAt: (row[2] as DateTime?),
name: (row[3] as String?)); name: (row[3] as String?));
if (row.length > 4) { if (row.length > 4) {
var userOpt = UserQuery.parseRow(row.skip(4).take(6).toList()); var modelOpt = UserQuery.parseRow(row.skip(4).take(6).toList());
userOpt.ifPresent((user) { modelOpt.ifPresent((m) {
model = model.copyWith(users: [user]); model = model.copyWith(users: [m]);
}); });
} }
return Optional.ofNullable(model); return Optional.of(model);
} }
@override @override