Test remove all
This commit is contained in:
parent
e4969b0220
commit
03789b20b0
2 changed files with 18 additions and 0 deletions
|
@ -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>;
|
||||
|
|
|
@ -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>()));
|
||||
|
|
Loading…
Reference in a new issue