Migrated test
This commit is contained in:
parent
7bd8e5a57b
commit
99c0bd9ada
6 changed files with 51 additions and 45 deletions
|
@ -17,7 +17,7 @@
|
|||
* Migrated json_god to 4.0.0 (13/13 tests passed)
|
||||
* Migrated angel_client to 4.0.0 (6/13 tests passed)
|
||||
* Migrated angel_websocket to 4.0.0 (2/3 tests passed)
|
||||
* Updated test to 3.0.0 (in progress)
|
||||
* Updated test to 4.0.0 (1/1 test passed)
|
||||
* Updated jael to 3.0.0 (in progress)
|
||||
* Updated jael_preprocessor to 3.0.0 (in progress)
|
||||
* Updated angel_jael to 3.0.0 (in progress)
|
||||
|
@ -41,7 +41,7 @@
|
|||
* Updated angel_validate to 3.0.0
|
||||
* Added and updated json_god to 3.0.0
|
||||
* Updated angel_client to 3.0.0
|
||||
* Updated angel_websocket to 3.0.0 (one issue to be resolved)
|
||||
* Updated angel_websocket to 3.0.0
|
||||
* Updated jael to 3.0.0
|
||||
* Updated jael_preprocessor to 3.0.0
|
||||
* Updated test to 3.0.0
|
||||
|
|
|
@ -6,8 +6,8 @@ import 'package:angel_websocket/server.dart';
|
|||
import 'package:test/test.dart';
|
||||
|
||||
main() {
|
||||
Angel app;
|
||||
TestClient client;
|
||||
Angel? app;
|
||||
late TestClient client;
|
||||
|
||||
setUp(() async {
|
||||
app = new Angel()
|
||||
|
@ -43,15 +43,15 @@ main() {
|
|||
index: ([params]) async => [
|
||||
{'michael': 'jackson'}
|
||||
],
|
||||
create: (data, [params]) async => {'foo': 'bar'}));
|
||||
create: (dynamic data, [params]) async => {'foo': 'bar'}));
|
||||
|
||||
var ws = new AngelWebSocket(app);
|
||||
await app.configure(ws.configureServer);
|
||||
app.all('/ws', ws.handleRequest);
|
||||
await app!.configure(ws.configureServer);
|
||||
app!.all('/ws', ws.handleRequest);
|
||||
|
||||
app.errorHandler = (e, req, res) => e.toJson();
|
||||
app!.errorHandler = (e, req, res) => e.toJson();
|
||||
|
||||
client = await connectTo(app);
|
||||
client = await connectTo(app!);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
|
|
|
@ -24,7 +24,7 @@ final Uuid _uuid = new Uuid();*/
|
|||
|
||||
/// Shorthand for bootstrapping a [TestClient].
|
||||
Future<TestClient> connectTo(Angel app,
|
||||
{Map initialSession,
|
||||
{Map? initialSession,
|
||||
bool autoDecodeGzip: true,
|
||||
bool useZone: false}) async {
|
||||
print("Load configuration");
|
||||
|
@ -58,9 +58,9 @@ class TestClient extends client.BaseAngelClient {
|
|||
final Angel server;
|
||||
|
||||
@override
|
||||
String authToken;
|
||||
String? authToken;
|
||||
|
||||
AngelHttp _http;
|
||||
late AngelHttp _http;
|
||||
|
||||
TestClient(this.server, {this.autoDecodeGzip: true, bool useZone: false})
|
||||
: super(http.IOClient(), '/') {
|
||||
|
@ -68,14 +68,14 @@ class TestClient extends client.BaseAngelClient {
|
|||
}
|
||||
|
||||
Future close() {
|
||||
this.client.close();
|
||||
this.client!.close();
|
||||
return server.close();
|
||||
}
|
||||
|
||||
/// Opens a WebSockets connection to the server. This will automatically bind the server
|
||||
/// over HTTP, if it is not already listening. Unfortunately, WebSockets cannot be mocked (yet!).
|
||||
Future<client.WebSockets> websocket(
|
||||
{String path: '/ws', Duration timeout}) async {
|
||||
{String path: '/ws', Duration? timeout}) async {
|
||||
if (_http.server == null) await _http.startServer();
|
||||
var url = _http.uri.replace(scheme: 'ws', path: path);
|
||||
var ws = _MockWebSockets(this, url.toString());
|
||||
|
@ -93,7 +93,7 @@ class TestClient extends client.BaseAngelClient {
|
|||
rq.headers.add('authorization', 'Basic $encoded');
|
||||
} else if (rq.headers.value('authorization')?.startsWith('Basic ') ==
|
||||
true) {
|
||||
var encoded = rq.headers.value('authorization').substring(6);
|
||||
var encoded = rq.headers.value('authorization')!.substring(6);
|
||||
var decoded = utf8.decode(base64Url.decode(encoded));
|
||||
var oldRq = rq;
|
||||
var newRq = MockHttpRequest(rq.method, rq.uri.replace(userInfo: decoded));
|
||||
|
@ -139,14 +139,14 @@ class TestClient extends client.BaseAngelClient {
|
|||
isRedirect: rs.headers['location'] != null,
|
||||
headers: extractedHeaders,
|
||||
persistentConnection:
|
||||
rq.headers.value('connection')?.toLowerCase()?.trim() ==
|
||||
rq.headers.value('connection')?.toLowerCase().trim() ==
|
||||
'keep-alive',
|
||||
//|| keepAliveState,
|
||||
reasonPhrase: rs.reasonPhrase);
|
||||
}
|
||||
|
||||
@override
|
||||
String basePath;
|
||||
late String basePath;
|
||||
|
||||
@override
|
||||
Stream<String> authenticateViaPopup(String url, {String eventName: 'token'}) {
|
||||
|
@ -160,7 +160,7 @@ class TestClient extends client.BaseAngelClient {
|
|||
|
||||
@override
|
||||
client.Service<Id, Data> service<Id, Data>(String path,
|
||||
{Type type, client.AngelDeserializer<Data> deserializer}) {
|
||||
{Type? type, client.AngelDeserializer<Data>? deserializer}) {
|
||||
String uri = path.toString().replaceAll(_straySlashes, "");
|
||||
return _services.putIfAbsent(uri,
|
||||
() => _MockService<Id, Data>(this, uri, deserializer: deserializer))
|
||||
|
@ -172,12 +172,12 @@ class _MockService<Id, Data> extends client.BaseAngelService<Id, Data> {
|
|||
final TestClient _app;
|
||||
|
||||
_MockService(this._app, String basePath,
|
||||
{client.AngelDeserializer<Data> deserializer})
|
||||
{client.AngelDeserializer<Data>? deserializer})
|
||||
: super(null, _app, basePath, deserializer: deserializer);
|
||||
|
||||
@override
|
||||
Future<StreamedResponse> send(http.BaseRequest request) {
|
||||
if (app.authToken != null && app.authToken.isNotEmpty) {
|
||||
if (app.authToken != null && app.authToken!.isNotEmpty) {
|
||||
request.headers['authorization'] ??= 'Bearer ${app.authToken}';
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,9 @@ import 'package:angel_validate/angel_validate.dart';
|
|||
///
|
||||
/// You can optionally check for a matching [message], [statusCode] and [errors].
|
||||
Matcher isAngelHttpException(
|
||||
{String message, int statusCode, Iterable<String> errors: const []}) =>
|
||||
{String? message,
|
||||
int? statusCode,
|
||||
Iterable<String> errors: const []}) =>
|
||||
new _IsAngelHttpException(
|
||||
message: message, statusCode: statusCode, errors: errors);
|
||||
|
||||
|
@ -98,7 +100,7 @@ class _HasContentType extends Matcher {
|
|||
if (!item.headers.containsKey('content-type')) return false;
|
||||
|
||||
if (contentType is ContentType) {
|
||||
var compare = ContentType.parse(item.headers['content-type']);
|
||||
var compare = ContentType.parse(item.headers['content-type']!);
|
||||
return equals(contentType.mimeType)
|
||||
.matches(compare.mimeType, matchState);
|
||||
} else {
|
||||
|
@ -136,7 +138,7 @@ class _HasHeader extends Matcher {
|
|||
Iterable v = value is Iterable ? (value as Iterable) : [value];
|
||||
return v
|
||||
.map((x) => x.toString())
|
||||
.every(item.headers[key.toLowerCase()].split(',').contains);
|
||||
.every(item.headers[key.toLowerCase()]!.split(',').contains);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
|
@ -182,13 +184,13 @@ class _HasValidBody extends Matcher {
|
|||
}
|
||||
|
||||
class _IsAngelHttpException extends Matcher {
|
||||
String message;
|
||||
int statusCode;
|
||||
String? message;
|
||||
int? statusCode;
|
||||
final List<String> errors = [];
|
||||
|
||||
_IsAngelHttpException(
|
||||
{this.message, this.statusCode, Iterable<String> errors: const []}) {
|
||||
this.errors.addAll(errors ?? []);
|
||||
this.errors.addAll(errors);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -2,40 +2,44 @@ author: Tobe O <thosakwe@gmail.com>
|
|||
description: Testing utility library for the Angel framework. Use with package:test.
|
||||
homepage: https://github.com/angel-dart/test.git
|
||||
name: angel_test
|
||||
version: 3.0.0
|
||||
version: 4.0.0
|
||||
publish_to: none
|
||||
environment:
|
||||
sdk: ">=2.10.0 <3.0.0"
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
dependencies:
|
||||
angel_client:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/client
|
||||
angel_framework:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/framework
|
||||
angel_http_exception:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/http_exception
|
||||
angel_validate:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/validate
|
||||
angel_websocket:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/websocket
|
||||
http: ^0.13.0
|
||||
matcher: ^0.12.0
|
||||
mock_request: ^1.0.0
|
||||
web_socket_channel: ^1.2.0
|
||||
http: ^0.13.1
|
||||
matcher: ^0.12.10
|
||||
mock_request:
|
||||
git:
|
||||
url: https://github.com/dukefirehawk/angel.git
|
||||
ref: sdk-2.12.x_nnbd
|
||||
path: packages/mock_request
|
||||
web_socket_channel: ^2.0.0
|
||||
dev_dependencies:
|
||||
test: ^1.15.7
|
||||
test: ^1.17.1
|
||||
|
||||
|
|
|
@ -6,13 +6,13 @@ import 'package:angel_websocket/server.dart';
|
|||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
Angel app;
|
||||
TestClient client;
|
||||
Angel? app;
|
||||
late TestClient client;
|
||||
|
||||
setUp(() async {
|
||||
app = Angel(reflector: MirrorsReflector())
|
||||
..get('/hello', (req, res) => 'Hello')
|
||||
..get('/user_info', (req, res) => {'u': req.uri.userInfo})
|
||||
..get('/user_info', (req, res) => {'u': req.uri!.userInfo})
|
||||
..get(
|
||||
'/error',
|
||||
(req, res) => throw AngelHttpException.forbidden(message: 'Test')
|
||||
|
@ -48,12 +48,12 @@ void main() {
|
|||
<String, dynamic>{'foo': 'bar'}));
|
||||
|
||||
var ws = AngelWebSocket(app);
|
||||
await app.configure(ws.configureServer);
|
||||
app.all('/ws', ws.handleRequest);
|
||||
await app!.configure(ws.configureServer);
|
||||
app!.all('/ws', ws.handleRequest);
|
||||
|
||||
app.errorHandler = (e, req, res) => e.toJson();
|
||||
app!.errorHandler = (e, req, res) => e.toJson();
|
||||
|
||||
client = await connectTo(app, useZone: false);
|
||||
client = await connectTo(app!, useZone: false);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
|
|
Loading…
Reference in a new issue