Updated test cases
This commit is contained in:
parent
50f8ba23da
commit
6e8f6aea9e
5 changed files with 94 additions and 43 deletions
|
@ -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 (30/54 tests passed)
|
* Migrated angel_orm_postgres to 3.0.0 (35/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
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,25 +16,35 @@ edgeCaseTests(FutureOr<QueryExecutor> Function() createExecutor,
|
||||||
|
|
||||||
test('can create object with no id', () async {
|
test('can create object with no id', () async {
|
||||||
var query = UnorthodoxQuery()..values.name = 'Hey';
|
var query = UnorthodoxQuery()..values.name = 'Hey';
|
||||||
var model = await query.insert(executor);
|
var modelOpt = await query.insert(executor);
|
||||||
|
expect(modelOpt.isPresent, true);
|
||||||
|
modelOpt.ifPresent((model) {
|
||||||
expect(model, Unorthodox(name: 'Hey'));
|
expect(model, Unorthodox(name: 'Hey'));
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
group('relations on non-model', () {
|
group('relations on non-model', () {
|
||||||
Unorthodox? unorthodox;
|
Unorthodox? unorthodox;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
var query = UnorthodoxQuery()..values.name = 'Hey';
|
var query = UnorthodoxQuery()..values.name = 'Hey';
|
||||||
unorthodox = (await query.insert(executor)).value;
|
|
||||||
|
var unorthodoxOpt = await query.insert(executor);
|
||||||
|
unorthodoxOpt.ifPresent((value) {
|
||||||
|
unorthodox = value;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('belongs to', () async {
|
test('belongs to', () async {
|
||||||
var query = WeirdJoinQuery()..values.joinName = unorthodox!.name;
|
var query = WeirdJoinQuery()..values.joinName = unorthodox!.name;
|
||||||
var model = await (query.insert(executor) as FutureOr<WeirdJoin>);
|
var modelOpt = await query.insert(executor);
|
||||||
|
expect(modelOpt.isPresent, true);
|
||||||
|
modelOpt.ifPresent((model) {
|
||||||
print(model.toJson());
|
print(model.toJson());
|
||||||
expect(model.id, isNotNull); // Postgres should set this.
|
expect(model.id, isNotNull); // Postgres should set this.
|
||||||
expect(model.unorthodox, unorthodox);
|
expect(model.unorthodox, unorthodox);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
group('layered', () {
|
group('layered', () {
|
||||||
WeirdJoin? weirdJoin;
|
WeirdJoin? weirdJoin;
|
||||||
|
@ -42,37 +52,54 @@ edgeCaseTests(FutureOr<QueryExecutor> Function() createExecutor,
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
var wjQuery = WeirdJoinQuery()..values.joinName = unorthodox!.name;
|
var wjQuery = WeirdJoinQuery()..values.joinName = unorthodox!.name;
|
||||||
weirdJoin = (await wjQuery.insert(executor)).value;
|
|
||||||
|
|
||||||
|
var weirdJoinOpt = await wjQuery.insert(executor);
|
||||||
|
//weirdJoin = (await wjQuery.insert(executor)).value;
|
||||||
|
weirdJoinOpt.ifPresent((value1) async {
|
||||||
|
weirdJoin = value1;
|
||||||
var gbQuery = SongQuery()
|
var gbQuery = SongQuery()
|
||||||
..values.weirdJoinId = weirdJoin!.id
|
..values.weirdJoinId = value1.id
|
||||||
..values.title = 'Girl Blue';
|
..values.title = 'Girl Blue';
|
||||||
girlBlue = (await gbQuery.insert(executor)).value;
|
|
||||||
|
var girlBlueOpt = await gbQuery.insert(executor);
|
||||||
|
girlBlueOpt.ifPresent((value2) {
|
||||||
|
girlBlue = value2;
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('has one', () async {
|
test('has one', () async {
|
||||||
var query = WeirdJoinQuery()..where!.id.equals(weirdJoin!.id!);
|
var query = WeirdJoinQuery()..where!.id.equals(weirdJoin!.id!);
|
||||||
var wj = await (query.getOne(executor) as FutureOr<WeirdJoin>);
|
var wjOpt = await query.getOne(executor);
|
||||||
|
expect(wjOpt.isPresent, true);
|
||||||
|
wjOpt.ifPresent((wj) {
|
||||||
print(wj.toJson());
|
print(wj.toJson());
|
||||||
expect(wj.song, girlBlue);
|
expect(wj.song, girlBlue);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('has many', () async {
|
test('has many', () async {
|
||||||
var numbas = <Numba?>[];
|
var numbas = <Numba>[];
|
||||||
|
|
||||||
for (int i = 0; i < 15; i++) {
|
for (int i = 0; i < 15; i++) {
|
||||||
var query = NumbaQuery()
|
var query = NumbaQuery()
|
||||||
..values.parent = weirdJoin!.id
|
..values.parent = weirdJoin!.id
|
||||||
..values.i = i;
|
..values.i = i;
|
||||||
var model = await query.insert(executor);
|
var modelObj = await query.insert(executor);
|
||||||
numbas.add(model.value);
|
expect(modelObj.isPresent, true);
|
||||||
|
modelObj.ifPresent((model) {
|
||||||
|
numbas.add(model);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var query = WeirdJoinQuery()..where!.id.equals(weirdJoin!.id!);
|
var query = WeirdJoinQuery()..where!.id.equals(weirdJoin!.id!);
|
||||||
var wj = await (query.getOne(executor) as FutureOr<WeirdJoin>);
|
var wjObj = await query.getOne(executor);
|
||||||
|
expect(wjObj.isPresent, true);
|
||||||
|
wjObj.ifPresent((wj) {
|
||||||
print(wj.toJson());
|
print(wj.toJson());
|
||||||
expect(wj.numbas, numbas);
|
expect(wj.numbas, numbas);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('many to many', () async {
|
test('many to many', () async {
|
||||||
var fooQuery = FooQuery()..values.bar = 'baz';
|
var fooQuery = FooQuery()..values.bar = 'baz';
|
||||||
|
@ -84,11 +111,14 @@ edgeCaseTests(FutureOr<QueryExecutor> Function() createExecutor,
|
||||||
await pivotQuery.insert(executor);
|
await pivotQuery.insert(executor);
|
||||||
fooQuery = FooQuery()..where!.bar.equals('baz');
|
fooQuery = FooQuery()..where!.bar.equals('baz');
|
||||||
|
|
||||||
var foo = await (fooQuery.getOne(executor) as FutureOr<Foo>);
|
var fooObj = await fooQuery.getOne(executor);
|
||||||
|
expect(fooObj.isPresent, true);
|
||||||
|
fooObj.ifPresent((foo) {
|
||||||
print(foo.toJson());
|
print(foo.toJson());
|
||||||
print(weirdJoin!.toJson());
|
print(weirdJoin!.toJson());
|
||||||
expect(foo.weirdJoins![0].id, weirdJoin!.id);
|
expect(foo.weirdJoins![0].id, weirdJoin!.id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,9 +14,12 @@ enumAndNestedTests(FutureOr<QueryExecutor> Function() createExecutor,
|
||||||
|
|
||||||
test('insert', () async {
|
test('insert', () async {
|
||||||
var query = HasCarQuery()..values.type = CarType.sedan;
|
var query = HasCarQuery()..values.type = CarType.sedan;
|
||||||
var result = await (query.insert(executor) as FutureOr<HasCar>);
|
var resultOpt = await (query.insert(executor));
|
||||||
|
expect(resultOpt.isPresent, true);
|
||||||
|
resultOpt.ifPresent((result) {
|
||||||
expect(result.type, CarType.sedan);
|
expect(result.type, CarType.sedan);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
group('query', () {
|
group('query', () {
|
||||||
HasCar? initialValue;
|
HasCar? initialValue;
|
||||||
|
|
|
@ -43,38 +43,55 @@ hasManyTests(FutureOr<QueryExecutor> Function() createExecutor,
|
||||||
var bananaQuery = FruitQuery()
|
var bananaQuery = FruitQuery()
|
||||||
..values.treeId = treeId
|
..values.treeId = treeId
|
||||||
..values.commonName = 'Banana';
|
..values.commonName = 'Banana';
|
||||||
|
var appleOpt = await appleQuery.insert(executor);
|
||||||
apple = (await appleQuery.insert(executor)).value;
|
var bananaOpt = await bananaQuery.insert(executor);
|
||||||
banana = (await bananaQuery.insert(executor)).value;
|
appleOpt.ifPresent((a) {
|
||||||
|
apple = a;
|
||||||
|
});
|
||||||
|
bananaOpt.ifPresent((a) {
|
||||||
|
banana = a;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('can fetch any children', () async {
|
test('can fetch any children', () async {
|
||||||
var query = TreeQuery()..where!.id.equals(treeId);
|
var query = TreeQuery()..where!.id.equals(treeId);
|
||||||
var tree = await (query.getOne(executor) as FutureOr<Tree>);
|
var treeOpt = await (query.getOne(executor));
|
||||||
|
expect(treeOpt.isPresent, true);
|
||||||
|
treeOpt.ifPresent((tree) {
|
||||||
verify(tree);
|
verify(tree);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('sets on update', () async {
|
test('sets on update', () async {
|
||||||
var tq = TreeQuery()
|
var tq = TreeQuery()
|
||||||
..where!.id.equals(treeId)
|
..where!.id.equals(treeId)
|
||||||
..values.rings = 24;
|
..values.rings = 24;
|
||||||
var tree = await (tq.updateOne(executor) as FutureOr<Tree>);
|
var treeOpt = await (tq.updateOne(executor));
|
||||||
|
expect(treeOpt.isPresent, true);
|
||||||
|
treeOpt.ifPresent((tree) {
|
||||||
verify(tree);
|
verify(tree);
|
||||||
expect(tree.rings, 24);
|
expect(tree.rings, 24);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('sets on delete', () async {
|
test('sets on delete', () async {
|
||||||
var tq = TreeQuery()..where!.id.equals(treeId);
|
var tq = TreeQuery()..where!.id.equals(treeId);
|
||||||
var tree = await (tq.deleteOne(executor) as FutureOr<Tree>);
|
var treeOpt = await (tq.deleteOne(executor));
|
||||||
|
expect(treeOpt.isPresent, true);
|
||||||
|
treeOpt.ifPresent((tree) {
|
||||||
verify(tree);
|
verify(tree);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('returns empty on false subquery', () async {
|
test('returns empty on false subquery', () async {
|
||||||
var tq = TreeQuery()
|
var tq = TreeQuery()
|
||||||
..where!.id.equals(treeId)
|
..where!.id.equals(treeId)
|
||||||
..fruits!.where!.commonName.equals('Kiwi');
|
..fruits!.where!.commonName.equals('Kiwi');
|
||||||
var tree = await (tq.getOne(executor) as FutureOr<Tree>);
|
var treeOpt = await (tq.getOne(executor));
|
||||||
|
expect(treeOpt.isPresent, true);
|
||||||
|
treeOpt.ifPresent((tree) {
|
||||||
expect(tree.fruits, isEmpty);
|
expect(tree.fruits, isEmpty);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -659,9 +659,10 @@ 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) {
|
||||||
model = model.copyWith(weirdJoins: [
|
var weirdOpt = WeirdJoinQuery.parseRow(row.skip(1).take(2).toList());
|
||||||
WeirdJoinQuery.parseRow(row.skip(1).take(2).toList()).value
|
weirdOpt.ifPresent((value) {
|
||||||
]);
|
model = model.copyWith(weirdJoins: [value]);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return Optional.ofNullable(model);
|
return Optional.ofNullable(model);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue