platform/test/simple_test.dart

68 lines
1.9 KiB
Dart
Raw Normal View History

2017-03-25 04:28:50 +00:00
import 'dart:convert';
2016-12-10 17:05:45 +00:00
import 'package:angel_framework/angel_framework.dart' as server;
2016-12-10 17:05:31 +00:00
import 'package:angel_test/angel_test.dart';
import 'package:test/test.dart';
main() {
2016-12-10 17:05:45 +00:00
server.Angel app;
2016-12-10 18:11:27 +00:00
TestClient testClient;
2016-12-10 17:05:31 +00:00
2016-12-10 17:05:45 +00:00
setUp(() async {
2016-12-10 18:11:27 +00:00
app = new server.Angel()
..get('/hello', 'Hello')
..post('/hello', (req, res) async {
return {'bar': req.body['foo']};
});
2016-12-10 17:05:45 +00:00
2016-12-10 18:11:27 +00:00
testClient = await connectTo(app);
2016-12-10 17:05:45 +00:00
});
2016-12-10 18:11:27 +00:00
tearDown(() async {
await testClient.close();
app = null;
});
2017-03-25 04:28:50 +00:00
test('mock()', () async {
var response = await mock(app, 'GET', Uri.parse('/hello'));
expect(await response.transform(UTF8.decoder).join(), equals('"Hello"'));
});
2016-12-10 18:11:27 +00:00
group('isJson+hasStatus', () {
test('get', () async {
final response = await testClient.get('/hello');
expect(response, isJson('Hello'));
});
test('post', () async {
final response = await testClient.post('/hello', body: {'foo': 'baz'});
expect(response, allOf(hasStatus(200), isJson({'bar': 'baz'})));
});
});
group('session', () {
test('initial session', () async {
2016-12-19 04:51:21 +00:00
final TestClient client = await connectTo(app,
initialSession: {'foo': 'bar'}, saveSession: true);
2016-12-10 18:11:27 +00:00
expect(client.session['foo'], equals('bar'));
});
test('add to session', () async {
2016-12-19 04:51:21 +00:00
final TestClient client = await connectTo(app, saveSession: true);
2016-12-10 18:11:27 +00:00
await client.addToSession({'michael': 'jackson'});
expect(client.session['michael'], equals('jackson'));
});
test('remove from session', () async {
2016-12-19 04:51:21 +00:00
final TestClient client = await connectTo(app,
initialSession: {'angel': 'framework'}, saveSession: true);
2016-12-10 18:11:27 +00:00
await client.removeFromSession(['angel']);
expect(client.session.containsKey('angel'), isFalse);
});
test('disable session', () async {
final client = await connectTo(app, saveSession: false);
expect(client.session, isNull);
});
});
}