Broken
This commit is contained in:
parent
c700a399e4
commit
e7e711340b
4 changed files with 57 additions and 18 deletions
|
@ -81,7 +81,7 @@ abstract class BaseAngelClient extends Angel {
|
||||||
if (json is! Map ||
|
if (json is! Map ||
|
||||||
!json.containsKey('data') ||
|
!json.containsKey('data') ||
|
||||||
!json.containsKey('token')) {
|
!json.containsKey('token')) {
|
||||||
throw new AngelHttpException.NotAuthenticated(
|
throw new AngelHttpException.notAuthenticated(
|
||||||
message:
|
message:
|
||||||
"Auth endpoint '$url' did not return a proper response.");
|
"Auth endpoint '$url' did not return a proper response.");
|
||||||
}
|
}
|
||||||
|
@ -200,6 +200,10 @@ class BaseAngelService extends Service {
|
||||||
var request = new http.Request(method, url);
|
var request = new http.Request(method, url);
|
||||||
|
|
||||||
if (headers != null) request.headers.addAll(headers);
|
if (headers != null) request.headers.addAll(headers);
|
||||||
|
|
||||||
|
if (app.authToken?.isNotEmpty == true)
|
||||||
|
request.headers['Authorization'] = 'Bearer ${app.authToken}';
|
||||||
|
|
||||||
if (encoding != null) request.encoding = encoding;
|
if (encoding != null) request.encoding = encoding;
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
if (body is String) {
|
if (body is String) {
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
import 'package:angel_client/browser.dart';
|
|
||||||
import 'package:test/test.dart';
|
|
||||||
|
|
||||||
main() async {
|
|
||||||
test("list todos", () async {
|
|
||||||
Angel app = new Rest("http://localhost:3001");
|
|
||||||
Service Todos = app.service("todos");
|
|
||||||
|
|
||||||
print(await Todos.index());
|
|
||||||
});
|
|
||||||
}
|
|
37
test/browser_test.dart
Normal file
37
test/browser_test.dart
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
@TestOn('browser')
|
||||||
|
import 'package:angel_client/browser.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
import 'for_browser_tests.dart';
|
||||||
|
|
||||||
|
main() {
|
||||||
|
test("list todos", () async {
|
||||||
|
var channel = spawnHybridCode(SERVER);
|
||||||
|
int port = await channel.stream.first;
|
||||||
|
var url = "http://localhost:$port";
|
||||||
|
print(url);
|
||||||
|
var app = new Rest(url);
|
||||||
|
var todoService = app.service("todos");
|
||||||
|
|
||||||
|
var todos = await todoService.index();
|
||||||
|
expect(todos, isEmpty);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('create todos', () async {
|
||||||
|
var channel = spawnHybridCode(SERVER);
|
||||||
|
int port = await channel.stream.first;
|
||||||
|
var url = "http://localhost:$port";
|
||||||
|
print(url);
|
||||||
|
var app = new Rest(url);
|
||||||
|
var todoService = app.service("todos");
|
||||||
|
|
||||||
|
var data = {'hello': 'world'};
|
||||||
|
var response = await todoService.create(data);
|
||||||
|
print('Created response: $response');
|
||||||
|
|
||||||
|
var todos = await todoService.index();
|
||||||
|
expect(todos, hasLength(1));
|
||||||
|
|
||||||
|
Map todo = todos.first;
|
||||||
|
expect(todo, equals(data));
|
||||||
|
});
|
||||||
|
}
|
|
@ -1,21 +1,30 @@
|
||||||
|
const String SERVER = '''
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import "package:angel_framework/angel_framework.dart";
|
import "package:angel_framework/angel_framework.dart";
|
||||||
import "package:angel_framework/src/defs.dart";
|
import "package:angel_framework/src/defs.dart";
|
||||||
|
import 'package:stream_channel/stream_channel.dart';
|
||||||
|
|
||||||
|
hybridMain(StreamChannel channel) async {
|
||||||
|
var app = new Angel();
|
||||||
|
|
||||||
main() async {
|
|
||||||
Angel app = new Angel();
|
|
||||||
app.before.add((req, ResponseContext res) {
|
app.before.add((req, ResponseContext res) {
|
||||||
res.header("Access-Control-Allow-Origin", "*");
|
res.headers["Access-Control-Allow-Origin"] = "*";
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use("/todos", new MemoryService<Todo>());
|
app.use("/todos", new MemoryService<Todo>());
|
||||||
|
|
||||||
await app.startServer(InternetAddress.LOOPBACK_IP_V4, 3001);
|
var server = await app.startServer(InternetAddress.LOOPBACK_IP_V4, 0);
|
||||||
print("Server up on localhost:3001");
|
|
||||||
|
print("Server up; listening at http://localhost:\${server.port}");
|
||||||
|
channel.sink.add(server.port);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Todo extends MemoryModel {
|
class Todo extends MemoryModel {
|
||||||
String hello;
|
String hello;
|
||||||
|
|
||||||
Todo({String this.hello});
|
Todo({int id, this.hello}) {
|
||||||
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
''';
|
||||||
|
|
Loading…
Reference in a new issue