platform/packages/framework/test/general_test.dart

40 lines
1.1 KiB
Dart
Raw Normal View History

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-10-22 15:54:41 +00:00
import 'package:angel_framework/http.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 {
2019-05-02 22:48:31 +00:00
app = Angel(reflector: MirrorsReflector())
..post('/foo', (req, res) => res.serialize({'hello': 'world'}))
2019-05-02 22:48:31 +00:00
..all('*', (req, res) => throw AngelHttpException.notFound());
client = http.Client();
2017-03-02 22:06:02 +00:00
2019-05-02 22:48:31 +00:00
server = await 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 {
2021-03-06 14:28:33 +00:00
var response = await client.get(Uri.parse('$url/foo'),
headers: {'X-HTTP-Method-Override': 'POST'});
2017-03-02 22:06:02 +00:00
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
});
}