1
- const redisClient = require ( "../../src/redis-client" ) ;
1
+ const { redisClient } = require ( "../../src/redis-client" ) ;
2
2
3
3
describe ( "Test redis client" , ( ) => {
4
4
const OLD_ENV = process . env ;
@@ -11,56 +11,56 @@ describe("Test redis client", () => {
11
11
afterAll ( ( ) => {
12
12
process . env = OLD_ENV ; // Restore old environment
13
13
} ) ;
14
- test ( "return empty object when REDIS_HOST is not set" , ( ) => {
15
- const client = require ( "../../src/redis-client" ) ;
16
- expect ( client ) . toEqual ( { } ) ;
14
+ test ( "Client reports not enabled when REDIS_HOST is not set" , ( ) => {
15
+ const { redisClient } = require ( "../../src/redis-client" ) ;
16
+ expect ( redisClient . clientEnabled ) . toEqual ( false ) ;
17
17
} )
18
18
19
19
test ( 'will receive process.env variables' , ( ) => {
20
20
// Set the variables
21
21
process . env . REDIS_HOST = 'localhost' ;
22
22
process . env . REDIS_PORT = 3367 ;
23
- const client = require ( "../../src/redis-client" ) ;
24
- expect ( client ) . not . toEqual ( { } ) ;
23
+ const { redisClient } = require ( "../../src/redis-client" ) ;
24
+ expect ( redisClient ) . not . toEqual ( { } ) ;
25
25
} ) ;
26
26
27
27
test ( "Test if record is correctly stored" , async ( ) => {
28
28
process . env . REDIS_HOST = 'localhost' ;
29
29
process . env . REDIS_PORT = 3367 ;
30
- const client = require ( "../../src/redis-client" ) ;
31
- await client . setAsync (
30
+ const { redisClient } = require ( "../../src/redis-client" ) ;
31
+ await redisClient . client . setTimeout (
32
32
'record1' ,
33
33
'hello' ,
34
34
) ;
35
- const res = await client . getAsync ( 'record1' ) ;
35
+ const res = await redisClient . client . getTimeout ( 'record1' ) ;
36
36
expect ( res ) . toEqual ( "hello" ) ;
37
37
} )
38
38
39
39
test ( "Test if record is correctly stored" , async ( ) => {
40
40
process . env . REDIS_HOST = 'localhost' ;
41
41
process . env . REDIS_PORT = 3367 ;
42
- const client = require ( "../../src/redis-client" ) ;
43
- await client . setAsync (
42
+ const { redisClient } = require ( "../../src/redis-client" ) ;
43
+ await redisClient . client . setTimeout (
44
44
'record1' ,
45
45
'hello' ,
46
46
) ;
47
- const res = await client . getAsync ( 'record1' ) ;
47
+ const res = await redisClient . client . getTimeout ( 'record1' ) ;
48
48
expect ( res ) . toEqual ( "hello" ) ;
49
49
} )
50
50
51
51
test ( "Test key should be removed after ttl" , async ( ) => {
52
52
process . env . REDIS_HOST = 'localhost' ;
53
53
process . env . REDIS_PORT = 3367 ;
54
- const client = require ( "../../src/redis-client" ) ;
55
- await client . setAsync (
54
+ const { redisClient } = require ( "../../src/redis-client" ) ;
55
+ await redisClient . client . setTimeout (
56
56
'record1' ,
57
57
'hello' ,
58
58
'EX' ,
59
59
2
60
60
) ;
61
61
await new Promise ( r => setTimeout ( r , 3000 ) ) ;
62
- const res = await client . getAsync ( 'record1' ) ;
62
+ const res = await redisClient . client . getTimeout ( 'record1' ) ;
63
63
expect ( res ) . not . toBeNull ;
64
64
} )
65
65
66
- } )
66
+ } )
0 commit comments