2017-02-22 03:13:08 +00:00
|
|
|
import 'package:angel_client/angel_client.dart' as c;
|
|
|
|
import 'package:angel_framework/angel_framework.dart';
|
|
|
|
import 'package:angel_rethink/angel_rethink.dart';
|
|
|
|
import 'package:angel_test/angel_test.dart';
|
2018-06-04 01:35:44 +00:00
|
|
|
import 'package:logging/logging.dart';
|
2021-02-14 05:22:25 +00:00
|
|
|
import 'package:rethinkdb_dart/rethinkdb_dart.dart';
|
2017-02-22 03:13:08 +00:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
import 'common.dart';
|
|
|
|
|
2021-06-26 13:13:43 +00:00
|
|
|
void main() {
|
2017-02-22 03:13:08 +00:00
|
|
|
Angel app;
|
|
|
|
TestClient client;
|
|
|
|
Rethinkdb r;
|
|
|
|
c.Service todoService;
|
|
|
|
|
|
|
|
setUp(() async {
|
2021-02-21 02:47:23 +00:00
|
|
|
r = Rethinkdb();
|
2017-02-22 03:13:08 +00:00
|
|
|
var conn = await r.connect();
|
|
|
|
|
2021-02-21 02:47:23 +00:00
|
|
|
app = Angel();
|
|
|
|
app.use('/todos', RethinkService(conn, r.table('todos')));
|
2017-02-22 03:13:08 +00:00
|
|
|
|
2017-04-10 02:11:48 +00:00
|
|
|
app.errorHandler = (e, req, res) async {
|
2017-02-22 03:13:08 +00:00
|
|
|
print('Whoops: $e');
|
2017-04-10 02:11:48 +00:00
|
|
|
};
|
2017-02-22 03:13:08 +00:00
|
|
|
|
2021-02-21 02:47:23 +00:00
|
|
|
app.logger = Logger.detached('angel')..onRecord.listen(print);
|
2017-02-22 03:13:08 +00:00
|
|
|
|
|
|
|
client = await connectTo(app);
|
|
|
|
todoService = client.service('todos');
|
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() => client.close());
|
|
|
|
|
|
|
|
test('index', () async {
|
|
|
|
var result = await todoService.index();
|
|
|
|
print('Response: $result');
|
|
|
|
expect(result, isList);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('create+read', () async {
|
2021-02-21 02:47:23 +00:00
|
|
|
var todo = Todo(title: 'Clean your room');
|
2017-02-22 03:13:08 +00:00
|
|
|
var creation = await todoService.create(todo.toJson());
|
|
|
|
print('Creation: $creation');
|
|
|
|
|
|
|
|
var id = creation['id'];
|
|
|
|
var result = await todoService.read(id);
|
|
|
|
|
|
|
|
print('Response: $result');
|
|
|
|
expect(result, isMap);
|
|
|
|
expect(result['id'], equals(id));
|
|
|
|
expect(result['title'], equals(todo.title));
|
|
|
|
expect(result['completed'], equals(todo.completed));
|
|
|
|
});
|
|
|
|
|
2017-04-10 02:11:48 +00:00
|
|
|
test('modify', () async {
|
2021-02-21 02:47:23 +00:00
|
|
|
var todo = Todo(title: 'Clean your room');
|
2017-02-22 03:13:08 +00:00
|
|
|
var creation = await todoService.create(todo.toJson());
|
|
|
|
print('Creation: $creation');
|
|
|
|
|
|
|
|
var id = creation['id'];
|
2017-04-10 02:11:48 +00:00
|
|
|
var result = await todoService.modify(id, {'title': 'Eat healthy'});
|
2017-02-22 03:13:08 +00:00
|
|
|
|
|
|
|
print('Response: $result');
|
|
|
|
expect(result, isMap);
|
|
|
|
expect(result['id'], equals(id));
|
|
|
|
expect(result['title'], equals('Eat healthy'));
|
|
|
|
expect(result['completed'], equals(todo.completed));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('remove', () async {
|
2021-02-21 02:47:23 +00:00
|
|
|
var todo = Todo(title: 'Clean your room');
|
2017-02-22 03:13:08 +00:00
|
|
|
var creation = await todoService.create(todo.toJson());
|
|
|
|
print('Creation: $creation');
|
|
|
|
|
|
|
|
var id = creation['id'];
|
|
|
|
var result = await todoService.remove(id);
|
|
|
|
|
|
|
|
print('Response: $result');
|
|
|
|
expect(result, isMap);
|
|
|
|
expect(result['id'], equals(id));
|
|
|
|
expect(result['title'], equals(todo.title));
|
|
|
|
expect(result['completed'], equals(todo.completed));
|
|
|
|
});
|
|
|
|
}
|