@@ -17,6 +17,13 @@ const emptyIndex = {
1717  uid : 'empty_test' , 
1818} 
1919
20+ type  Books  =  { 
21+   id : number 
22+   title : string 
23+   comment : string 
24+   genre : string 
25+ } 
26+ 
2027const  dataset  =  [ 
2128  { 
2229    id : 123 , 
@@ -85,6 +92,52 @@ describe.each([
8592    await  client . waitForTask ( task2 ) 
8693  } ) 
8794
95+   test ( `${ permission }   key: Multi index search no queries` ,  async  ( )  =>  { 
96+     const  client  =  await  getClient ( permission ) 
97+     const  response  =  await  client . multiSearch ( { 
98+       queries : [ ] , 
99+     } ) 
100+ 
101+     expect ( response . results . length ) . toEqual ( 0 ) 
102+   } ) 
103+ 
104+   test ( `${ permission }   key: Multi index search with one query` ,  async  ( )  =>  { 
105+     const  client  =  await  getClient ( permission ) 
106+     const  response  =  await  client . multiSearch ( { 
107+       queries : [ {  indexUid : index . uid ,  q : 'prince'  } ] , 
108+     } ) 
109+ 
110+     expect ( response . results [ 0 ] . hits . length ) . toEqual ( 2 ) 
111+   } ) 
112+ 
113+   test ( `${ permission }   key: Multi index search with multiple queries` ,  async  ( )  =>  { 
114+     const  client  =  await  getClient ( permission ) 
115+     const  response  =  await  client . multiSearch ( { 
116+       queries : [ 
117+         {  indexUid : index . uid ,  q : 'something'  } , 
118+         {  indexUid : emptyIndex . uid ,  q : 'something'  } , 
119+       ] , 
120+     } ) 
121+ 
122+     expect ( response . results . length ) . toEqual ( 2 ) 
123+   } ) 
124+ 
125+   test ( `${ permission }   key: Multi index search with one query` ,  async  ( )  =>  { 
126+     const  client  =  await  getClient ( permission ) 
127+ 
128+     type  MyIndex  =  { 
129+       id : 1 
130+     } 
131+ 
132+     const  response  =  await  client . multiSearch < MyIndex  &  Books > ( { 
133+       queries : [ {  indexUid : index . uid ,  q : 'prince'  } ] , 
134+     } ) 
135+ 
136+     expect ( response . results [ 0 ] . hits . length ) . toEqual ( 2 ) 
137+     expect ( response . results [ 0 ] . hits [ 0 ] . id ) . toEqual ( 456 ) 
138+     expect ( response . results [ 0 ] . hits [ 0 ] . title ) . toEqual ( 'Le Petit Prince' ) 
139+   } ) 
140+ 
88141  test ( `${ permission }   key: Basic search` ,  async  ( )  =>  { 
89142    const  client  =  await  getClient ( permission ) 
90143    const  response  =  await  client . index ( index . uid ) . search ( 'prince' ,  { } ) 
@@ -94,6 +147,7 @@ describe.each([
94147    expect ( response ) . toHaveProperty ( 'offset' ,  0 ) 
95148    expect ( response ) . toHaveProperty ( 'processingTimeMs' ,  expect . any ( Number ) ) 
96149    expect ( response ) . toHaveProperty ( 'query' ,  'prince' ) 
150+     expect ( response . facetStats ) . toBeUndefined ( ) 
97151    expect ( response . hits . length ) . toEqual ( 2 ) 
98152    // @ts -expect-error Not present in the SearchResponse type because neither `page` or `hitsPerPage` is provided in the search params. 
99153    expect ( response . hitsPerPage ) . toBeUndefined ( ) 
@@ -453,12 +507,16 @@ describe.each([
453507    const  client  =  await  getClient ( permission ) 
454508    const  response  =  await  client . index ( index . uid ) . search ( 'a' ,  { 
455509      filter : [ 'genre = romance' ] , 
456-       facets : [ 'genre' ] , 
510+       facets : [ 'genre' ,   'id' ] , 
457511    } ) 
458512
459513    expect ( response ) . toHaveProperty ( 'facetDistribution' ,  { 
460514      genre : {  romance : 2  } , 
515+       id : {  '123' : 1 ,  '2' : 1  } , 
461516    } ) 
517+ 
518+     expect ( response . facetStats ) . toEqual ( {  id : {  min : 2 ,  max : 123  }  } ) 
519+     expect ( response . facetStats ?. [ 'id' ] ?. max ) . toBe ( 123 ) 
462520    expect ( response ) . toHaveProperty ( 'hits' ,  expect . any ( Array ) ) 
463521    expect ( response . hits . length ) . toEqual ( 2 ) 
464522  } ) 
@@ -739,6 +797,14 @@ describe.each([{ permission: 'No' }])(
739797        ErrorStatusCode . MISSING_AUTHORIZATION_HEADER 
740798      ) 
741799    } ) 
800+ 
801+     test ( `${ permission }   key: Try multi search and be denied` ,  async  ( )  =>  { 
802+       const  client  =  await  getClient ( permission ) 
803+       await  expect ( client . multiSearch ( {  queries : [ ]  } ) ) . rejects . toHaveProperty ( 
804+         'code' , 
805+         ErrorStatusCode . MISSING_AUTHORIZATION_HEADER 
806+       ) 
807+     } ) 
742808  } 
743809) 
744810
0 commit comments