From 63266f588f6ddb2476e2cea4bab42a3864f77470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jovan=20Kruni=C4=87?= Date: Thu, 24 Jan 2019 14:41:21 +0100 Subject: [PATCH] feat(storage): support deletion of multiple entries --- src/app/modules/storage/storage.provider.spec.ts | 5 ++++- src/app/modules/storage/storage.provider.ts | 10 ++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/app/modules/storage/storage.provider.spec.ts b/src/app/modules/storage/storage.provider.spec.ts index 99aadcd0..1c888c4d 100644 --- a/src/app/modules/storage/storage.provider.spec.ts +++ b/src/app/modules/storage/storage.provider.spec.ts @@ -104,7 +104,7 @@ describe('StorageProvider', () => { expect(Array.from(entries.keys()).sort()).toEqual(['bar', 'foo', 'foo.bar']); }); - it('should delete one entry', async () => { + it('should delete one or more entries from the storage', async () => { spyOn(storage, 'remove').and.callThrough(); await storageProvider.putMultiple(sampleEntries); let entries = await storageProvider.getAll(); @@ -114,6 +114,9 @@ describe('StorageProvider', () => { expect(storage.remove).toHaveBeenCalled(); entries = await storageProvider.getAll(); expect(Array.from(entries.values())).toEqual(['Bar', 123]); + + await storageProvider.delete('foo', 'foo.bar'); + expect(await storageProvider.length()).toBe(0); }); it('should delete all entries in the storage', async () => { diff --git a/src/app/modules/storage/storage.provider.ts b/src/app/modules/storage/storage.provider.ts index 802f3844..536c91e2 100644 --- a/src/app/modules/storage/storage.provider.ts +++ b/src/app/modules/storage/storage.provider.ts @@ -81,12 +81,14 @@ export class StorageProvider { } /** - * Deletes a storage entry using the key used to save it + * Deletes storage entries using keys used to save them * - * @param key Unique identifier of the resource + * @param keys Unique identifiers of the resources for deletion */ - async delete(key: string): Promise { - return this.storage.remove(key); + async delete(...keys: string[]): Promise { + await keys.forEach((key) => { + this.storage.remove(key); + }); } /**