FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode-cli/test/plugins/test_cache.js at master · bb-study-group/leetcode-cli · GitHub
bb-study-group
leetcode-cli
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode-cli
/
test
/
plugins
/
test_cache.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
240 lines (196 loc) · 6.75 KB
Breadcrumbs
leetcode-cli
/
test
/
plugins
/
test_cache.js
Copy path
File metadata and controls
240 lines (196 loc) · 6.75 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
'use strict'
;
const
_
=
require
(
'underscore'
)
;
const
assert
=
require
(
'chai'
)
.
assert
;
const
rewire
=
require
(
'rewire'
)
;
const
h
=
require
(
'../../lib/helper'
)
;
const
log
=
require
(
'../../lib/log'
)
;
const
config
=
require
(
'../../lib/config'
)
;
const
th
=
require
(
'../helper'
)
;
describe
(
'plugin:cache'
,
function
(
)
{
let
plugin
;
let
next
;
let
cache
;
let
file
;
let
session
;
const
PROBLEMS
=
[
{
id
:
0
,
fid
:
0
,
name
:
'name0'
,
slug
:
'slug0'
,
starred
:
false
,
category
:
'algorithms'
}
,
{
id
:
1
,
fid
:
1
,
name
:
'name1'
,
slug
:
'slug1'
,
starred
:
true
,
category
:
'algorithms'
}
]
;
const
PROBLEM
=
{
id
:
0
,
fid
:
0
,
slug
:
'slug0'
,
category
:
'algorithms'
}
;
before
(
function
(
)
{
log
.
init
(
)
;
config
.
init
(
)
;
}
)
;
beforeEach
(
function
(
)
{
th
.
clean
(
)
;
next
=
{
}
;
file
=
rewire
(
'../../lib/file'
)
;
file
.
cacheDir
=
(
)
=>
th
.
DIR
;
cache
=
rewire
(
'../../lib/cache'
)
;
cache
.
__set__
(
'file'
,
file
)
;
cache
.
init
(
)
;
session
=
rewire
(
'../../lib/session'
)
;
session
.
__set__
(
'cache'
,
cache
)
;
plugin
=
rewire
(
'../../lib/plugins/cache'
)
;
plugin
.
__set__
(
'cache'
,
cache
)
;
plugin
.
__set__
(
'session'
,
session
)
;
plugin
.
init
(
)
;
plugin
.
setNext
(
next
)
;
}
)
;
describe
(
'#getProblems'
,
function
(
)
{
it
(
'should getProblems w/ cache ok'
,
function
(
done
)
{
cache
.
set
(
'problems'
,
PROBLEMS
)
;
plugin
.
getProblems
(
function
(
e
,
problems
)
{
assert
.
equal
(
e
,
null
)
;
assert
.
deepEqual
(
problems
,
PROBLEMS
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'should getProblems w/o cache ok'
,
function
(
done
)
{
cache
.
del
(
'problems'
)
;
next
.
getProblems
=
cb
=>
cb
(
null
,
PROBLEMS
)
;
plugin
.
getProblems
(
function
(
e
,
problems
)
{
assert
.
equal
(
e
,
null
)
;
assert
.
deepEqual
(
problems
,
PROBLEMS
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'should getProblems w/o cache fail if client error'
,
function
(
done
)
{
cache
.
del
(
'problems'
)
;
next
.
getProblems
=
cb
=>
cb
(
'client getProblems error'
)
;
plugin
.
getProblems
(
function
(
e
,
problems
)
{
assert
.
equal
(
e
,
'client getProblems error'
)
;
done
(
)
;
}
)
;
}
)
;
}
)
;
// #getProblems
describe
(
'#getProblem'
,
function
(
)
{
it
(
'should getProblem w/ cache ok'
,
function
(
done
)
{
cache
.
set
(
'problems'
,
PROBLEMS
)
;
cache
.
set
(
'0.slug0.algorithms'
,
PROBLEMS
[
0
]
)
;
plugin
.
getProblem
(
_
.
clone
(
PROBLEM
)
,
function
(
e
,
problem
)
{
assert
.
equal
(
e
,
null
)
;
assert
.
deepEqual
(
problem
,
PROBLEMS
[
0
]
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'should getProblem w/o cache ok'
,
function
(
done
)
{
cache
.
set
(
'problems'
,
PROBLEMS
)
;
cache
.
del
(
'0.slug0.algorithms'
)
;
next
.
getProblem
=
(
problem
,
cb
)
=>
cb
(
null
,
PROBLEMS
[
0
]
)
;
plugin
.
getProblem
(
_
.
clone
(
PROBLEM
)
,
function
(
e
,
problem
)
{
assert
.
equal
(
e
,
null
)
;
assert
.
deepEqual
(
problem
,
PROBLEMS
[
0
]
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'should getProblem fail if client error'
,
function
(
done
)
{
cache
.
set
(
'problems'
,
PROBLEMS
)
;
cache
.
del
(
'0.slug0.algorithms'
)
;
next
.
getProblem
=
(
problem
,
cb
)
=>
cb
(
'client getProblem error'
)
;
plugin
.
getProblem
(
_
.
clone
(
PROBLEM
)
,
function
(
e
,
problem
)
{
assert
.
equal
(
e
,
'client getProblem error'
)
;
done
(
)
;
}
)
;
}
)
;
}
)
;
// #getProblem
describe
(
'#saveProblem'
,
function
(
)
{
it
(
'should ok'
,
function
(
)
{
cache
.
del
(
'0.slug0.algorithms'
)
;
const
problem
=
_
.
clone
(
PROBLEMS
[
0
]
)
;
problem
.
locked
=
true
;
problem
.
state
=
'ac'
;
const
ret
=
plugin
.
saveProblem
(
problem
)
;
assert
.
equal
(
ret
,
true
)
;
assert
.
deepEqual
(
cache
.
get
(
'0.slug0.algorithms'
)
,
{
id
:
0
,
fid
:
0
,
slug
:
'slug0'
,
name
:
'name0'
,
category
:
'algorithms'
}
)
;
}
)
;
}
)
;
// #saveProblem
describe
(
'#updateProblem'
,
function
(
)
{
it
(
'should updateProblem ok'
,
function
(
done
)
{
cache
.
set
(
'problems'
,
PROBLEMS
)
;
const
kv
=
{
value
:
'value00'
}
;
const
ret
=
plugin
.
updateProblem
(
PROBLEMS
[
0
]
,
kv
)
;
assert
.
equal
(
ret
,
true
)
;
plugin
.
getProblems
(
function
(
e
,
problems
)
{
assert
.
equal
(
e
,
null
)
;
assert
.
deepEqual
(
problems
,
[
{
id
:
0
,
fid
:
0
,
name
:
'name0'
,
slug
:
'slug0'
,
value
:
'value00'
,
starred
:
false
,
category
:
'algorithms'
}
,
{
id
:
1
,
fid
:
1
,
name
:
'name1'
,
slug
:
'slug1'
,
starred
:
true
,
category
:
'algorithms'
}
]
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'should updateProblem fail if no problems found'
,
function
(
)
{
cache
.
del
(
'problems'
)
;
const
ret
=
plugin
.
updateProblem
(
PROBLEMS
[
0
]
,
{
}
)
;
assert
.
equal
(
ret
,
false
)
;
}
)
;
it
(
'should updateProblem fail if unknown problem'
,
function
(
)
{
cache
.
set
(
'problems'
,
[
PROBLEMS
[
1
]
]
)
;
const
ret
=
plugin
.
updateProblem
(
PROBLEMS
[
0
]
,
{
}
)
;
assert
.
equal
(
ret
,
false
)
;
}
)
;
}
)
;
// #updateProblem
describe
(
'#user'
,
function
(
)
{
const
USER
=
{
name
:
'test-user'
,
pass
:
'password'
}
;
const
USER_SAFE
=
{
name
:
'test-user'
}
;
it
(
'should login ok'
,
function
(
done
)
{
config
.
autologin
.
enable
=
true
;
// before login
cache
.
del
(
h
.
KEYS
.
user
)
;
assert
.
equal
(
session
.
getUser
(
)
,
null
)
;
assert
.
equal
(
session
.
isLogin
(
)
,
false
)
;
next
.
login
=
(
user
,
cb
)
=>
cb
(
null
,
user
)
;
plugin
.
login
(
USER
,
function
(
e
,
user
)
{
assert
.
equal
(
e
,
null
)
;
assert
.
deepEqual
(
user
,
USER
)
;
// after login
assert
.
deepEqual
(
session
.
getUser
(
)
,
USER
)
;
assert
.
equal
(
session
.
isLogin
(
)
,
true
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'should login ok w/ auto login'
,
function
(
done
)
{
config
.
autologin
.
enable
=
false
;
cache
.
del
(
h
.
KEYS
.
user
)
;
next
.
login
=
(
user
,
cb
)
=>
cb
(
null
,
user
)
;
plugin
.
login
(
USER
,
function
(
e
,
user
)
{
assert
.
equal
(
e
,
null
)
;
assert
.
deepEqual
(
user
,
USER
)
;
assert
.
deepEqual
(
session
.
getUser
(
)
,
USER_SAFE
)
;
assert
.
equal
(
session
.
isLogin
(
)
,
true
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'should login fail if client login error'
,
function
(
done
)
{
next
.
login
=
(
user
,
cb
)
=>
cb
(
'client login error'
)
;
plugin
.
login
(
USER
,
function
(
e
,
user
)
{
assert
.
equal
(
e
,
'client login error'
)
;
done
(
)
;
}
)
;
}
)
;
it
(
'should logout ok'
,
function
(
done
)
{
// before logout
cache
.
set
(
h
.
KEYS
.
user
,
USER
)
;
assert
.
deepEqual
(
session
.
getUser
(
)
,
USER
)
;
assert
.
equal
(
session
.
isLogin
(
)
,
true
)
;
// after logout
plugin
.
logout
(
USER
,
true
)
;
assert
.
equal
(
session
.
getUser
(
)
,
null
)
;
assert
.
equal
(
session
.
isLogin
(
)
,
false
)
;
done
(
)
;
}
)
;
it
(
'should logout ok'
,
function
(
done
)
{
// before logout
cache
.
set
(
h
.
KEYS
.
user
,
USER
)
;
assert
.
deepEqual
(
session
.
getUser
(
)
,
USER
)
;
assert
.
equal
(
session
.
isLogin
(
)
,
true
)
;
// after logout
plugin
.
logout
(
null
,
true
)
;
assert
.
equal
(
session
.
getUser
(
)
,
null
)
;
assert
.
equal
(
session
.
isLogin
(
)
,
false
)
;
done
(
)
;
}
)
;
}
)
;
// #user
}
)
;
Back
|
FazBrowse Home
|
New Git URL