platform/packages/framework/test/anonymous_service_test.dart

45 lines
1.3 KiB
Dart
Raw Normal View History

2021-05-14 10:34:09 +00:00
import 'package:angel3_framework/angel3_framework.dart';
2017-06-29 22:17:42 +00:00
import 'package:test/test.dart';
2021-07-08 02:42:40 +00:00
void main() {
2017-06-29 22:17:42 +00:00
test('custom methods', () async {
2021-03-20 08:11:18 +00:00
var svc = AnonymousService<String?, String?>(
2018-10-21 08:44:51 +00:00
index: ([p]) async => ['index'],
2017-06-29 22:17:42 +00:00
read: (id, [p]) async => 'read',
create: (data, [p]) async => 'create',
modify: (id, data, [p]) async => 'modify',
update: (id, data, [p]) async => 'update',
remove: (id, [p]) async => 'remove');
2018-10-21 08:54:49 +00:00
expect(await svc.index(), ['index']);
2017-06-29 22:17:42 +00:00
expect(await svc.read(null), 'read');
expect(await svc.create(null), 'create');
expect(await svc.modify(null, null), 'modify');
expect(await svc.update(null, null), 'update');
expect(await svc.remove(null), 'remove');
});
test('defaults to throwing', () async {
try {
2019-05-02 22:48:31 +00:00
var svc = AnonymousService();
2017-06-29 22:17:42 +00:00
await svc.read(1);
throw 'Should have thrown 405!';
} on AngelHttpException {
// print('Ok!');
}
try {
2019-05-02 22:48:31 +00:00
var svc = AnonymousService();
2017-06-29 22:17:42 +00:00
await svc.modify(2, null);
throw 'Should have thrown 405!';
} on AngelHttpException {
// print('Ok!');
}
try {
2019-05-02 22:48:31 +00:00
var svc = AnonymousService();
2017-06-29 22:17:42 +00:00
await svc.update(3, null);
throw 'Should have thrown 405!';
} on AngelHttpException {
// print('Ok!');
}
});
}