feat(storage): support deletion of multiple entries

This commit is contained in:
Jovan Krunić
2019-01-24 14:41:21 +01:00
parent 4334cad68c
commit 63266f588f
2 changed files with 10 additions and 5 deletions

View File

@@ -104,7 +104,7 @@ describe('StorageProvider', () => {
expect(Array.from(entries.keys()).sort()).toEqual(['bar', 'foo', 'foo.bar']); 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(); spyOn(storage, 'remove').and.callThrough();
await storageProvider.putMultiple(sampleEntries); await storageProvider.putMultiple(sampleEntries);
let entries = await storageProvider.getAll(); let entries = await storageProvider.getAll();
@@ -114,6 +114,9 @@ describe('StorageProvider', () => {
expect(storage.remove).toHaveBeenCalled(); expect(storage.remove).toHaveBeenCalled();
entries = await storageProvider.getAll(); entries = await storageProvider.getAll();
expect(Array.from(entries.values())).toEqual(['Bar', 123]); 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 () => { it('should delete all entries in the storage', async () => {

View File

@@ -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<void> { async delete(...keys: string[]): Promise<void> {
return this.storage.remove(key); await keys.forEach((key) => {
this.storage.remove(key);
});
} }
/** /**