Fixed framework test cases
This commit is contained in:
parent
b7728bc761
commit
00663ef667
5 changed files with 36 additions and 35 deletions
|
@ -31,8 +31,8 @@ main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("allow override of method", () async {
|
test("allow override of method", () async {
|
||||||
var response = await client
|
var response = await client.get(Uri.parse('$url/foo'),
|
||||||
.get('$url/foo', headers: {'X-HTTP-Method-Override': 'POST'});
|
headers: {'X-HTTP-Method-Override': 'POST'});
|
||||||
print('Response: ${response.body}');
|
print('Response: ${response.body}');
|
||||||
expect(json.decode(response.body), equals({'hello': 'world'}));
|
expect(json.decode(response.body), equals({'hello': 'world'}));
|
||||||
});
|
});
|
||||||
|
|
|
@ -59,7 +59,7 @@ main() {
|
||||||
count++;
|
count++;
|
||||||
});
|
});
|
||||||
|
|
||||||
var response = await client.get("$url/todos");
|
var response = await client.get(Uri.parse("$url/todos"));
|
||||||
print(response.body);
|
print(response.body);
|
||||||
expect(count, equals(2));
|
expect(count, equals(2));
|
||||||
});
|
});
|
||||||
|
@ -73,7 +73,7 @@ main() {
|
||||||
event.cancel({"this_hook": "should never run"});
|
event.cancel({"this_hook": "should never run"});
|
||||||
});
|
});
|
||||||
|
|
||||||
var response = await client.post("$url/todos",
|
var response = await client.post(Uri.parse("$url/todos"),
|
||||||
body: json.encode({"arbitrary": "data"}),
|
body: json.encode({"arbitrary": "data"}),
|
||||||
headers: headers as Map<String, String>);
|
headers: headers as Map<String, String>);
|
||||||
print(response.body);
|
print(response.body);
|
||||||
|
@ -93,7 +93,7 @@ main() {
|
||||||
event.cancel({"this_hook": "should never run either"});
|
event.cancel({"this_hook": "should never run either"});
|
||||||
});
|
});
|
||||||
|
|
||||||
var response = await client.get("$url/todos");
|
var response = await client.get(Uri.parse("$url/todos"));
|
||||||
print(response.body);
|
print(response.body);
|
||||||
var result = json.decode(response.body) as List;
|
var result = json.decode(response.body) as List;
|
||||||
expect(result[0]["angel"], equals("framework"));
|
expect(result[0]["angel"], equals("framework"));
|
||||||
|
@ -121,7 +121,7 @@ main() {
|
||||||
print('Indexing books at path: ${e.request.path}');
|
print('Indexing books at path: ${e.request.path}');
|
||||||
});
|
});
|
||||||
|
|
||||||
var response = await client.get('$url/books');
|
var response = await client.get(Uri.parse('$url/books'));
|
||||||
print(response.body);
|
print(response.body);
|
||||||
|
|
||||||
var result = json.decode(response.body);
|
var result = json.decode(response.body);
|
||||||
|
|
|
@ -127,12 +127,12 @@ main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Can match basic url', () async {
|
test('Can match basic url', () async {
|
||||||
var response = await client.get("$url/hello");
|
var response = await client.get(Uri.parse("$url/hello"));
|
||||||
expect(response.body, equals('"world"'));
|
expect(response.body, equals('"world"'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Can match url with multiple parameters', () async {
|
test('Can match url with multiple parameters', () async {
|
||||||
var response = await client.get('$url/name/HELLO/last/WORLD');
|
var response = await client.get(Uri.parse('$url/name/HELLO/last/WORLD'));
|
||||||
print('Response: ${response.body}');
|
print('Response: ${response.body}');
|
||||||
var json_ = json.decode(response.body);
|
var json_ = json.decode(response.body);
|
||||||
expect(json_, const IsInstanceOf<Map>());
|
expect(json_, const IsInstanceOf<Map>());
|
||||||
|
@ -141,18 +141,18 @@ main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Chained routes', () async {
|
test('Chained routes', () async {
|
||||||
var response = await client.get("$url/chained");
|
var response = await client.get(Uri.parse("$url/chained"));
|
||||||
expect(response.body, equals('abc'));
|
expect(response.body, equals('abc'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Can nest another Angel instance', () async {
|
test('Can nest another Angel instance', () async {
|
||||||
var response = await client.post('$url/nes/ted/foo');
|
var response = await client.post(Uri.parse('$url/nes/ted/foo'));
|
||||||
var json_ = json.decode(response.body);
|
var json_ = json.decode(response.body);
|
||||||
expect(json_['route'], equals('foo'));
|
expect(json_['route'], equals('foo'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Can parse parameters from a nested Angel instance', () async {
|
test('Can parse parameters from a nested Angel instance', () async {
|
||||||
var response = await client.get('$url/todos/1337/action/test');
|
var response = await client.get(Uri.parse('$url/todos/1337/action/test'));
|
||||||
var json_ = json.decode(response.body);
|
var json_ = json.decode(response.body);
|
||||||
print('JSON: $json_');
|
print('JSON: $json_');
|
||||||
expect(json_['id'], equals('1337'));
|
expect(json_['id'], equals('1337'));
|
||||||
|
@ -160,27 +160,27 @@ main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Can add and use named middleware', () async {
|
test('Can add and use named middleware', () async {
|
||||||
var response = await client.get('$url/intercepted');
|
var response = await client.get(Uri.parse('$url/intercepted'));
|
||||||
expect(response.body, equals('Middleware'));
|
expect(response.body, equals('Middleware'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Middleware via metadata', () async {
|
test('Middleware via metadata', () async {
|
||||||
// Metadata
|
// Metadata
|
||||||
var response = await client.get('$url/meta');
|
var response = await client.get(Uri.parse('$url/meta'));
|
||||||
expect(response.body, equals('Middleware'));
|
expect(response.body, equals('Middleware'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Can serialize function result as JSON', () async {
|
test('Can serialize function result as JSON', () async {
|
||||||
Map headers = <String, String>{'Content-Type': 'application/json'};
|
Map headers = <String, String>{'Content-Type': 'application/json'};
|
||||||
String postData = json.encode({'it': 'works'});
|
String postData = json.encode({'it': 'works'});
|
||||||
var response = await client.post("$url/lambda",
|
var response = await client.post(Uri.parse("$url/lambda"),
|
||||||
headers: headers as Map<String, String>, body: postData);
|
headers: headers as Map<String, String>, body: postData);
|
||||||
print('Response: ${response.body}');
|
print('Response: ${response.body}');
|
||||||
expect(json.decode(response.body)['it'], equals('works'));
|
expect(json.decode(response.body)['it'], equals('works'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Fallback routes', () async {
|
test('Fallback routes', () async {
|
||||||
var response = await client.get('$url/my_favorite_artist');
|
var response = await client.get(Uri.parse('$url/my_favorite_artist'));
|
||||||
expect(response.body, equals('"MJ"'));
|
expect(response.body, equals('"MJ"'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -193,32 +193,32 @@ main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Redirect to named routes', () async {
|
test('Redirect to named routes', () async {
|
||||||
var response = await client.get('$url/named');
|
var response = await client.get(Uri.parse('$url/named'));
|
||||||
print(response.body);
|
print(response.body);
|
||||||
expect(json.decode(response.body), equals('Hello tests'));
|
expect(json.decode(response.body), equals('Hello tests'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Match routes, even with query params', () async {
|
test('Match routes, even with query params', () async {
|
||||||
var response =
|
var response = await client
|
||||||
await client.get("$url/log?foo=bar&bar=baz&baz.foo=bar&baz.bar=foo");
|
.get(Uri.parse("$url/log?foo=bar&bar=baz&baz.foo=bar&baz.bar=foo"));
|
||||||
print(response.body);
|
print(response.body);
|
||||||
expect(json.decode(response.body), equals('Logged'));
|
expect(json.decode(response.body), equals('Logged'));
|
||||||
|
|
||||||
response = await client.get("$url/query/foo?bar=baz");
|
response = await client.get(Uri.parse("$url/query/foo?bar=baz"));
|
||||||
print(response.body);
|
print(response.body);
|
||||||
expect(response.body, equals("Service with Middleware"));
|
expect(response.body, equals("Service with Middleware"));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('only match route with matching method', () async {
|
test('only match route with matching method', () async {
|
||||||
var response = await client.get("$url/method");
|
var response = await client.get(Uri.parse("$url/method"));
|
||||||
print(response.body);
|
print(response.body);
|
||||||
expect(response.body, '"Only GET"');
|
expect(response.body, '"Only GET"');
|
||||||
|
|
||||||
response = await client.post("$url/method");
|
response = await client.post(Uri.parse("$url/method"));
|
||||||
print(response.body);
|
print(response.body);
|
||||||
expect(response.body, '"Only POST"');
|
expect(response.body, '"Only POST"');
|
||||||
|
|
||||||
response = await client.patch("$url/method");
|
response = await client.patch(Uri.parse("$url/method"));
|
||||||
print(response.body);
|
print(response.body);
|
||||||
expect(response.body, '"MJ"');
|
expect(response.body, '"MJ"');
|
||||||
});
|
});
|
||||||
|
|
|
@ -35,11 +35,11 @@ main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("correct content-type", () async {
|
test("correct content-type", () async {
|
||||||
var response = await client.get('$url/foo');
|
var response = await client.get(Uri.parse('$url/foo'));
|
||||||
print('Response: ${response.body}');
|
print('Response: ${response.body}');
|
||||||
expect(response.headers['content-type'], contains('application/json'));
|
expect(response.headers['content-type'], contains('application/json'));
|
||||||
|
|
||||||
response = await client.get('$url/bar');
|
response = await client.get(Uri.parse('$url/bar'));
|
||||||
print('Response: ${response.body}');
|
print('Response: ${response.body}');
|
||||||
expect(response.headers['content-type'], contains('text/html'));
|
expect(response.headers['content-type'], contains('text/html'));
|
||||||
});
|
});
|
||||||
|
|
|
@ -44,7 +44,7 @@ main() {
|
||||||
|
|
||||||
group('memory', () {
|
group('memory', () {
|
||||||
test('can index an empty service', () async {
|
test('can index an empty service', () async {
|
||||||
var response = await client.get("$url/todos/");
|
var response = await client.get(Uri.parse("$url/todos/"));
|
||||||
print(response.body);
|
print(response.body);
|
||||||
expect(response.body, equals('[]'));
|
expect(response.body, equals('[]'));
|
||||||
print(response.body);
|
print(response.body);
|
||||||
|
@ -53,7 +53,7 @@ main() {
|
||||||
|
|
||||||
test('can create data', () async {
|
test('can create data', () async {
|
||||||
String postData = json.encode({'text': 'Hello, world!'});
|
String postData = json.encode({'text': 'Hello, world!'});
|
||||||
var response = await client.post("$url/todos",
|
var response = await client.post(Uri.parse("$url/todos"),
|
||||||
headers: headers as Map<String, String>, body: postData);
|
headers: headers as Map<String, String>, body: postData);
|
||||||
expect(response.statusCode, 201);
|
expect(response.statusCode, 201);
|
||||||
var jsons = json.decode(response.body);
|
var jsons = json.decode(response.body);
|
||||||
|
@ -63,9 +63,9 @@ main() {
|
||||||
|
|
||||||
test('can fetch data', () async {
|
test('can fetch data', () async {
|
||||||
String postData = json.encode({'text': 'Hello, world!'});
|
String postData = json.encode({'text': 'Hello, world!'});
|
||||||
await client.post("$url/todos",
|
await client.post(Uri.parse("$url/todos"),
|
||||||
headers: headers as Map<String, String>, body: postData);
|
headers: headers as Map<String, String>, body: postData);
|
||||||
var response = await client.get("$url/todos/0");
|
var response = await client.get(Uri.parse("$url/todos/0"));
|
||||||
expect(response.statusCode, 200);
|
expect(response.statusCode, 200);
|
||||||
var jsons = json.decode(response.body);
|
var jsons = json.decode(response.body);
|
||||||
print(jsons);
|
print(jsons);
|
||||||
|
@ -74,11 +74,11 @@ main() {
|
||||||
|
|
||||||
test('can modify data', () async {
|
test('can modify data', () async {
|
||||||
String postData = json.encode({'text': 'Hello, world!'});
|
String postData = json.encode({'text': 'Hello, world!'});
|
||||||
await client.post("$url/todos",
|
await client.post(Uri.parse("$url/todos"),
|
||||||
headers: headers as Map<String, String>, body: postData);
|
headers: headers as Map<String, String>, body: postData);
|
||||||
postData = json.encode({'text': 'modified'});
|
postData = json.encode({'text': 'modified'});
|
||||||
|
|
||||||
var response = await client.patch("$url/todos/0",
|
var response = await client.patch(Uri.parse("$url/todos/0"),
|
||||||
headers: headers as Map<String, String>, body: postData);
|
headers: headers as Map<String, String>, body: postData);
|
||||||
expect(response.statusCode, 200);
|
expect(response.statusCode, 200);
|
||||||
var jsons = json.decode(response.body);
|
var jsons = json.decode(response.body);
|
||||||
|
@ -88,11 +88,11 @@ main() {
|
||||||
|
|
||||||
test('can overwrite data', () async {
|
test('can overwrite data', () async {
|
||||||
String postData = json.encode({'text': 'Hello, world!'});
|
String postData = json.encode({'text': 'Hello, world!'});
|
||||||
await client.post("$url/todos",
|
await client.post(Uri.parse("$url/todos"),
|
||||||
headers: headers as Map<String, String>, body: postData);
|
headers: headers as Map<String, String>, body: postData);
|
||||||
postData = json.encode({'over': 'write'});
|
postData = json.encode({'over': 'write'});
|
||||||
|
|
||||||
var response = await client.post("$url/todos/0",
|
var response = await client.post(Uri.parse("$url/todos/0"),
|
||||||
headers: headers as Map<String, String>, body: postData);
|
headers: headers as Map<String, String>, body: postData);
|
||||||
expect(response.statusCode, 200);
|
expect(response.statusCode, 200);
|
||||||
var jsons = json.decode(response.body);
|
var jsons = json.decode(response.body);
|
||||||
|
@ -115,10 +115,11 @@ main() {
|
||||||
test('can delete data', () async {
|
test('can delete data', () async {
|
||||||
String postData = json.encode({'text': 'Hello, world!'});
|
String postData = json.encode({'text': 'Hello, world!'});
|
||||||
var created = await client
|
var created = await client
|
||||||
.post("$url/todos",
|
.post(Uri.parse("$url/todos"),
|
||||||
headers: headers as Map<String, String>, body: postData)
|
headers: headers as Map<String, String>, body: postData)
|
||||||
.then((r) => json.decode(r.body));
|
.then((r) => json.decode(r.body));
|
||||||
var response = await client.delete("$url/todos/${created['id']}");
|
var response =
|
||||||
|
await client.delete(Uri.parse("$url/todos/${created['id']}"));
|
||||||
expect(response.statusCode, 200);
|
expect(response.statusCode, 200);
|
||||||
var json_ = json.decode(response.body);
|
var json_ = json.decode(response.body);
|
||||||
print(json_);
|
print(json_);
|
||||||
|
@ -126,7 +127,7 @@ main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cannot remove all unless explicitly set', () async {
|
test('cannot remove all unless explicitly set', () async {
|
||||||
var response = await client.delete('$url/todos/null');
|
var response = await client.delete(Uri.parse('$url/todos/null'));
|
||||||
expect(response.statusCode, 403);
|
expect(response.statusCode, 403);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue