diff --git a/src/storage-provider-local.test.ts b/src/storage-provider-local.test.ts index 053fe0a..aa8434d 100644 --- a/src/storage-provider-local.test.ts +++ b/src/storage-provider-local.test.ts @@ -15,6 +15,18 @@ describe('LocalStorageProvider', () => { expect(await store.get('key4')).toBe(true); }); + it('should support custom storage key', async () => { + const store1 = new LocalStorageProvider('custom-storage-key'); + const store2 = new LocalStorageProvider('custom-storage-key'); + const store3 = new LocalStorageProvider('another-custom-storage-key'); + + await store1.save('key1', 'value1'); + + expect(await store1.get('key1')).toBe('value1'); + expect(await store2.get('key1')).toBe('value1'); + expect(await store3.get('key1')).toBe(undefined); + }); + it('should return undefined for empty value', async () => { const store = new LocalStorageProvider(); expect(await store.get('notDefinedKey')).toBe(undefined); diff --git a/src/storage-provider-local.ts b/src/storage-provider-local.ts index 3f362a9..0ffde1f 100644 --- a/src/storage-provider-local.ts +++ b/src/storage-provider-local.ts @@ -1,7 +1,11 @@ import type IStorageProvider from './storage-provider'; export default class LocalStorageProvider implements IStorageProvider { - private prefix = 'unleash:repository'; + private prefix: string; + + constructor(name = 'unleash:repository') { + this.prefix = name; + } public async save(name: string, data: any) { const repo = JSON.stringify(data);