Test remove all

This commit is contained in:
Tobe O 2018-11-06 01:06:45 -05:00
parent e4969b0220
commit 03789b20b0
2 changed files with 18 additions and 0 deletions

View file

@ -151,6 +151,14 @@ class SembastService extends Service<String, Map<String, dynamic>> {
@override
Future<Map<String, dynamic>> remove(String id,
[Map<String, dynamic> params]) async {
if (id == null ||
id == 'null' &&
(allowRemoveAll == true ||
params?.containsKey('provider') != true)) {
await store.deleteAll(await store.findKeys(new Finder()));
return {};
}
return database.transaction((txn) async {
var store = txn.getStore(this.store.name);
var record = await store.get(int.parse(id)) as Map<String, dynamic>;

View file

@ -66,6 +66,16 @@ main() async {
expect(await database.get(id), isNull);
});
test('remove', () async {
await service.create({'bar': 'baz'});
await service.create({'bar': 'baz'});
await service.create({'bar': 'baz'});
expect(await service.index(), isNotEmpty);
await service.remove(null);
expect(await service.index(), isEmpty);
});
test('remove nonexistent', () async {
expect(() => service.remove('440'),
throwsA(const TypeMatcher<AngelHttpException>()));