1- import  weaviate  from  '..' ; 
1+ import  weaviate ,   {   NodesStatusResponse   }  from  '..' ; 
22
3- const  { 
3+ import  { 
44  createTestFoodSchemaAndData , 
55  cleanupTestFood , 
66  PIZZA_CLASS_NAME , 
77  SOUP_CLASS_NAME , 
8- }  =   require ( '../utils/testData' ) ; 
8+ }  from   '../utils/testData' ; 
99
1010const  EXPECTED_WEAVIATE_VERSION  =  '1.20.0-prealpha' ; 
1111const  EXPECTED_WEAVIATE_GIT_HASH  =  '0529e8e' ; 
@@ -20,16 +20,22 @@ describe('cluster nodes endpoint', () => {
2020    return  client . cluster 
2121      . nodesStatusGetter ( ) 
2222      . do ( ) 
23-       . then ( ( nodesStatusResponse : any )  =>  { 
23+       . then ( ( nodesStatusResponse : NodesStatusResponse )  =>  { 
24+         expect ( nodesStatusResponse . nodes ) . toBeDefined ( ) ; 
2425        expect ( nodesStatusResponse . nodes ) . toHaveLength ( 1 ) ; 
25-         const  node  =  nodesStatusResponse . nodes [ 0 ] ; 
26-         expect ( node . name ) . toMatch ( / .+ / ) ; 
27-         expect ( node . version ) . toEqual ( EXPECTED_WEAVIATE_VERSION ) ; 
28-         expect ( node . gitHash ) . toEqual ( EXPECTED_WEAVIATE_GIT_HASH ) ; 
29-         expect ( node . status ) . toEqual ( 'HEALTHY' ) ; 
30-         expect ( node . stats . objectCount ) . toEqual ( 0 ) ; 
31-         expect ( node . stats . shardCount ) . toEqual ( 0 ) ; 
32-         expect ( node . shards ) . toBeNull ( ) ; 
26+         if  ( nodesStatusResponse . nodes )  { 
27+           const  node  =  nodesStatusResponse . nodes [ 0 ]  ??  [ ] ; 
28+           expect ( node . name ) . toMatch ( / .+ / ) ; 
29+           expect ( node . version ) . toEqual ( EXPECTED_WEAVIATE_VERSION ) ; 
30+           expect ( node . gitHash ) . toEqual ( EXPECTED_WEAVIATE_GIT_HASH ) ; 
31+           expect ( node . status ) . toEqual ( 'HEALTHY' ) ; 
32+           expect ( node . stats ) . toBeDefined ( ) ; 
33+           expect ( node . stats ?. objectCount ) . toEqual ( 0 ) ; 
34+           expect ( node . stats ?. shardCount ) . toEqual ( 0 ) ; 
35+           expect ( node . shards ) . toBeNull ( ) ; 
36+         }  else  { 
37+           throw  new  Error ( 'nodesStatusResponse.nodes should be defined' ) ; 
38+         } 
3339      } ) 
3440      . catch ( ( e : any )  =>  { 
3541        throw  new  Error ( 'should not fail on getting nodes: '  +  e ) ; 
@@ -42,31 +48,73 @@ describe('cluster nodes endpoint', () => {
4248    return  client . cluster 
4349      . nodesStatusGetter ( ) 
4450      . do ( ) 
45-       . then ( ( nodesStatusResponse : any )  =>  { 
51+       . then ( ( nodesStatusResponse : NodesStatusResponse )  =>  { 
4652        expect ( nodesStatusResponse . nodes ) . toHaveLength ( 1 ) ; 
47-         const  node  =  nodesStatusResponse . nodes [ 0 ] ; 
48-         expect ( node . name ) . toMatch ( / .+ / ) ; 
49-         expect ( node . version ) . toEqual ( EXPECTED_WEAVIATE_VERSION ) ; 
50-         expect ( node . gitHash ) . toEqual ( EXPECTED_WEAVIATE_GIT_HASH ) ; 
51-         expect ( node . status ) . toEqual ( 'HEALTHY' ) ; 
52-         expect ( node . stats . objectCount ) . toEqual ( 6 ) ; 
53-         expect ( node . stats . shardCount ) . toEqual ( 2 ) ; 
54-         expect ( node . shards ) . toHaveLength ( 2 ) ; 
55-         expect ( [ node . shards [ 0 ] . class ,  node . shards [ 1 ] . class ] ) . toEqual ( 
56-           expect . arrayContaining ( [ PIZZA_CLASS_NAME ,  SOUP_CLASS_NAME ] ) 
57-         ) ; 
58-         for  ( let  i  =  0 ;  i  <  node . shards . length ;  i ++ )  { 
59-           const  shard  =  node . shards [ i ] ; 
53+         if  ( nodesStatusResponse . nodes )  { 
54+           const  node  =  nodesStatusResponse . nodes [ 0 ] ; 
55+           expect ( node . name ) . toMatch ( / .+ / ) ; 
56+           expect ( node . version ) . toEqual ( EXPECTED_WEAVIATE_VERSION ) ; 
57+           expect ( node . gitHash ) . toEqual ( EXPECTED_WEAVIATE_GIT_HASH ) ; 
58+           expect ( node . status ) . toEqual ( 'HEALTHY' ) ; 
59+           expect ( node . stats ?. objectCount ) . toEqual ( 6 ) ; 
60+           expect ( node . stats ?. shardCount ) . toEqual ( 2 ) ; 
61+           expect ( node . shards ) . toBeDefined ( ) ; 
62+           expect ( node . shards ) . toHaveLength ( 2 ) ; 
63+           if  ( node . shards )  { 
64+             expect ( [ node . shards [ 0 ] . class ,  node . shards [ 1 ] . class ] ) . toEqual ( 
65+               expect . arrayContaining ( [ PIZZA_CLASS_NAME ,  SOUP_CLASS_NAME ] ) 
66+             ) ; 
67+             for  ( let  i  =  0 ;  i  <  node . shards . length ;  i ++ )  { 
68+               const  shard  =  node . shards [ i ] ; 
69+               expect ( shard . name ) . toMatch ( / .+ / ) ; 
70+               switch  ( shard . class )  { 
71+                 case  PIZZA_CLASS_NAME :
72+                   expect ( shard . objectCount ) . toEqual ( 4 ) ; 
73+                   break ; 
74+                 case  SOUP_CLASS_NAME :
75+                   expect ( shard . objectCount ) . toEqual ( 2 ) ; 
76+                   break ; 
77+               } 
78+             } 
79+           }  else  { 
80+             throw  new  Error ( 'node.shards should be defined' ) ; 
81+           } 
82+         }  else  { 
83+           throw  new  Error ( 'nodesStatusResponse.nodes should be defined' ) ; 
84+         } 
85+       } ) 
86+       . catch ( ( e : any )  =>  { 
87+         throw  new  Error ( 'should not fail on getting nodes: '  +  e ) ; 
88+       } ) ; 
89+   } ) ; 
6090
61-           expect ( shard . name ) . toMatch ( / .+ / ) ; 
62-           switch  ( shard . class )  { 
63-             case  PIZZA_CLASS_NAME :
64-               expect ( shard . objectCount ) . toEqual ( 4 ) ; 
65-               break ; 
66-             case  SOUP_CLASS_NAME :
67-               expect ( shard . objectCount ) . toEqual ( 2 ) ; 
68-               break ; 
91+   it ( 'get nodes status of only Pizza class in food db' ,  ( )  =>  { 
92+     return  client . cluster 
93+       . nodesStatusGetter ( ) 
94+       . withClassName ( PIZZA_CLASS_NAME ) 
95+       . do ( ) 
96+       . then ( ( nodesStatusResponse : NodesStatusResponse )  =>  { 
97+         expect ( nodesStatusResponse . nodes ) . toBeDefined ( ) ; 
98+         expect ( nodesStatusResponse . nodes ) . toHaveLength ( 1 ) ; 
99+         if  ( nodesStatusResponse . nodes )  { 
100+           const  node  =  nodesStatusResponse . nodes [ 0 ] ; 
101+           expect ( node . name ) . toMatch ( / .+ / ) ; 
102+           expect ( node . version ) . toEqual ( EXPECTED_WEAVIATE_VERSION ) ; 
103+           expect ( node . gitHash ) . toEqual ( EXPECTED_WEAVIATE_GIT_HASH ) ; 
104+           expect ( node . status ) . toEqual ( 'HEALTHY' ) ; 
105+           expect ( node . stats ?. objectCount ) . toEqual ( 4 ) ; 
106+           expect ( node . stats ?. shardCount ) . toEqual ( 1 ) ; 
107+           expect ( node . shards ) . toBeDefined ( ) ; 
108+           expect ( node . shards ) . toHaveLength ( 1 ) ; 
109+           if  ( node . shards )  { 
110+             expect ( node . shards [ 0 ] . class ) . toEqual ( PIZZA_CLASS_NAME ) ; 
111+             expect ( node . shards [ 0 ] . objectCount ) . toEqual ( 4 ) ; 
112+             expect ( node . shards [ 0 ] . name ) . toBeDefined ( ) ; 
113+           }  else  { 
114+             throw  new  Error ( 'node.shards should be defined' ) ; 
69115          } 
116+         }  else  { 
117+           throw  new  Error ( 'nodesStatusResponse.nodes should be defined' ) ; 
70118        } 
71119      } ) 
72120      . catch ( ( e : any )  =>  { 
0 commit comments