2021-04-05 18:23:37 +02:00
|
|
|
import test from 'ava'
|
2022-01-09 12:11:24 +01:00
|
|
|
import SessionCache from './session-cache.js'
|
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
|
2021-12-09 19:46:19 +01:00
|
|
|
},
|
2021-04-05 18:23:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
test.afterEach(() => {
|
|
|
|
fakeStorage.clear()
|
|
|
|
})
|
|
|
|
|
2021-12-09 19:46:19 +01:00
|
|
|
test('#add & #get', (t) => {
|
2021-04-05 18:23:37 +02:00
|
|
|
SessionCache.add(fakeStorage, { a: 'b' }, { c: 'd' })
|
|
|
|
t.deepEqual(SessionCache.get(fakeStorage, { a: 'b' }), { c: 'd' })
|
|
|
|
})
|
|
|
|
|
2021-12-09 19:46:19 +01:00
|
|
|
test('#get no entry', (t) => {
|
2021-04-05 18:23:37 +02:00
|
|
|
t.is(SessionCache.get(fakeStorage, { a: 'bb' }), null)
|
|
|
|
})
|