2017-01-30 02:39:11 +00:00
|
|
|
import 'package:angel_framework/angel_framework.dart';
|
|
|
|
import 'package:angel_relations/angel_relations.dart' as relations;
|
|
|
|
import 'package:angel_seeder/angel_seeder.dart';
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
import 'common.dart';
|
|
|
|
|
|
|
|
main() {
|
|
|
|
Angel app;
|
|
|
|
|
|
|
|
setUp(() async {
|
2021-02-21 02:47:23 +00:00
|
|
|
app = Angel()..use('/authors', MapService())..use('/books', MapService());
|
2017-01-30 02:39:11 +00:00
|
|
|
|
|
|
|
await app.configure(seed(
|
|
|
|
'authors',
|
2021-02-21 02:47:23 +00:00
|
|
|
SeederConfiguration<Map>(
|
2017-01-30 02:39:11 +00:00
|
|
|
count: 10,
|
|
|
|
template: {'name': (Faker faker) => faker.person.name()},
|
|
|
|
callback: (Map author, seed) {
|
|
|
|
return seed(
|
|
|
|
'books',
|
2021-02-21 02:47:23 +00:00
|
|
|
SeederConfiguration(delete: false, count: 10, template: {
|
2017-01-30 02:39:11 +00:00
|
|
|
'authorId': author['id'],
|
|
|
|
'title': (Faker faker) =>
|
|
|
|
'I love to eat ${faker.food.dish()}'
|
|
|
|
}));
|
|
|
|
})));
|
|
|
|
|
2021-02-16 02:10:09 +00:00
|
|
|
// TODO: Missing method afterAll
|
|
|
|
//app.findService ('books').afterAll(relations.belongsTo('authors'));
|
2017-01-30 02:39:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('index', () async {
|
2021-02-16 02:10:09 +00:00
|
|
|
var books = await app.findService('books').index();
|
2017-01-30 02:39:11 +00:00
|
|
|
print(books);
|
|
|
|
|
|
|
|
expect(books, allOf(isList, isNotEmpty));
|
|
|
|
|
|
|
|
for (Map book in books) {
|
|
|
|
expect(book.keys, contains('author'));
|
|
|
|
|
|
|
|
Map author = book['author'];
|
|
|
|
expect(author['id'], equals(book['authorId']));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('create', () async {
|
|
|
|
var warAndPeace = await app
|
2021-02-16 02:10:09 +00:00
|
|
|
.findService('books')
|
|
|
|
.create(Book(title: 'War and Peace').toJson());
|
2017-01-30 02:39:11 +00:00
|
|
|
|
|
|
|
print(warAndPeace);
|
|
|
|
expect(warAndPeace.keys, contains('author'));
|
|
|
|
expect(warAndPeace['author'], isNull);
|
|
|
|
});
|
|
|
|
}
|