2017-12-10 05:13:31 +00:00
|
|
|
import 'package:async/async.dart';
|
|
|
|
import 'dart:io';
|
|
|
|
import 'package:angel_client/io.dart' as c;
|
|
|
|
import 'package:angel_framework/angel_framework.dart' as s;
|
2018-10-22 23:05:11 +00:00
|
|
|
import 'package:angel_framework/http.dart' as s;
|
2019-04-20 15:21:15 +00:00
|
|
|
import 'package:pedantic/pedantic.dart';
|
2017-12-10 05:13:31 +00:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
main() {
|
|
|
|
HttpServer server;
|
|
|
|
c.Angel app;
|
|
|
|
c.ServiceList list;
|
|
|
|
StreamQueue queue;
|
|
|
|
|
|
|
|
setUp(() async {
|
|
|
|
var serverApp = new s.Angel();
|
2018-06-23 00:18:38 +00:00
|
|
|
var http = new s.AngelHttp(serverApp);
|
2017-12-10 05:13:31 +00:00
|
|
|
serverApp.use('/api/todos', new s.MapService(autoIdAndDateFields: false));
|
|
|
|
|
2018-06-23 00:18:38 +00:00
|
|
|
server = await http.startServer();
|
2017-12-10 05:13:31 +00:00
|
|
|
var uri = 'http://${server.address.address}:${server.port}';
|
|
|
|
app = new c.Rest(uri);
|
|
|
|
list = new c.ServiceList(app.service('api/todos'));
|
|
|
|
queue = new StreamQueue(list.onChange);
|
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() async {
|
|
|
|
await server.close(force: true);
|
|
|
|
await list.close();
|
|
|
|
await list.service.close();
|
|
|
|
await app.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('listens on create', () async {
|
2019-04-20 15:21:15 +00:00
|
|
|
unawaited(list.service.create({'foo': 'bar'}));
|
2017-12-10 05:13:31 +00:00
|
|
|
await list.onChange.first;
|
2018-08-26 22:41:01 +00:00
|
|
|
expect(list, [
|
|
|
|
{'foo': 'bar'}
|
|
|
|
]);
|
2017-12-10 05:13:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('listens on modify', () async {
|
2019-04-20 15:21:15 +00:00
|
|
|
unawaited(list.service.create({'id': 1, 'foo': 'bar'}));
|
2017-12-10 05:13:31 +00:00
|
|
|
await queue.next;
|
|
|
|
|
|
|
|
await list.service.update(1, {'id': 1, 'bar': 'baz'});
|
|
|
|
await queue.next;
|
2018-08-26 22:41:01 +00:00
|
|
|
expect(list, [
|
|
|
|
{'id': 1, 'bar': 'baz'}
|
|
|
|
]);
|
2017-12-10 05:13:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('listens on remove', () async {
|
2019-04-20 15:21:15 +00:00
|
|
|
unawaited(list.service.create({'id': '1', 'foo': 'bar'}));
|
2017-12-10 05:13:31 +00:00
|
|
|
await queue.next;
|
|
|
|
|
|
|
|
await list.service.remove('1');
|
|
|
|
await queue.next;
|
|
|
|
expect(list, isEmpty);
|
|
|
|
});
|
2018-08-26 22:41:01 +00:00
|
|
|
}
|