Fixed test cases

This commit is contained in:
thomashii 2021-03-05 15:51:48 +08:00
parent dd938c7512
commit 6875451993
6 changed files with 31 additions and 22 deletions

View file

@ -124,7 +124,7 @@ class AngelAuthResult {
/// Attempts to deserialize a response from a [Map].
factory AngelAuthResult.fromMap(Map data) {
final result = new AngelAuthResult();
final result = AngelAuthResult();
if (data is Map && data.containsKey('token') && data['token'] is String)
result._token = data['token'].toString();
@ -133,10 +133,10 @@ class AngelAuthResult {
result.data.addAll((data['data'] as Map<String, dynamic>) ?? {});
if (result.token == null) {
throw new FormatException(
throw FormatException(
'The required "token" field was not present in the given data.');
} else if (data['data'] is! Map) {
throw new FormatException(
throw FormatException(
'The required "data" field in the given data was not a map; instead, it was ${data['data']}.');
}
@ -145,7 +145,7 @@ class AngelAuthResult {
/// Attempts to deserialize a response from a [String].
factory AngelAuthResult.fromJson(String s) =>
new AngelAuthResult.fromMap(json.decode(s) as Map);
AngelAuthResult.fromMap(json.decode(s) as Map);
/// Converts this instance into a JSON-friendly representation.
Map<String, dynamic> toJson() {
@ -200,7 +200,7 @@ abstract class Service<Id, Data> {
///
/// Handy utility for handling data in a type-safe manner.
Service<Id, U> map<U>(U Function(Data) encoder, Data Function(U) decoder) {
return new _MappedService(this, encoder, decoder);
return _MappedService(this, encoder, decoder);
}
}
@ -215,7 +215,7 @@ class _MappedService<Id, Data, U> extends Service<Id, U> {
Angel get app => inner.app;
@override
Future close() => new Future.value();
Future close() => Future.value();
@override
Future<U> create(U data, [Map<String, dynamic> params]) {
@ -281,19 +281,18 @@ class ServiceList<Id, Data> extends DelegatingList<Data> {
final Service<Id, Data> service;
final StreamController<ServiceList<Id, Data>> _onChange =
new StreamController();
final StreamController<ServiceList<Id, Data>> _onChange = StreamController();
final List<StreamSubscription> _subs = [];
ServiceList(this.service, {this.idField = 'id', Equality<Data> equality})
: super([]) {
_equality = equality;
_equality ??= new EqualityBy<Data, Id>((map) {
_equality ??= EqualityBy<Data, Id>((map) {
if (map is Map)
return map[idField ?? 'id'] as Id;
else
throw new UnsupportedError(
throw UnsupportedError(
'ServiceList only knows how to find the id from a Map object. Provide a custom `Equality` in your call to the constructor.');
});
// Index

View file

@ -70,7 +70,11 @@ abstract class BaseAngelClient extends Angel {
var segments = baseUrl.pathSegments
.followedBy(p.split(authEndpoint))
.followedBy([type]);
var url = baseUrl.replace(path: p.joinAll(segments));
// TODO: convert windows path to proper url
var p1 = p.joinAll(segments).replaceAll('\\', '/');
var url = baseUrl.replace(path: p1);
http.Response response;
if (credentials != null) {

View file

@ -13,13 +13,13 @@ export 'angel_client.dart';
class Rest extends BaseAngelClient {
final List<Service> _services = [];
Rest(String path) : super(new http.Client() as http.BaseClient, path);
Rest(String path) : super(http.Client() as http.BaseClient, path);
@override
Service<Id, Data> service<Id, Data>(String path,
{Type type, AngelDeserializer deserializer}) {
var url = baseUrl.replace(path: p.join(baseUrl.path, path));
var s = new RestService<Id, Data>(client, this, url, type);
var s = RestService<Id, Data>(client, this, url, type);
_services.add(s);
return s;
}
@ -27,10 +27,11 @@ class Rest extends BaseAngelClient {
@override
Stream<String> authenticateViaPopup(String url,
{String eventName = 'token'}) {
throw new UnimplementedError(
throw UnimplementedError(
'Opening popup windows is not supported in the `dart:io` client.');
}
@override
Future close() async {
await super.close();
await Future.wait(_services.map((s) => s.close())).then((_) {
@ -48,6 +49,7 @@ class RestService<Id, Data> extends BaseAngelService<Id, Data> {
@override
Data deserialize(x) {
print(x);
if (type != null) {
return x.runtimeType == type
? x as Data
@ -58,7 +60,8 @@ class RestService<Id, Data> extends BaseAngelService<Id, Data> {
}
@override
makeBody(x) {
String makeBody(x) {
print(x);
if (type != null) {
return super.makeBody(god.serializeObject(x));
}

View file

@ -10,7 +10,8 @@ dependencies:
path: ../http_exception
collection: ^1.0.0
http: ^0.12.0
json_god: ">=2.0.0-beta <3.0.0"
json_god: ^2.0.0-beta
#dart_json_mapper: ^1.7.0
meta: ^1.0.0
path: ^1.0.0
dev_dependencies:

View file

@ -5,7 +5,7 @@ import 'package:file/memory.dart';
import 'package:logging/logging.dart';
import 'package:test/test.dart';
main() {
void main() {
Angel app;
MemoryFileSystem fileSystem;
TestClient client;
@ -48,6 +48,7 @@ main() {
test('serves as fallback', () async {
var response = await client.get('/nope');
print(response);
expect(response.body, 'index');
});
}

View file

@ -36,22 +36,23 @@ void main() {
await app.configure(auth.configureServer);
var sock = AngelWebSocket(app);
await app.configure(sock.configureServer);
app.all('/ws', sock.handleRequest);
app.logger = Logger('angel_auth')..onRecord.listen(print);
var server = await http.startServer();
client = c.Rest('http://${server.address.address}:${server.port}');
ws = c.WebSockets('ws://${server.address.address}:${server.port}/ws');
await ws.connect();
});
tearDown(() {
return Future.wait([
http.close(),
client.close(),
ws.close(),
]);
http.close();
client.close();
ws.close();
});
test('auth event fires', () async {