Skip to content

Commit bece4e0

Browse files
committed
[remove duplicates] update local storage
1 parent 2b7b274 commit bece4e0

File tree

7 files changed

+69
-2
lines changed

7 files changed

+69
-2
lines changed

src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { constants } from './utils'
55
export * from './utils/enums'
66
export { createContract } from './contracts'
77
export { default as StakeWiseSDK } from './StakeWiseSDK'
8+
export { default as localStorage } from './modules/local-storage'
89
export { wrapAbortPromise, AbortPromise } from './modules/gql-module'
910

1011
export {

src/modules/gql-module/utils/getRequestUrl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { constants } from '../../../utils'
2-
import localStorage from './local-storage'
2+
import localStorage from '../../local-storage'
33

44

55
const sessionErrorUrl = constants.sessionStorageNames.moduleErrorUrl

src/modules/gql-module/utils/saveErrorUrlToSessionStorage.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { constants } from '../../../utils'
2-
import localStorage from './local-storage'
2+
import localStorage from '../../local-storage'
33

44

55
const sessionErrorUrl = constants.sessionStorageNames.moduleErrorUrl
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import MemoryStorage from './MemoryStorage'
2+
3+
4+
describe('MemoryStorage', () => {
5+
6+
it('should write and read values', () => {
7+
const storage = new MemoryStorage()
8+
9+
storage.setItem('key1', 'value1')
10+
storage.setItem('key2', 'value2')
11+
12+
expect(storage.getItem('key1')).toEqual('value1')
13+
expect(storage.getItem('key2')).toEqual('value2')
14+
})
15+
16+
it('should overwrite values', () => {
17+
const storage = new MemoryStorage()
18+
19+
storage.setItem('key', 'value1')
20+
21+
expect(storage.getItem('key')).toEqual('value1')
22+
23+
storage.setItem('key', 'value2')
24+
25+
expect(storage.getItem('key')).toEqual('value2')
26+
})
27+
28+
it('should remove and clear', () => {
29+
const storage = new MemoryStorage()
30+
31+
storage.setItem('key1', 'value1')
32+
storage.setItem('key2', 'value2')
33+
storage.removeItem('key2')
34+
35+
expect(storage.getItem('key1')).toEqual('value1')
36+
expect(storage.getItem('key2')).toBeNull()
37+
38+
storage.clear()
39+
40+
expect(storage.length).toEqual(0)
41+
})
42+
43+
it('should return null for undefined values', () => {
44+
const storage = new MemoryStorage()
45+
46+
expect(storage.getItem('key')).toBeNull()
47+
})
48+
49+
it('should return null for undefined keys', () => {
50+
const storage = new MemoryStorage()
51+
52+
expect(storage.key(1)).toBeNull()
53+
})
54+
55+
it('should return correct length', () => {
56+
const storage = new MemoryStorage()
57+
58+
storage.setItem('key1', 'value1')
59+
60+
expect(storage.length).toEqual(1)
61+
62+
storage.setItem('key2', 'value2')
63+
64+
expect(storage.length).toEqual(2)
65+
})
66+
})

0 commit comments

Comments
 (0)