2019-06-16 05:44:43 -07:00
|
|
|
import 'package:moor/moor.dart';
|
2019-09-26 13:52:20 -07:00
|
|
|
import 'package:test/test.dart';
|
2019-06-16 05:44:43 -07:00
|
|
|
|
|
|
|
import 'data/tables/todos.dart';
|
|
|
|
import 'data/utils/mocks.dart';
|
|
|
|
|
|
|
|
// the content is set to non-null and the title must be between 4 and 16 chars
|
|
|
|
// long
|
2019-06-21 11:29:42 -07:00
|
|
|
const absentContent =
|
|
|
|
TodosTableCompanion(title: Value('Test'), content: Value.absent());
|
2019-12-04 12:45:09 -08:00
|
|
|
const shortTitle =
|
|
|
|
TodosTableCompanion(title: Value('A'), content: Value('content'));
|
|
|
|
final TodosTableCompanion longTitle = TodosTableCompanion(
|
2019-06-21 11:29:42 -07:00
|
|
|
title: Value('A ${'very' * 5} long title'), content: const Value('hi'));
|
|
|
|
const valid =
|
|
|
|
TodosTableCompanion(title: Value('Test'), content: Value('Some content'));
|
2019-06-16 05:44:43 -07:00
|
|
|
|
|
|
|
void main() {
|
2021-01-20 03:30:59 -08:00
|
|
|
late TodoDb db;
|
|
|
|
late MockExecutor executor;
|
2019-06-16 05:44:43 -07:00
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
executor = MockExecutor();
|
|
|
|
db = TodoDb(executor);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('detects errors on insert', () {
|
2019-06-21 11:07:29 -07:00
|
|
|
expect(
|
|
|
|
() => db.into(db.todosTable).insert(absentContent),
|
|
|
|
throwsA(predicate<InvalidDataException>(
|
|
|
|
(e) => e.message.contains('was required, but'))),
|
|
|
|
);
|
2019-06-16 05:44:43 -07:00
|
|
|
expect(
|
|
|
|
() => db.into(db.todosTable).insert(shortTitle),
|
|
|
|
throwsA(predicate<InvalidDataException>(
|
|
|
|
(e) => e.message.contains('Must at least be'))),
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
() => db.into(db.todosTable).insert(longTitle),
|
|
|
|
throwsA(predicate<InvalidDataException>(
|
|
|
|
(e) => e.message.contains('Must at most be'))),
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(db.into(db.todosTable).insert(valid), completes);
|
|
|
|
});
|
|
|
|
}
|