Update test cases

This commit is contained in:
thomashii@dukefirehawk.com 2021-05-05 09:37:59 +08:00
parent 41569aa53f
commit 005e819fa9
4 changed files with 44 additions and 25 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 (25/54 tests passed) * Migrated angel_orm_postgres to 3.0.0 (27/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

@ -130,11 +130,11 @@ belongsToTests(FutureOr<QueryExecutor> Function() createExecutor,
printSeparator('Delete stream test'); printSeparator('Delete stream test');
var query = BookQuery()..where!.name.equals(deathlyHallows!.name!); var query = BookQuery()..where!.name.equals(deathlyHallows!.name!);
print(query.compile(Set(), preamble: 'DELETE', withFields: false)); print(query.compile(Set(), preamble: 'DELETE', withFields: false));
List<Book>? books = await query.delete(executor); List<Book> books = await query.delete(executor);
expect(books, hasLength(1)); expect(books, hasLength(1));
var book = books.first; var book = books.first;
expect(book.id, deathlyHallows!.id); expect(book.id, deathlyHallows?.id);
expect(book.author, isNotNull); expect(book.author, isNotNull);
expect(book.author!.name, jkRowling!.name); expect(book.author!.name, jkRowling!.name);
}); });
@ -142,9 +142,10 @@ belongsToTests(FutureOr<QueryExecutor> Function() createExecutor,
test('update book', () async { test('update book', () async {
var cloned = deathlyHallows!.copyWith(name: "Sorcerer's Stone"); var cloned = deathlyHallows!.copyWith(name: "Sorcerer's Stone");
var query = BookQuery() var query = BookQuery()
..where!.id.equals(int.parse(cloned.id!)) ..where?.id.equals(int.parse(cloned.id!))
..values.copyFrom(cloned); ..values.copyFrom(cloned);
var bookOpt = await (query.updateOne(executor)); var bookOpt = await (query.updateOne(executor));
expect(bookOpt.isPresent, true);
bookOpt.ifPresent((book) { bookOpt.ifPresent((book) {
print(book.toJson()); print(book.toJson());
expect(book.name, cloned.name); expect(book.name, cloned.name);

View file

@ -24,7 +24,7 @@ customExprTests(FutureOr<QueryExecutor> Function() createExecutor,
tearDown(() => close!(executor)); tearDown(() => close!(executor));
test('fetches correct result', () async { test('fetches correct result', () async {
expect(numbersModel!.two, 2); expect(numbersModel?.two, 2);
}); });
test('in relation', () async { test('in relation', () async {
@ -34,9 +34,12 @@ customExprTests(FutureOr<QueryExecutor> Function() createExecutor,
..numbersId = numbersModel!.idAsInt ..numbersId = numbersModel!.idAsInt
..createdAt = numbersModel!.createdAt ..createdAt = numbersModel!.createdAt
..updatedAt = numbersModel!.updatedAt; ..updatedAt = numbersModel!.updatedAt;
var abc = await (abcQuery.insert(executor) as FutureOr<Alphabet>); var abcOpt = await (abcQuery.insert(executor));
expect(abcOpt.isPresent, true);
abcOpt.ifPresent((abc) {
expect(abc.numbers, numbersModel); expect(abc.numbers, numbersModel);
expect(abc.numbers!.two, 2); expect(abc.numbers?.two, 2);
expect(abc.value, 'abc'); expect(abc.value, 'abc');
}); });
});
} }

View file

@ -63,34 +63,49 @@ hasOneTests(FutureOr<QueryExecutor> Function() createExecutor,
var legQuery = LegQuery() var legQuery = LegQuery()
..where!.id.equals(int.parse(originalLeg!.id!)) ..where!.id.equals(int.parse(originalLeg!.id!))
..values.copyFrom(originalLeg!.copyWith(name: 'Right')); ..values.copyFrom(originalLeg!.copyWith(name: 'Right'));
var foot = await (footQuery.insert(executor) as FutureOr<Foot>); var footOpt = await (footQuery.insert(executor));
var leg = await (legQuery.updateOne(executor) as FutureOr<Leg>); var legOpt = await (legQuery.updateOne(executor));
expect(footOpt.isPresent, true);
expect(legOpt.isPresent, true);
legOpt.ifPresent((leg) {
print(leg.toJson()); print(leg.toJson());
expect(leg.name, 'Right'); expect(leg.name, 'Right');
expect(leg.foot, isNotNull); expect(leg.foot, isNotNull);
footOpt.ifPresent((foot) {
expect(leg.foot!.id, foot.id); expect(leg.foot!.id, foot.id);
expect(leg.foot!.nToes, foot.nToes); expect(leg.foot!.nToes, foot.nToes);
}); });
});
});
test('sets foot on delete', () async { test('sets foot on delete', () async {
var footQuery = FootQuery() var footQuery = FootQuery()
..values.legId = int.parse(originalLeg!.id!) ..values.legId = int.parse(originalLeg!.id!)
..values.nToes = 5.64; ..values.nToes = 5.64;
var legQuery = LegQuery()..where!.id.equals(int.parse(originalLeg!.id!)); var legQuery = LegQuery()..where!.id.equals(int.parse(originalLeg!.id!));
var foot = await (footQuery.insert(executor) as FutureOr<Foot>); var footOpt = await (footQuery.insert(executor));
var leg = await (legQuery.deleteOne(executor) as FutureOr<Leg>); var legOpt = await (legQuery.deleteOne(executor));
expect(footOpt.isPresent, true);
expect(legOpt.isPresent, true);
legOpt.ifPresent((leg) {
print(leg.toJson()); print(leg.toJson());
expect(leg.name, originalLeg!.name); expect(leg.name, originalLeg?.name);
expect(leg.foot, isNotNull); expect(leg.foot, isNotNull);
footOpt.ifPresent((foot) {
expect(leg.foot!.id, foot.id); expect(leg.foot!.id, foot.id);
expect(leg.foot!.nToes, foot.nToes); expect(leg.foot!.nToes, foot.nToes);
}); });
});
});
test('sets null on false subquery', () async { test('sets null on false subquery', () async {
var legQuery = LegQuery() var legQuery = LegQuery()
..where!.id.equals(originalLeg!.idAsInt!) ..where!.id.equals(originalLeg!.idAsInt!)
..foot!.where!.legId.equals(originalLeg!.idAsInt! + 1024); ..foot!.where!.legId.equals(originalLeg!.idAsInt! + 1024);
var leg = await (legQuery.getOne(executor) as FutureOr<Leg>); var legOpt = await (legQuery.getOne(executor));
expect(legOpt.isPresent, true);
legOpt.ifPresent((leg) {
expect(leg.foot, isNull); expect(leg.foot, isNull);
}); });
});
} }