platform/test/basic_test.dart

53 lines
1.4 KiB
Dart
Raw Normal View History

2016-12-05 02:16:54 +00:00
import 'dart:io';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_cors/angel_cors.dart';
import 'package:http/http.dart' as http;
import 'package:test/test.dart';
main() {
Angel app;
http.Client client;
HttpServer server;
String url;
setUp(() async {
app = new Angel()
2017-11-18 17:30:39 +00:00
..before.add(cors(new CorsOptions()))
2016-12-05 02:16:54 +00:00
..post('/', (req, res) async {
2016-12-05 02:48:35 +00:00
res.write('hello world');
return false;
})
..all('*', () {
2017-04-15 19:45:29 +00:00
throw new AngelHttpException.notFound();
2016-12-05 02:16:54 +00:00
});
server = await app.startServer();
url = 'http://${server.address.address}:${server.port}';
client = new http.Client();
});
tearDown(() async {
await server.close(force: true);
app = null;
client = null;
url = null;
});
test('POST works', () async {
final response = await client.post(url);
expect(response.statusCode, equals(200));
2016-12-05 02:48:35 +00:00
print('Response: ${response.body}');
print('Headers: ${response.headers}');
2016-12-05 02:16:54 +00:00
expect(response.headers['access-control-allow-origin'], equals('*'));
});
2017-04-15 19:45:29 +00:00
test('mirror headers', () async {
2017-11-18 17:30:39 +00:00
final response = await client
.post(url, headers: {'access-control-request-headers': 'foo'});
2017-04-15 19:45:29 +00:00
expect(response.statusCode, equals(200));
print('Response: ${response.body}');
print('Headers: ${response.headers}');
expect(response.headers['access-control-allow-headers'], equals('foo'));
});
2016-12-05 02:16:54 +00:00
}