From f81a44623d59d1a6849e83e95a968a8df5da4a4d Mon Sep 17 00:00:00 2001 From: joshaber Date: Tue, 31 May 2016 15:18:04 -0400 Subject: [PATCH] Created an in memory store for use in tests. --- test/in-memory-store.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/in-memory-store.ts diff --git a/test/in-memory-store.ts b/test/in-memory-store.ts new file mode 100644 index 0000000000..fbe262bcb7 --- /dev/null +++ b/test/in-memory-store.ts @@ -0,0 +1,29 @@ +export default class InMemoryStore { + private store: {[key: string]: string} + private secureStore: {[key: string]: string} + + public constructor() { + this.store = {} + this.secureStore = {} + } + + private secureKey(key: string, login: string): string { + return `__key/${key}/${login}` + } + + public setItem(key: string, loginOrValue: string, secureValue?: string) { + if (secureValue) { + this.secureStore[this.secureKey(key, loginOrValue)] = secureValue + } else { + this.store[key] = loginOrValue + } + } + + public getItem(key: string, login?: string): string { + if (login) { + return this.secureStore[this.secureKey(key, login)] + } else { + return this.store[key] + } + } +}