-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstorageMemory.js
74 lines (61 loc) · 1.82 KB
/
storageMemory.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
'use strict'
const test = require('ava')
const { StorageMemory } = require('..')
let storageMemory
test('should create instance success', t => {
t.notThrows(() => { return new StorageMemory() })
})
test.before(t => {
storageMemory = new StorageMemory()
t.pass()
})
test('should set value success and return it', async t => {
const key = 'key'
const value = 'value'
await storageMemory.set(key, value, 10)
t.is(await storageMemory.get(key), value)
})
test('should not set value if maxAge not passed', async t => {
const key = 'key1'
const value = 'value'
await storageMemory.set(key, value)
t.is(await storageMemory.get(key), null)
})
test('should not set value if maxAge = 0', async t => {
const key = 'key2'
const value = 'value'
await storageMemory.set(key, value, 0)
t.is(await storageMemory.get(key), null)
})
test('should not set value if maxAge < 0', async t => {
const key = 'key3'
const value = 'value'
await storageMemory.set(key, value, -10)
t.is(await storageMemory.get(key), null)
})
test('should not set value if maxAge is non-number', async t => {
const key = 'key4'
const value = 'value'
await storageMemory.set(key, value, 'dsfdsfsf')
t.is(await storageMemory.get(key), null)
})
test('should not set null value', async t => {
const key = 'key5'
const value = null
await storageMemory.set(key, value, 10)
t.is(await storageMemory.get(key), null)
})
test('should not set undefined value', async t => {
const key = 'key6'
const value = undefined
await storageMemory.set(key, value, 10)
t.is(await storageMemory.get(key), null)
})
test('should delete value', async t => {
const key = 'key7'
const value = 'value'
await storageMemory.set(key, value, 10)
t.is(await storageMemory.get(key), value)
await storageMemory.del(key)
t.is(await storageMemory.get(key), null)
})