2017-03-02 22:06:02 +00:00
|
|
|
import 'dart:io';
|
2018-08-19 15:33:25 +00:00
|
|
|
import 'package:angel_container/mirrors.dart';
|
2017-03-02 22:06:02 +00:00
|
|
|
import 'package:angel_framework/angel_framework.dart';
|
2018-08-20 03:06:29 +00:00
|
|
|
import 'dart:convert';
|
2017-03-02 22:06:02 +00:00
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
main() {
|
|
|
|
Angel app;
|
|
|
|
http.Client client;
|
|
|
|
HttpServer server;
|
|
|
|
String url;
|
|
|
|
|
|
|
|
setUp(() async {
|
2018-08-20 02:40:11 +00:00
|
|
|
app = new Angel(reflector: MirrorsReflector())
|
2018-08-20 20:21:06 +00:00
|
|
|
..post('/foo', (req, res) => res.serialize({'hello': 'world'}))
|
|
|
|
..all('*', (req, res) => throw new AngelHttpException.notFound());
|
2017-03-02 22:06:02 +00:00
|
|
|
client = new http.Client();
|
|
|
|
|
2018-02-07 05:36:24 +00:00
|
|
|
server = await new AngelHttp(app).startServer();
|
2017-03-02 22:06:02 +00:00
|
|
|
url = "http://${server.address.host}:${server.port}";
|
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() async {
|
|
|
|
app = null;
|
|
|
|
url = null;
|
|
|
|
client.close();
|
|
|
|
client = null;
|
|
|
|
await server.close(force: true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("allow override of method", () async {
|
|
|
|
var response = await client
|
|
|
|
.get('$url/foo', headers: {'X-HTTP-Method-Override': 'POST'});
|
|
|
|
print('Response: ${response.body}');
|
2018-06-08 07:06:26 +00:00
|
|
|
expect(json.decode(response.body), equals({'hello': 'world'}));
|
2017-03-02 22:06:02 +00:00
|
|
|
});
|
|
|
|
}
|