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_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 (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
|
||||
|
||||
|
||||
|
|
|
@ -16,25 +16,35 @@ edgeCaseTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
|
||||
test('can create object with no id', () async {
|
||||
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'));
|
||||
});
|
||||
});
|
||||
|
||||
group('relations on non-model', () {
|
||||
Unorthodox? unorthodox;
|
||||
|
||||
setUp(() async {
|
||||
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 {
|
||||
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());
|
||||
expect(model.id, isNotNull); // Postgres should set this.
|
||||
expect(model.unorthodox, unorthodox);
|
||||
});
|
||||
});
|
||||
|
||||
group('layered', () {
|
||||
WeirdJoin? weirdJoin;
|
||||
|
@ -42,37 +52,54 @@ edgeCaseTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
|
||||
setUp(() async {
|
||||
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()
|
||||
..values.weirdJoinId = weirdJoin!.id
|
||||
..values.weirdJoinId = value1.id
|
||||
..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 {
|
||||
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());
|
||||
expect(wj.song, girlBlue);
|
||||
});
|
||||
});
|
||||
|
||||
test('has many', () async {
|
||||
var numbas = <Numba?>[];
|
||||
var numbas = <Numba>[];
|
||||
|
||||
for (int i = 0; i < 15; i++) {
|
||||
var query = NumbaQuery()
|
||||
..values.parent = weirdJoin!.id
|
||||
..values.i = i;
|
||||
var model = await query.insert(executor);
|
||||
numbas.add(model.value);
|
||||
var modelObj = await query.insert(executor);
|
||||
expect(modelObj.isPresent, true);
|
||||
modelObj.ifPresent((model) {
|
||||
numbas.add(model);
|
||||
});
|
||||
}
|
||||
|
||||
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());
|
||||
expect(wj.numbas, numbas);
|
||||
});
|
||||
});
|
||||
|
||||
test('many to many', () async {
|
||||
var fooQuery = FooQuery()..values.bar = 'baz';
|
||||
|
@ -84,11 +111,14 @@ edgeCaseTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
await pivotQuery.insert(executor);
|
||||
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(weirdJoin!.toJson());
|
||||
expect(foo.weirdJoins![0].id, weirdJoin!.id);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -14,9 +14,12 @@ enumAndNestedTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
|
||||
test('insert', () async {
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
group('query', () {
|
||||
HasCar? initialValue;
|
||||
|
|
|
@ -43,38 +43,55 @@ hasManyTests(FutureOr<QueryExecutor> Function() createExecutor,
|
|||
var bananaQuery = FruitQuery()
|
||||
..values.treeId = treeId
|
||||
..values.commonName = 'Banana';
|
||||
|
||||
apple = (await appleQuery.insert(executor)).value;
|
||||
banana = (await bananaQuery.insert(executor)).value;
|
||||
var appleOpt = await appleQuery.insert(executor);
|
||||
var bananaOpt = await bananaQuery.insert(executor);
|
||||
appleOpt.ifPresent((a) {
|
||||
apple = a;
|
||||
});
|
||||
bananaOpt.ifPresent((a) {
|
||||
banana = a;
|
||||
});
|
||||
});
|
||||
|
||||
test('can fetch any children', () async {
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
test('sets on update', () async {
|
||||
var tq = TreeQuery()
|
||||
..where!.id.equals(treeId)
|
||||
..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);
|
||||
expect(tree.rings, 24);
|
||||
});
|
||||
});
|
||||
|
||||
test('sets on delete', () async {
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
test('returns empty on false subquery', () async {
|
||||
var tq = TreeQuery()
|
||||
..where!.id.equals(treeId)
|
||||
..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);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -659,9 +659,10 @@ class FooQuery extends Query<Foo, FooQueryWhere> {
|
|||
}
|
||||
var model = Foo(bar: (row[0] as String?));
|
||||
if (row.length > 1) {
|
||||
model = model.copyWith(weirdJoins: [
|
||||
WeirdJoinQuery.parseRow(row.skip(1).take(2).toList()).value
|
||||
]);
|
||||
var weirdOpt = WeirdJoinQuery.parseRow(row.skip(1).take(2).toList());
|
||||
weirdOpt.ifPresent((value) {
|
||||
model = model.copyWith(weirdJoins: [value]);
|
||||
});
|
||||
}
|
||||
return Optional.ofNullable(model);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue