2021-04-05 18:23:37 +02:00
|
|
|
import test from 'ava'
|
2021-04-13 20:50:56 +02:00
|
|
|
import SessionCache from './session-cache'
|
2021-04-05 18:23:37 +02:00
|
|
|
|
|
|
|
const fakeStorage = {
|
|
|
|
|
|
|
|
elements: {},
|
|
|
|
|
|
|
|
clear() {
|
|
|
|
this.elements = {}
|
|
|
|
},
|
|
|
|
|
|
|
|
getItem(key) {
|
|
|
|
const value = this.elements[key]
|
|
|
|
if (value === undefined) return null
|
|
|
|
return value
|
|
|
|
},
|
|
|
|
|
|
|
|
setItem(key, value) {
|
|
|
|
this.elements[key] = value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
test.afterEach(() => {
|
|
|
|
fakeStorage.clear()
|
|
|
|
})
|
|
|
|
|
|
|
|
test('#add & #get', t => {
|
|
|
|
SessionCache.add(fakeStorage, { a: 'b' }, { c: 'd' })
|
|
|
|
t.deepEqual(SessionCache.get(fakeStorage, { a: 'b' }), { c: 'd' })
|
|
|
|
})
|
|
|
|
|
|
|
|
test('#get no entry', t => {
|
|
|
|
t.is(SessionCache.get(fakeStorage, { a: 'bb' }), null)
|
|
|
|
})
|