Created an in memory store for use in tests.

This commit is contained in:
joshaber 2016-05-31 15:18:04 -04:00
parent fa0fa3cb81
commit f81a44623d

29
test/in-memory-store.ts Normal file
View file

@ -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]
}
}
}