@@ -10,7 +10,14 @@ describe('RedisService', () => {
1010 module = await Test . createTestingModule ( {
1111 imports : [
1212 RedisModule . forRoot ( {
13- url : 'redis://localhost:6379'
13+ cluster : {
14+ rootNodes : [
15+ {
16+ url : 'redis://127.0.0.1:7380' ,
17+ password : 'mycluster'
18+ }
19+ ]
20+ }
1421 } )
1522 ]
1623 } ) . compile ( ) ;
@@ -36,9 +43,10 @@ describe('RedisService', () => {
3643 try {
3744 const result = await client . ping ( ) ;
3845 expect ( result ) . toBe ( 'PONG' ) ;
39- } catch ( error : unknown ) {
40- // If Redis is not available, skip the test
41- console . log ( 'Redis not available, skipping connection test' ) ;
46+ } catch ( error ) {
47+ console . log ( `Redis not available, skipping connection test: ${ String ( error ) } ` ) ;
48+ // Skip test if Redis is not available
49+ return ;
4250 }
4351 } ) ;
4452
@@ -62,8 +70,8 @@ describe('RedisService', () => {
6270 // Verify deletion
6371 const afterDelete = await client . get ( testKey ) ;
6472 expect ( afterDelete ) . toBeNull ( ) ;
65- } catch ( error : unknown ) {
66- console . log ( ' Redis operations failed, skipping test:' , ( error as Error ) . message ) ;
73+ } catch ( error ) {
74+ console . log ( ` Redis operations failed, skipping test: ${ String ( error ) } ` ) ;
6775 }
6876 } ) ;
6977
@@ -86,7 +94,7 @@ describe('RedisService', () => {
8694 // Cleanup
8795 await client . del ( counterKey ) ;
8896 } catch ( error : unknown ) {
89- console . log ( ' Redis counter operations failed, skipping test:' , ( error as Error ) . message ) ;
97+ console . log ( ` Redis counter operations failed, skipping test: ${ String ( error ) } ` ) ;
9098 }
9199 } ) ;
92100
@@ -103,13 +111,13 @@ describe('RedisService', () => {
103111 expect ( immediate ) . toBe ( 'expiry-test' ) ;
104112
105113 // Wait for expiry
106- await new Promise ( resolve => setTimeout ( resolve , 1100 ) ) ;
114+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1100 ) ) ;
107115
108116 // Should not exist after expiry
109117 const afterExpiry = await client . get ( expiryKey ) ;
110118 expect ( afterExpiry ) . toBeNull ( ) ;
111119 } catch ( error : unknown ) {
112- console . log ( ' Redis expiry operations failed, skipping test:' , ( error as Error ) . message ) ;
120+ console . log ( ` Redis expiry operations failed, skipping test: ${ String ( error ) } ` ) ;
113121 }
114122 } ) ;
115123
@@ -134,7 +142,7 @@ describe('RedisService', () => {
134142 // Cleanup
135143 await client . del ( listKey ) ;
136144 } catch ( error : unknown ) {
137- console . log ( ' Redis list operations failed, skipping test:' , ( error as Error ) . message ) ;
145+ console . log ( ` Redis list operations failed, skipping test: ${ String ( error ) } ` ) ;
138146 }
139147 } ) ;
140148
@@ -161,7 +169,7 @@ describe('RedisService', () => {
161169 // Cleanup
162170 await client . del ( hashKey ) ;
163171 } catch ( error : unknown ) {
164- console . log ( ' Redis hash operations failed, skipping test:' , ( error as Error ) . message ) ;
172+ console . log ( ` Redis hash operations failed, skipping test: ${ String ( error ) } ` ) ;
165173 }
166174 } ) ;
167175
@@ -176,9 +184,10 @@ describe('RedisService', () => {
176184
177185 // Cleanup
178186 await client . del ( 'test:error:key' ) ;
179- } catch ( error : unknown ) {
180- // If Redis is not available, test should not fail
181- console . log ( 'Redis connection test failed, but this is expected if Redis is not running' ) ;
187+ } catch ( error ) {
188+ console . log ( `Redis connection test failed, but this is expected if Redis is not running: ${ String ( error ) } ` ) ;
189+ // Skip test if Redis is not available
190+ return ;
182191 }
183192 } ) ;
184193
0 commit comments