-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencryptedLocalStorage.test.js
More file actions
32 lines (27 loc) · 982 Bytes
/
encryptedLocalStorage.test.js
File metadata and controls
32 lines (27 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { assert, expect, it, describe } from 'vitest'
import { Either } from 'ramda-fantasy'
import { decryptFromLocalStorage } from './encryptedLocalStorage'
describe('Encrypted Local Storage', () => {
it.each([
['with correct password', '1', Either.isRight],
['with wrong password', 'haha', Either.isLeft],
['without password', '', Either.isLeft],
])('Decrypt data %s', async (_, password, expectedPredicate) => {
localStorage.setItem(
'data',
'Q30a49y9eKyC2m/HrHlP8Woup+qPzfxC9CTNLOVvMcMnEbQvZZJeOXWXT8nNhA=='
)
await decryptFromLocalStorage('data', password)
.then(expectedPredicate)
.then(assert.isTrue)
})
it.each([
['empty', null, Either.isRight],
['unencrypted', '{}', Either.isRight],
])('Decrypt %s data', async (_, value, expectedPredicate) => {
localStorage.setItem('data', value)
await decryptFromLocalStorage('data')
.then(expectedPredicate)
.then(assert.isTrue)
})
})