From 43736c4f488cbd6a566447e6102883d4c1b72811 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Fri, 7 Dec 2018 21:23:00 -0500 Subject: [PATCH] update has one tests --- angel_orm_generator/test/belongs_to_test.dart | 4 +- angel_orm_generator/test/has_one_test.dart | 55 ++++++++++++------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/angel_orm_generator/test/belongs_to_test.dart b/angel_orm_generator/test/belongs_to_test.dart index 79fbe1f1..0a0890bd 100644 --- a/angel_orm_generator/test/belongs_to_test.dart +++ b/angel_orm_generator/test/belongs_to_test.dart @@ -132,7 +132,9 @@ main() { test('update book', () async { var cloned = deathlyHallows.copyWith(name: "Sorcerer's Stone"); - var query = new BookQuery()..values.copyFrom(cloned); + var query = new BookQuery() + ..where.id.equals(int.parse(cloned.id)) + ..values.copyFrom(cloned); var book = await query.updateOne(executor); print(book.toJson()); expect(book.name, cloned.name); diff --git a/angel_orm_generator/test/has_one_test.dart b/angel_orm_generator/test/has_one_test.dart index 02e916eb..f4366042 100644 --- a/angel_orm_generator/test/has_one_test.dart +++ b/angel_orm_generator/test/has_one_test.dart @@ -3,31 +3,36 @@ library angel_orm_generator.test.has_one_test; import 'package:angel_orm/angel_orm.dart'; import 'package:test/test.dart'; -import 'models/foot.orm.g.dart'; +import 'models/foot.dart'; import 'models/leg.dart'; -import 'models/leg.orm.g.dart'; import 'common.dart'; main() { - QueryExecutor connection; + QueryExecutor executor; Leg originalLeg; setUp(() async { - connection = await connectToPostgres(['leg', 'foot']); - originalLeg = await LegQuery.insert(connection, name: 'Left'); + executor = await connectToPostgres(['leg', 'foot']); + var query = new LegQuery()..values.name = 'Left'; + originalLeg = await query.insert(executor); }); test('sets to null if no child', () async { - var leg = await LegQuery.getOne(int.parse(originalLeg.id), connection); + var query = new LegQuery()..where.id.equals(int.parse(originalLeg.id)); + var leg = await query.getOne(executor); expect(leg.name, originalLeg.name); expect(leg.id, originalLeg.id); expect(leg.foot, isNull); }); test('can fetch one foot', () async { - var foot = await FootQuery.insert(connection, - legId: int.parse(originalLeg.id), nToes: 5); - var leg = await LegQuery.getOne(int.parse(originalLeg.id), connection); + var footQuery = new FootQuery() + ..values.legId = int.parse(originalLeg.id) + ..values.nToes = 5; + var legQuery = new LegQuery()..where.id.equals(int.parse(originalLeg.id)); + var foot = await footQuery.insert(executor); + var leg = await legQuery.getOne(executor); + expect(leg.name, originalLeg.name); expect(leg.id, originalLeg.id); expect(leg.foot, isNotNull); @@ -36,11 +41,12 @@ main() { }); test('only fetches one foot even if there are multiple', () async { - var foot = await FootQuery.insert(connection, - legId: int.parse(originalLeg.id), nToes: 5); - await FootQuery.insert(connection, - legId: int.parse(originalLeg.id), nToes: 24); - var leg = await LegQuery.getOne(int.parse(originalLeg.id), connection); + var footQuery = new FootQuery() + ..values.legId = int.parse(originalLeg.id) + ..values.nToes = 24; + var legQuery = new LegQuery()..where.id.equals(int.parse(originalLeg.id)); + var foot = await footQuery.insert(executor); + var leg = await legQuery.getOne(executor); expect(leg.name, originalLeg.name); expect(leg.id, originalLeg.id); expect(leg.foot, isNotNull); @@ -49,10 +55,14 @@ main() { }); test('sets foot on update', () async { - var foot = await FootQuery.insert(connection, - legId: int.parse(originalLeg.id), nToes: 5); - var leg = await LegQuery.updateLeg( - connection, originalLeg.clone()..name = 'Right'); + var footQuery = new FootQuery() + ..values.legId = int.parse(originalLeg.id) + ..values.nToes = 5; + var legQuery = new LegQuery() + ..where.id.equals(int.parse(originalLeg.id)) + ..values.copyFrom(originalLeg.copyWith(name: 'Right')); + var foot = await footQuery.insert(executor); + var leg = await legQuery.updateOne(executor); print(leg.toJson()); expect(leg.name, 'Right'); expect(leg.foot, isNotNull); @@ -61,9 +71,12 @@ main() { }); test('sets foot on delete', () async { - var foot = await FootQuery.insert(connection, - legId: int.parse(originalLeg.id), nToes: 5); - var leg = await LegQuery.deleteOne(int.parse(originalLeg.id), connection); + var footQuery = new FootQuery() + ..values.legId = int.parse(originalLeg.id) + ..values.nToes = 5; + var legQuery = new LegQuery()..where.id.equals(int.parse(originalLeg.id)); + var foot = await footQuery.insert(executor); + var leg = await legQuery.deleteOne(executor); print(leg.toJson()); expect(leg.name, originalLeg.name); expect(leg.foot, isNotNull);