2
2
3
3
const cds = require ( "@sap/cds" ) ;
4
4
const xsenv = require ( "@sap/xsenv" ) ;
5
- const redisMock = require ( "./_env/mocks/redis" ) ;
6
- jest . mock ( "redis" , ( ) => require ( "./_env/mocks/redis" ) ) ;
7
- const redis = require ( "../src/redis" ) ;
5
+ const redisMock = require ( ".. /_env/mocks/redis" ) ;
6
+ jest . mock ( "redis" , ( ) => require ( ".. /_env/mocks/redis" ) ) ;
7
+ const redis = require ( "../../ src/redis" ) ;
8
8
9
- cds . test ( __dirname + "/_env" ) ;
9
+ cds . test ( __dirname + "/../ _env" ) ;
10
10
11
11
jest . spyOn ( xsenv , "serviceCredentials" ) . mockReturnValue ( { uri : "uri" } ) ;
12
12
13
+ const redisConfig = {
14
+ a : 1 ,
15
+ } ;
16
+ const adapterOptions = {
17
+ impl : "redis" ,
18
+ local : true ,
19
+ config : redisConfig ,
20
+ } ;
21
+
13
22
cds . env . websocket = {
14
23
kind : "ws" ,
15
- adapter : {
16
- impl : "redis" ,
17
- local : true ,
18
- } ,
24
+ adapter : adapterOptions ,
19
25
} ;
20
26
21
27
describe ( "Redis" , ( ) => {
@@ -24,14 +30,16 @@ describe("Redis", () => {
24
30
afterAll ( async ( ) => { } ) ;
25
31
26
32
test ( "Client" , async ( ) => {
27
- const main = await redis . createPrimaryClientAndConnect ( ) ;
33
+ const main = await redis . createPrimaryClientAndConnect ( adapterOptions ) ;
28
34
expect ( main ) . toBeDefined ( ) ;
29
- const second = await redis . createSecondaryClientAndConnect ( ) ;
35
+ expect ( main . options ) . toMatchObject ( redisConfig ) ;
36
+ const second = await redis . createSecondaryClientAndConnect ( adapterOptions ) ;
30
37
expect ( second ) . toBeDefined ( ) ;
38
+ expect ( second . options ) . toMatchObject ( redisConfig ) ;
31
39
} ) ;
32
40
33
41
test ( "Client fail" , async ( ) => {
34
- const main = await redis . createPrimaryClientAndConnect ( ) ;
42
+ const main = await redis . createPrimaryClientAndConnect ( adapterOptions ) ;
35
43
expect ( main ) . toBeDefined ( ) ;
36
44
main . error ( new Error ( "Failed" ) ) ;
37
45
expect ( main . on ) . toHaveBeenNthCalledWith ( 1 , "error" , expect . any ( Function ) ) ;
@@ -40,33 +48,33 @@ describe("Redis", () => {
40
48
test ( "Client createClient exception" , async ( ) => {
41
49
await redis . closeClients ( ) ;
42
50
redisMock . throwError ( "createClient" ) ;
43
- let main = await redis . createPrimaryClientAndConnect ( ) ;
51
+ let main = await redis . createPrimaryClientAndConnect ( adapterOptions ) ;
44
52
expect ( main ) . toBeUndefined ( ) ;
45
53
redisMock . throwError ( "createClient" ) ;
46
- let secondary = await redis . createSecondaryClientAndConnect ( ) ;
54
+ let secondary = await redis . createSecondaryClientAndConnect ( adapterOptions ) ;
47
55
expect ( secondary ) . toBeUndefined ( ) ;
48
56
} ) ;
49
57
50
58
test ( "Client connect exception" , async ( ) => {
51
59
await redis . closeClients ( ) ;
52
60
redisMock . throwError ( "connect" ) ;
53
- let main = await redis . createPrimaryClientAndConnect ( ) ;
61
+ let main = await redis . createPrimaryClientAndConnect ( adapterOptions ) ;
54
62
expect ( main ) . toBeUndefined ( ) ;
55
63
redisMock . throwError ( "connect" ) ;
56
- let secondary = await redis . createSecondaryClientAndConnect ( ) ;
64
+ let secondary = await redis . createSecondaryClientAndConnect ( adapterOptions ) ;
57
65
expect ( secondary ) . toBeUndefined ( ) ;
58
66
} ) ;
59
67
60
68
test ( "Client error" , async ( ) => {
61
69
await redis . closeClients ( ) ;
62
- const main = await redis . createPrimaryClientAndConnect ( ) ;
70
+ const main = await redis . createPrimaryClientAndConnect ( adapterOptions ) ;
63
71
expect ( main ) . toBeDefined ( ) ;
64
72
main . error ( new Error ( "error" ) ) ;
65
73
} ) ;
66
74
67
75
test ( "Client reconnect" , async ( ) => {
68
76
await redis . closeClients ( ) ;
69
- const main = await redis . createPrimaryClientAndConnect ( ) ;
77
+ const main = await redis . createPrimaryClientAndConnect ( adapterOptions ) ;
70
78
expect ( main ) . toBeDefined ( ) ;
71
79
main . reconnect ( ) ;
72
80
} ) ;
0 commit comments