platform/test/support_shelf_test.dart

50 lines
1.5 KiB
Dart
Raw Normal View History

2017-06-12 23:53:08 +00:00
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_shelf/angel_shelf.dart';
import 'package:angel_test/angel_test.dart';
2018-01-08 21:04:52 +00:00
import 'package:logging/logging.dart';
2017-06-12 23:53:08 +00:00
import 'package:shelf/shelf.dart' as shelf;
2018-01-09 14:44:59 +00:00
import 'package:stack_trace/stack_trace.dart';
2017-06-12 23:53:08 +00:00
import 'package:test/test.dart';
2018-01-08 21:04:52 +00:00
import 'pretty_logging.dart';
2017-06-12 23:53:08 +00:00
main() {
TestClient client;
setUp(() async {
var app = new Angel()..lazyParseBodies = true;
2018-01-09 14:44:59 +00:00
await app.configure(supportShelf());
2017-06-12 23:53:08 +00:00
app.get('/inject', (shelf.Request request) {
print('URL of injected request: ${request.url.path}');
return {'inject': request.url.path == 'inject'};
});
app.get('/hello', (shelf.Request request) {
return new shelf.Response.ok('world');
});
2018-01-08 21:04:52 +00:00
app.logger = new Logger.detached('angel')..onRecord.listen(prettyLog);
2017-06-12 23:53:08 +00:00
client = await connectTo(app);
});
tearDown(() => client.close());
test('injected into request', () async {
2018-01-09 14:44:59 +00:00
var response = await client.get('/inject', headers: {'accept': 'application/json'});
2017-06-12 23:53:08 +00:00
print('Response: ${response.body}');
expect(response, isJson({'inject': true}));
});
2018-01-09 14:44:59 +00:00
test('can return shelf response', () {
return Chain.capture(() async {
var response = await client.get('/hello', headers: {'accept': 'application/json'});
print('Response: ${response.body}');
expect(response, hasBody('world'));
}, onError: (e, chain) {
print(e);
print(chain.terse);
expect(0, 1);
});
2017-06-12 23:53:08 +00:00
});
}