diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2020-02-09 11:13:55 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2020-02-09 11:29:13 +0900 |
commit | b2fc46ebf79ebb1ffa068fb513d1eeb9b50d7b3f (patch) | |
tree | 7f3037b2f4f1f8ca8082e2fd573c5bab03a490aa /src/background/repositories/CachedSettingRepository.ts | |
parent | 4d5573356e30721431b74351d93691d6ce4da4a8 (diff) |
Add SettingUseCase tests
Diffstat (limited to 'src/background/repositories/CachedSettingRepository.ts')
-rw-r--r-- | src/background/repositories/CachedSettingRepository.ts | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/background/repositories/CachedSettingRepository.ts b/src/background/repositories/CachedSettingRepository.ts index b73d94a..1af15d4 100644 --- a/src/background/repositories/CachedSettingRepository.ts +++ b/src/background/repositories/CachedSettingRepository.ts @@ -1,12 +1,20 @@ -import { injectable } from 'tsyringe'; import MemoryStorage from '../infrastructures/MemoryStorage'; import Settings from '../../shared/settings/Settings'; import Properties from '../../shared/settings/Properties'; const CACHED_SETTING_KEY = 'setting'; -@injectable() -export default class CachedSettingRepository { +export default interface CachedSettingRepository { + get(): Promise<Settings>; + + update(value: Settings): Promise<void>; + + setProperty( + name: string, value: string | number | boolean, + ): Promise<void>; +} + +export class CachedSettingRepositoryImpl implements CachedSettingRepository { private cache: MemoryStorage; constructor() { @@ -18,8 +26,9 @@ export default class CachedSettingRepository { return Promise.resolve(Settings.fromJSON(data)); } - update(value: Settings): void { - return this.cache.set(CACHED_SETTING_KEY, value.toJSON()); + update(value: Settings): Promise<void> { + this.cache.set(CACHED_SETTING_KEY, value.toJSON()); + return Promise.resolve() } async setProperty( @@ -49,6 +58,6 @@ export default class CachedSettingRepository { current.properties.complete = newValue as string; break; } - return this.update(current); + await this.update(current); } } |