platform/test/repeat_request_test.dart

34 lines
1.1 KiB
Dart
Raw Normal View History

2017-08-28 15:29:27 +00:00
import 'dart:async';
import 'dart:convert';
2018-08-19 15:33:25 +00:00
import 'package:angel_container/mirrors.dart';
2017-08-28 15:29:27 +00:00
import 'package:angel_framework/angel_framework.dart';
2018-10-22 15:54:41 +00:00
import 'package:angel_framework/http.dart';
2017-08-28 15:29:27 +00:00
import 'package:mock_request/mock_request.dart';
import 'package:test/test.dart';
main() {
MockHttpRequest mk(int id) {
2019-05-02 22:48:31 +00:00
return MockHttpRequest('GET', Uri.parse('/test/$id'))..close();
2017-08-28 15:29:27 +00:00
}
test('can request the same url twice', () async {
2019-05-02 22:48:31 +00:00
var app = Angel(reflector: MirrorsReflector())
..get('/test/:id', ioc((id) => 'Hello $id'));
2017-08-28 15:29:27 +00:00
var rq1 = mk(1), rq2 = mk(2), rq3 = mk(1);
2019-05-02 22:48:31 +00:00
await Future.wait([rq1, rq2, rq3].map(AngelHttp(app).handleRequest));
2018-06-08 07:06:26 +00:00
var body1 = await rq1.response.transform(utf8.decoder).join(),
body2 = await rq2.response.transform(utf8.decoder).join(),
body3 = await rq3.response.transform(utf8.decoder).join();
2017-08-28 15:29:27 +00:00
print('Response #1: $body1');
print('Response #2: $body2');
print('Response #3: $body3');
expect(
body1,
allOf(
isNot(body2),
equals(body3),
));
});
}