platform/test/car_test.dart

66 lines
1.7 KiB
Dart
Raw Normal View History

2017-06-24 21:21:32 +00:00
import 'dart:io';
import 'package:angel_orm/angel_orm.dart';
import 'package:postgres/postgres.dart';
2017-06-18 04:19:05 +00:00
import 'package:test/test.dart';
import 'models/car.dart';
import 'models/car.orm.g.dart';
final DateTime MILENNIUM = new DateTime.utc(2000, 1, 1);
main() {
2017-06-24 21:21:32 +00:00
PostgreSQLConnection connection;
setUp(() async {
connection = new PostgreSQLConnection('127.0.0.1', 0, '');
await connection.open();
// Create temp table
var query = await new File('test/models/car.sql').readAsString();
await connection.execute(query);
});
tearDown(() async {
// Drop `cars`
await connection.execute('DROP TABLE `cars`;');
await connection.close();
});
2017-06-18 04:19:05 +00:00
test('to where', () {
var query = new CarQuery();
query.where
..familyFriendly.equals(true)
..recalledAt.lessThanOrEqualTo(MILENNIUM, includeTime: false);
var whereClause = query.where.toWhereClause();
print('Where clause: $whereClause');
2017-06-24 21:21:32 +00:00
expect(whereClause,
"WHERE `family_friendly` = 1 AND `recalled_at` <= '00-01-01'");
2017-06-18 04:19:05 +00:00
});
2017-06-24 21:21:32 +00:00
test('parseRow', () {
var row = [
0,
'Mazda',
'CX9',
1,
DATE_YMD_HMS.format(MILENNIUM),
DATE_YMD_HMS.format(MILENNIUM),
DATE_YMD_HMS.format(MILENNIUM)
];
print(row);
var car = CarQuery.parseRow(row);
2017-06-18 04:19:05 +00:00
print(car.toJson());
2017-06-24 21:21:32 +00:00
expect(car.id, '0');
expect(car.make, 'Mazda');
expect(car.description, 'CX9');
expect(car.familyFriendly, true);
expect(MILENNIUM.toIso8601String(),
startsWith(car.recalledAt.toIso8601String()));
expect(MILENNIUM.toIso8601String(),
startsWith(car.createdAt.toIso8601String()));
expect(MILENNIUM.toIso8601String(),
startsWith(car.updatedAt.toIso8601String()));
});
test('insert', () async {});
2017-06-18 04:19:05 +00:00
}