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_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

View file

@ -116,15 +116,18 @@ class BookQuery extends Query<Book, BookQueryWhere> {
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

View file

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

View file

@ -94,7 +94,7 @@ class NumbersQuery extends Query<Numbers, NumbersQueryWhere> {
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<Alphabet, AlphabetQueryWhere> {
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

View file

@ -108,10 +108,10 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
}
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<RoleUser, RoleUserQueryWhere> {
}
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<User, UserQueryWhere> {
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

View file

@ -74,7 +74,7 @@ class HasCarQuery extends Query<HasCar, HasCarQueryWhere> {
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

View file

@ -67,10 +67,8 @@ class HasMapQuery extends Query<HasMap, HasMapQueryWhere> {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = HasMap(
value: (row[0] as Map<dynamic, dynamic>?),
list: (row[1] as List<dynamic>?));
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<dynamic, dynamic>? get value {
return (values['value'] as Map<dynamic, dynamic>?);
Map<dynamic, dynamic> get value {
return (values['value'] as Map<dynamic, dynamic>);
}
set value(Map<dynamic, dynamic>? value) => values['value'] = value;
List<dynamic>? get list {
return (json.decode((values['list'] as String)) as List?);
set value(Map<dynamic, dynamic> value) => values['value'] = value;
List<dynamic> get 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) {
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<dynamic, dynamic>? value;
final Map<dynamic, dynamic> value;
@override
final List<dynamic>? list;
final List<dynamic> list;
HasMap copyWith({Map<dynamic, dynamic>? value, List<dynamic>? list}) {
return HasMap(value: value ?? this.value, list: list ?? this.list);
HasMap copyWith(
{Map<dynamic, dynamic> value = const {}, List<dynamic> list = const []}) {
return HasMap(value: value, list: list);
}
bool operator ==(other) {
@ -188,10 +187,10 @@ class HasMapSerializer extends Codec<HasMap, Map> {
return HasMap(
value: map['value'] is Map
? (map['value'] as Map).cast<dynamic, dynamic>()
: null,
: {},
list: map['list'] is Iterable
? (map['list'] as Iterable).cast<dynamic>().toList()
: null);
: []);
}
static Map<String, dynamic> toMap(_HasMap model) {

View file

@ -104,10 +104,12 @@ class LegQuery extends Query<Leg, LegQueryWhere> {
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<Foot, FootQueryWhere> {
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

View file

@ -111,10 +111,12 @@ class OrderQuery extends Query<Order, OrderQueryWhere> {
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<Customer, CustomerQueryWhere> {
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?));
return Optional.ofNullable(model);
return Optional.of(model);
}
@override

View file

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

View file

@ -148,7 +148,7 @@ class UnorthodoxQuery extends Query<Unorthodox, UnorthodoxQueryWhere> {
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<WeirdJoin, WeirdJoinQueryWhere> {
}
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<Song, SongQueryWhere> {
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<Numba, NumbaQueryWhere> {
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<Foo, FooQueryWhere> {
}
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);

View file

@ -461,12 +461,12 @@ class RoleQuery extends Query<Role, RoleQueryWhere> {
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