@@ -49,16 +49,48 @@ describe.each([
4949 expect ( health ) . toBe ( true )
5050 } )
5151
52- test ( `${ permission } key: Create client with custom headers` , async ( ) => {
52+ test ( `${ permission } key: Create client with custom headers (object) ` , async ( ) => {
5353 const key = await getKey ( permission )
5454 const client = new MeiliSearch ( {
5555 ...config ,
5656 apiKey : key ,
57- headers : {
58- Expect : '200-OK' ,
57+ requestConfig : {
58+ headers : {
59+ Expect : '200-OK' ,
60+ } ,
61+ } ,
62+ } )
63+ expect ( client . httpRequest . headers [ 'Expect' ] ) . toBe ( '200-OK' )
64+ const health = await client . isHealthy ( )
65+ expect ( health ) . toBe ( true )
66+ } )
67+
68+ test ( `${ permission } key: Create client with custom headers (array)` , async ( ) => {
69+ const key = await getKey ( permission )
70+ const client = new MeiliSearch ( {
71+ ...config ,
72+ apiKey : key ,
73+ requestConfig : {
74+ headers : [ [ 'Expect' , '200-OK' ] ] ,
5975 } ,
6076 } )
61- expect ( client . config . headers ) . toStrictEqual ( { Expect : '200-OK' } )
77+ expect ( client . httpRequest . headers [ 'Expect' ] ) . toBe ( '200-OK' )
78+ const health = await client . isHealthy ( )
79+ expect ( health ) . toBe ( true )
80+ } )
81+
82+ test ( `${ permission } key: Create client with custom headers (Headers)` , async ( ) => {
83+ const key = await getKey ( permission )
84+ const headers = new Headers ( )
85+ headers . append ( 'Expect' , '200-OK' )
86+ const client = new MeiliSearch ( {
87+ ...config ,
88+ apiKey : key ,
89+ requestConfig : {
90+ headers,
91+ } ,
92+ } )
93+ expect ( client . httpRequest . headers . expect ) . toBe ( '200-OK' )
6294 const health = await client . isHealthy ( )
6395 expect ( health ) . toBe ( true )
6496 } )
@@ -169,11 +201,15 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
169201 const client = new MeiliSearch ( {
170202 ...config ,
171203 apiKey : key ,
172- headers : {
173- Expect : '200-OK' ,
204+ requestConfig : {
205+ headers : {
206+ Expect : '200-OK' ,
207+ } ,
174208 } ,
175209 } )
176- expect ( client . config . headers ) . toStrictEqual ( { Expect : '200-OK' } )
210+ expect ( client . config . requestConfig ?. headers ) . toStrictEqual ( {
211+ Expect : '200-OK' ,
212+ } )
177213 const health = await client . isHealthy ( )
178214
179215 expect ( health ) . toBe ( true )
@@ -186,12 +222,46 @@ describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
186222 expect ( results . length ) . toBe ( 1 )
187223 } )
188224
225+ test ( `${ permission } key: Create client with custom http client` , async ( ) => {
226+ const key = await getKey ( permission )
227+ const client = new MeiliSearch ( {
228+ ...config ,
229+ apiKey : key ,
230+ async httpClient ( url , init ) {
231+ const result = await fetch ( url , init )
232+ return result . json ( )
233+ } ,
234+ } )
235+ const health = await client . isHealthy ( )
236+
237+ expect ( health ) . toBe ( true )
238+
239+ const task = await client . createIndex ( 'test' )
240+ await client . waitForTask ( task . taskUid )
241+
242+ const { results } = await client . getIndexes ( )
243+
244+ expect ( results . length ) . toBe ( 1 )
245+
246+ const index = await client . getIndex ( 'test' )
247+
248+ const { taskUid } = await index . addDocuments ( [
249+ { id : 1 , title : 'index_2' } ,
250+ ] )
251+ await client . waitForTask ( taskUid )
252+
253+ const { results : documents } = await index . getDocuments ( )
254+ expect ( documents . length ) . toBe ( 1 )
255+ } )
256+
189257 test ( `${ permission } key: Create client with no custom client agents` , async ( ) => {
190258 const key = await getKey ( permission )
191259 const client = new MeiliSearch ( {
192260 ...config ,
193261 apiKey : key ,
194- headers : { } ,
262+ requestConfig : {
263+ headers : { } ,
264+ } ,
195265 } )
196266
197267 expect ( client . httpRequest . headers [ 'X-Meilisearch-Client' ] ) . toStrictEqual (
0 commit comments