2017-03-02 22:06:02 +00:00
|
|
|
import 'dart:io';
|
2021-05-14 10:34:09 +00:00
|
|
|
import 'package:angel3_container/mirrors.dart';
|
|
|
|
import 'package:angel3_framework/angel3_framework.dart';
|
|
|
|
import 'package:angel3_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';
|
|
|
|
|
2021-05-14 10:34:09 +00:00
|
|
|
void main() {
|
2021-04-03 05:50:52 +00:00
|
|
|
late Angel app;
|
|
|
|
late http.Client client;
|
2021-03-20 08:11:18 +00:00
|
|
|
late HttpServer server;
|
2021-04-03 05:50:52 +00:00
|
|
|
late String url;
|
2017-03-02 22:06:02 +00:00
|
|
|
|
|
|
|
setUp(() async {
|
2019-05-02 22:48:31 +00:00
|
|
|
app = Angel(reflector: MirrorsReflector())
|
2018-08-20 20:21:06 +00:00
|
|
|
..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();
|
2021-07-08 02:42:40 +00:00
|
|
|
url = 'http://${server.address.host}:${server.port}';
|
2017-03-02 22:06:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() async {
|
2021-04-03 05:50:52 +00:00
|
|
|
client.close();
|
2017-03-02 22:06:02 +00:00
|
|
|
await server.close(force: true);
|
|
|
|
});
|
|
|
|
|
2021-07-08 02:42:40 +00:00
|
|
|
test('allow override of method', () async {
|
2021-04-03 05:50:52 +00:00
|
|
|
var response = await client.get(Uri.parse('$url/foo'),
|
2021-03-06 14:28:33 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
}
|