update has one tests
This commit is contained in:
parent
b6b9c7148d
commit
43736c4f48
2 changed files with 37 additions and 22 deletions
|
@ -132,7 +132,9 @@ main() {
|
||||||
|
|
||||||
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 = 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);
|
var book = await query.updateOne(executor);
|
||||||
print(book.toJson());
|
print(book.toJson());
|
||||||
expect(book.name, cloned.name);
|
expect(book.name, cloned.name);
|
||||||
|
|
|
@ -3,31 +3,36 @@ library angel_orm_generator.test.has_one_test;
|
||||||
|
|
||||||
import 'package:angel_orm/angel_orm.dart';
|
import 'package:angel_orm/angel_orm.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'models/foot.orm.g.dart';
|
import 'models/foot.dart';
|
||||||
import 'models/leg.dart';
|
import 'models/leg.dart';
|
||||||
import 'models/leg.orm.g.dart';
|
|
||||||
import 'common.dart';
|
import 'common.dart';
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
QueryExecutor connection;
|
QueryExecutor executor;
|
||||||
Leg originalLeg;
|
Leg originalLeg;
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
connection = await connectToPostgres(['leg', 'foot']);
|
executor = await connectToPostgres(['leg', 'foot']);
|
||||||
originalLeg = await LegQuery.insert(connection, name: 'Left');
|
var query = new LegQuery()..values.name = 'Left';
|
||||||
|
originalLeg = await query.insert(executor);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('sets to null if no child', () async {
|
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.name, originalLeg.name);
|
||||||
expect(leg.id, originalLeg.id);
|
expect(leg.id, originalLeg.id);
|
||||||
expect(leg.foot, isNull);
|
expect(leg.foot, isNull);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('can fetch one foot', () async {
|
test('can fetch one foot', () async {
|
||||||
var foot = await FootQuery.insert(connection,
|
var footQuery = new FootQuery()
|
||||||
legId: int.parse(originalLeg.id), nToes: 5);
|
..values.legId = int.parse(originalLeg.id)
|
||||||
var leg = await LegQuery.getOne(int.parse(originalLeg.id), connection);
|
..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.name, originalLeg.name);
|
||||||
expect(leg.id, originalLeg.id);
|
expect(leg.id, originalLeg.id);
|
||||||
expect(leg.foot, isNotNull);
|
expect(leg.foot, isNotNull);
|
||||||
|
@ -36,11 +41,12 @@ main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('only fetches one foot even if there are multiple', () async {
|
test('only fetches one foot even if there are multiple', () async {
|
||||||
var foot = await FootQuery.insert(connection,
|
var footQuery = new FootQuery()
|
||||||
legId: int.parse(originalLeg.id), nToes: 5);
|
..values.legId = int.parse(originalLeg.id)
|
||||||
await FootQuery.insert(connection,
|
..values.nToes = 24;
|
||||||
legId: int.parse(originalLeg.id), nToes: 24);
|
var legQuery = new LegQuery()..where.id.equals(int.parse(originalLeg.id));
|
||||||
var leg = await LegQuery.getOne(int.parse(originalLeg.id), connection);
|
var foot = await footQuery.insert(executor);
|
||||||
|
var leg = await legQuery.getOne(executor);
|
||||||
expect(leg.name, originalLeg.name);
|
expect(leg.name, originalLeg.name);
|
||||||
expect(leg.id, originalLeg.id);
|
expect(leg.id, originalLeg.id);
|
||||||
expect(leg.foot, isNotNull);
|
expect(leg.foot, isNotNull);
|
||||||
|
@ -49,10 +55,14 @@ main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('sets foot on update', () async {
|
test('sets foot on update', () async {
|
||||||
var foot = await FootQuery.insert(connection,
|
var footQuery = new FootQuery()
|
||||||
legId: int.parse(originalLeg.id), nToes: 5);
|
..values.legId = int.parse(originalLeg.id)
|
||||||
var leg = await LegQuery.updateLeg(
|
..values.nToes = 5;
|
||||||
connection, originalLeg.clone()..name = 'Right');
|
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());
|
print(leg.toJson());
|
||||||
expect(leg.name, 'Right');
|
expect(leg.name, 'Right');
|
||||||
expect(leg.foot, isNotNull);
|
expect(leg.foot, isNotNull);
|
||||||
|
@ -61,9 +71,12 @@ main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('sets foot on delete', () async {
|
test('sets foot on delete', () async {
|
||||||
var foot = await FootQuery.insert(connection,
|
var footQuery = new FootQuery()
|
||||||
legId: int.parse(originalLeg.id), nToes: 5);
|
..values.legId = int.parse(originalLeg.id)
|
||||||
var leg = await LegQuery.deleteOne(int.parse(originalLeg.id), connection);
|
..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());
|
print(leg.toJson());
|
||||||
expect(leg.name, originalLeg.name);
|
expect(leg.name, originalLeg.name);
|
||||||
expect(leg.foot, isNotNull);
|
expect(leg.foot, isNotNull);
|
||||||
|
|
Loading…
Reference in a new issue