@@ -8,6 +8,8 @@ const genRandom = (bytes=8) => crypto.pseudoRandomBytes(bytes).toString("hex");
8
8
const randKey1 = genRandom ( ) ;
9
9
const randValue1 = genRandom ( ) ;
10
10
const randKey2 = genRandom ( 16 ) ;
11
+ const randKey3 = genRandom ( ) ;
12
+ const randValue3 = genRandom ( ) ;
11
13
12
14
describe ( "redis test" , function ( ) {
13
15
before ( async function ( ) {
@@ -19,13 +21,41 @@ describe("redis test", function() {
19
21
. then ( res => {
20
22
assert . strictEqual ( res , randValue1 ) ;
21
23
done ( ) ;
22
- } ) . catch ( err => assert . fail ( err ) ) ;
24
+ } ) . catch ( err => done ( err ) ) ;
23
25
} ) ;
24
26
it ( "Should not be able to get not stored value" , ( done ) => {
25
27
redis . get ( randKey2 )
26
28
. then ( res => {
27
- if ( res ) assert . fail ( "Value should not be found" ) ;
29
+ if ( res ) done ( "Value should not be found" ) ;
28
30
done ( ) ;
29
- } ) . catch ( err => assert . fail ( err ) ) ;
31
+ } ) . catch ( err => done ( err ) ) ;
32
+ } ) ;
33
+ it ( "Should be able to delete stored value" , ( done ) => {
34
+ redis . del ( randKey1 )
35
+ . then ( ( ) => {
36
+ redis . get ( randKey1 )
37
+ . then ( res => {
38
+ assert . strictEqual ( res , null ) ;
39
+ done ( ) ;
40
+ } ) . catch ( err => done ( err ) ) ;
41
+ } ) . catch ( err => done ( err ) ) ;
42
+ } ) ;
43
+ it ( "Should be able to set expiring value" , ( done ) => {
44
+ redis . setEx ( randKey3 , 8400 , randValue3 )
45
+ . then ( ( ) => {
46
+ redis . get ( randKey3 )
47
+ . then ( res => {
48
+ assert . strictEqual ( res , randValue3 ) ;
49
+ done ( ) ;
50
+ } ) . catch ( err => done ( err ) ) ;
51
+ } ) . catch ( err => done ( err ) ) ;
52
+ } ) ;
53
+ it ( "Should continue when undefined value is fetched" , ( done ) => {
54
+ const undefkey = `undefined.${ genRandom ( ) } ` ;
55
+ redis . get ( undefkey )
56
+ . then ( result => {
57
+ assert . ok ( ! result ) ; // result should be falsy
58
+ done ( ) ;
59
+ } ) ;
30
60
} ) ;
31
61
} ) ;
0 commit comments