@@ -195,81 +195,52 @@ describe.each([
195195
196196 describe ( 'Test on indexes methods' , ( ) => {
197197 test ( `${ permission } key: create with no primary key` , async ( ) => {
198- try {
199- const response = await client . createIndex ( indexNoPk . uid )
200- expect ( response ) . toHaveProperty ( 'uid' , indexNoPk . uid )
201- expect ( response ) . toHaveProperty ( 'primaryKey' , null )
202- } catch ( error ) {
203- throw new Error ( error )
204- }
205- try {
206- const response = await client . index ( indexNoPk . uid ) . getRawInfo ( )
207- expect ( response ) . toHaveProperty ( 'uid' , indexNoPk . uid )
208- expect ( response ) . toHaveProperty ( 'primaryKey' , null )
209- expect ( response ) . toHaveProperty ( 'createdAt' , expect . any ( String ) )
210- expect ( response ) . toHaveProperty ( 'updatedAt' , expect . any ( String ) )
211- } catch ( error ) {
212- throw new Error ( error )
213- }
214-
215- try {
216- const response = await client . getIndex ( indexNoPk . uid )
217- expect ( response . primaryKey ) . toBe ( null )
218- expect ( response . uid ) . toBe ( indexNoPk . uid )
219- } catch ( error ) {
220- throw new Error ( error )
221- }
198+ const newIndex = await client . createIndex ( indexNoPk . uid )
199+ expect ( newIndex ) . toHaveProperty ( 'uid' , indexNoPk . uid )
200+ expect ( newIndex ) . toHaveProperty ( 'primaryKey' , null )
201+
202+ const rawIndex = await client . index ( indexNoPk . uid ) . getRawInfo ( )
203+ expect ( rawIndex ) . toHaveProperty ( 'uid' , indexNoPk . uid )
204+ expect ( rawIndex ) . toHaveProperty ( 'primaryKey' , null )
205+ expect ( rawIndex ) . toHaveProperty ( 'createdAt' , expect . any ( String ) )
206+ expect ( rawIndex ) . toHaveProperty ( 'updatedAt' , expect . any ( String ) )
207+
208+ const response = await client . getIndex ( indexNoPk . uid )
209+ expect ( response . primaryKey ) . toBe ( null )
210+ expect ( response . uid ) . toBe ( indexNoPk . uid )
222211 } )
223212
224213 test ( `${ permission } key: create with primary key` , async ( ) => {
225- try {
226- const response = await client . createIndex ( indexPk . uid , {
227- primaryKey : indexPk . primaryKey ,
228- } )
229- expect ( response ) . toHaveProperty ( 'uid' , indexPk . uid )
230- expect ( response ) . toHaveProperty ( 'primaryKey' , indexPk . primaryKey )
231- } catch ( error ) {
232- throw new Error ( error )
233- }
234-
235- try {
236- const response = await client . index ( indexPk . uid ) . getRawInfo ( )
237- expect ( response ) . toHaveProperty ( 'primaryKey' , indexPk . primaryKey )
238- expect ( response ) . toHaveProperty ( 'createdAt' , expect . any ( String ) )
239- expect ( response ) . toHaveProperty ( 'updatedAt' , expect . any ( String ) )
240- } catch ( error ) {
241- throw new Error ( error )
242- }
243-
244- try {
245- const response = await client . getIndex ( indexPk . uid )
246- expect ( response . primaryKey ) . toBe ( indexPk . primaryKey )
247- expect ( response . uid ) . toBe ( indexPk . uid )
248- } catch ( error ) {
249- throw new Error ( error )
250- }
214+ const newIndex = await client . createIndex ( indexPk . uid , {
215+ primaryKey : indexPk . primaryKey ,
216+ } )
217+ expect ( newIndex ) . toHaveProperty ( 'uid' , indexPk . uid )
218+ expect ( newIndex ) . toHaveProperty ( 'primaryKey' , indexPk . primaryKey )
219+
220+ const rawIndex = await client . index ( indexPk . uid ) . getRawInfo ( )
221+ expect ( rawIndex ) . toHaveProperty ( 'primaryKey' , indexPk . primaryKey )
222+ expect ( rawIndex ) . toHaveProperty ( 'createdAt' , expect . any ( String ) )
223+ expect ( rawIndex ) . toHaveProperty ( 'updatedAt' , expect . any ( String ) )
224+
225+ const response = await client . getIndex ( indexPk . uid )
226+ expect ( response . primaryKey ) . toBe ( indexPk . primaryKey )
227+ expect ( response . uid ) . toBe ( indexPk . uid )
251228 } )
252229
253230 test ( `${ permission } key: get all indexes when not empty` , async ( ) => {
254231 await client . createIndex ( indexPk . uid )
255- try {
256- const response : IndexResponse [ ] = await client . getIndexes ( )
257- const indexes = response . map ( ( index ) => index . uid )
258- expect ( indexes ) . toEqual ( expect . arrayContaining ( [ indexPk . uid ] ) )
259- expect ( indexes . length ) . toEqual ( 1 )
260- } catch ( error ) {
261- throw new Error ( error )
262- }
232+
233+ const response : IndexResponse [ ] = await client . getIndexes ( )
234+ const indexes = response . map ( ( index ) => index . uid )
235+ expect ( indexes ) . toEqual ( expect . arrayContaining ( [ indexPk . uid ] ) )
236+ expect ( indexes . length ) . toEqual ( 1 )
263237 } )
264238
265239 test ( `${ permission } key: Get index that exists` , async ( ) => {
266240 await client . createIndex ( indexPk . uid )
267- try {
268- const response = await client . getIndex ( indexPk . uid )
269- expect ( response ) . toHaveProperty ( 'uid' , indexPk . uid )
270- } catch ( error ) {
271- throw new Error ( error )
272- }
241+
242+ const response = await client . getIndex ( indexPk . uid )
243+ expect ( response ) . toHaveProperty ( 'uid' , indexPk . uid )
273244 } )
274245
275246 test ( `${ permission } key: Get index that does not exist` , async ( ) => {
@@ -281,15 +252,12 @@ describe.each([
281252
282253 test ( `${ permission } key: update primary key` , async ( ) => {
283254 await client . createIndex ( indexPk . uid )
284- try {
285- const response : Index < any > = await client . updateIndex ( indexPk . uid , {
286- primaryKey : 'newPrimaryKey' ,
287- } )
288- expect ( response ) . toHaveProperty ( 'uid' , indexPk . uid )
289- expect ( response ) . toHaveProperty ( 'primaryKey' , 'newPrimaryKey' )
290- } catch ( error ) {
291- throw new Error ( error )
292- }
255+
256+ const response : Index < any > = await client . updateIndex ( indexPk . uid , {
257+ primaryKey : 'newPrimaryKey' ,
258+ } )
259+ expect ( response ) . toHaveProperty ( 'uid' , indexPk . uid )
260+ expect ( response ) . toHaveProperty ( 'primaryKey' , 'newPrimaryKey' )
293261 } )
294262
295263 test ( `${ permission } key: update primary key that already exists` , async ( ) => {
@@ -308,12 +276,10 @@ describe.each([
308276
309277 test ( `${ permission } key: delete index` , async ( ) => {
310278 await client . createIndex ( indexNoPk . uid )
311- try {
312- const response : void = await client . deleteIndex ( indexNoPk . uid )
313- expect ( response ) . toBe ( undefined )
314- } catch ( error ) {
315- throw new Error ( error )
316- }
279+
280+ const response : void = await client . deleteIndex ( indexNoPk . uid )
281+ expect ( response ) . toBe ( undefined )
282+
317283 await expect ( client . getIndexes ( ) ) . resolves . toHaveLength ( 0 )
318284 } )
319285
@@ -334,14 +300,10 @@ describe.each([
334300 } )
335301 test ( `${ permission } key: delete index if exists on existing index` , async ( ) => {
336302 await client . createIndex ( indexPk . uid )
337- try {
338- const response : boolean = await client . deleteIndexIfExists (
339- indexPk . uid
340- )
341- expect ( response ) . toBe ( true )
342- } catch ( error ) {
343- throw new Error ( error )
344- }
303+
304+ const response : boolean = await client . deleteIndexIfExists ( indexPk . uid )
305+ expect ( response ) . toBe ( true )
306+
345307 await expect ( client . getIndex ( indexPk . uid ) ) . rejects . toHaveProperty (
346308 'errorCode' ,
347309 ErrorStatusCode . INDEX_NOT_FOUND
@@ -350,12 +312,8 @@ describe.each([
350312
351313 test ( `${ permission } key: delete index if exists on index that does not exist` , async ( ) => {
352314 const indexes = await client . getIndexes ( )
353- try {
354- const response : boolean = await client . deleteIndexIfExists ( 'badIndex' )
355- expect ( response ) . toBe ( false )
356- } catch ( error ) {
357- throw new Error ( error )
358- }
315+ const response : boolean = await client . deleteIndexIfExists ( 'badIndex' )
316+ expect ( response ) . toBe ( false )
359317
360318 await expect ( client . getIndex ( 'badIndex' ) ) . rejects . toHaveProperty (
361319 'errorCode' ,
@@ -375,56 +333,36 @@ describe.each([
375333
376334 describe ( 'Test on base routes' , ( ) => {
377335 test ( `${ permission } key: get health` , async ( ) => {
378- try {
379- const response : Health = await client . health ( )
380- expect ( response ) . toHaveProperty (
381- 'status' ,
382- expect . stringMatching ( 'available' )
383- )
384- } catch ( error ) {
385- throw new Error ( error )
386- }
336+ const response : Health = await client . health ( )
337+ expect ( response ) . toHaveProperty (
338+ 'status' ,
339+ expect . stringMatching ( 'available' )
340+ )
387341 } )
388342
389343 test ( `${ permission } key: is server healthy` , async ( ) => {
390- try {
391- const response : boolean = await client . isHealthy ( )
392- expect ( response ) . toBe ( true )
393- } catch ( error ) {
394- throw new Error ( error )
395- }
344+ const response : boolean = await client . isHealthy ( )
345+ expect ( response ) . toBe ( true )
396346 } )
397347
398348 test ( `${ permission } key: is healthy return false on bad host` , async ( ) => {
399349 const client = new MeiliSearch ( { host : 'http://localhost:9345' } )
400- try {
401- const response : boolean = await client . isHealthy ( )
402- expect ( response ) . toBe ( false )
403- } catch ( error ) {
404- throw new Error ( error )
405- }
350+ const response : boolean = await client . isHealthy ( )
351+ expect ( response ) . toBe ( false )
406352 } )
407353
408354 test ( `${ permission } key: get version` , async ( ) => {
409- try {
410- const response : Version = await client . getVersion ( )
411- expect ( response ) . toHaveProperty ( 'commitSha' , expect . any ( String ) )
412- expect ( response ) . toHaveProperty ( 'commitDate' , expect . any ( String ) )
413- expect ( response ) . toHaveProperty ( 'pkgVersion' , expect . any ( String ) )
414- } catch ( error ) {
415- throw new Error ( error )
416- }
355+ const response : Version = await client . getVersion ( )
356+ expect ( response ) . toHaveProperty ( 'commitSha' , expect . any ( String ) )
357+ expect ( response ) . toHaveProperty ( 'commitDate' , expect . any ( String ) )
358+ expect ( response ) . toHaveProperty ( 'pkgVersion' , expect . any ( String ) )
417359 } )
418360
419361 test ( `${ permission } key: get /stats information` , async ( ) => {
420- try {
421- const response : Stats = await client . getStats ( )
422- expect ( response ) . toHaveProperty ( 'databaseSize' , expect . any ( Number ) )
423- expect ( response ) . toHaveProperty ( 'lastUpdate' ) // TODO: Could be null, find out why
424- expect ( response ) . toHaveProperty ( 'indexes' , expect . any ( Object ) )
425- } catch ( error ) {
426- throw new Error ( error )
427- }
362+ const response : Stats = await client . getStats ( )
363+ expect ( response ) . toHaveProperty ( 'databaseSize' , expect . any ( Number ) )
364+ expect ( response ) . toHaveProperty ( 'lastUpdate' ) // TODO: Could be null, find out why
365+ expect ( response ) . toHaveProperty ( 'indexes' , expect . any ( Object ) )
428366 } )
429367 } )
430368 }
@@ -478,15 +416,11 @@ describe.each([{ client: publicClient, permission: 'Public' }])(
478416
479417 describe ( 'Test on misc client methods' , ( ) => {
480418 test ( `${ permission } key: get health` , async ( ) => {
481- try {
482- const response : Health = await client . health ( )
483- expect ( response ) . toHaveProperty (
484- 'status' ,
485- expect . stringMatching ( 'available' )
486- )
487- } catch ( error ) {
488- throw new Error ( error )
489- }
419+ const response : Health = await client . health ( )
420+ expect ( response ) . toHaveProperty (
421+ 'status' ,
422+ expect . stringMatching ( 'available' )
423+ )
490424 } )
491425
492426 test ( `${ permission } key: try to get version and be denied` , async ( ) => {
@@ -574,15 +508,11 @@ describe.each([{ client: anonymousClient, permission: 'No' }])(
574508
575509 describe ( 'Test on misc client methods' , ( ) => {
576510 test ( `${ permission } key: get health` , async ( ) => {
577- try {
578- const response : Health = await client . health ( )
579- expect ( response ) . toHaveProperty (
580- 'status' ,
581- expect . stringMatching ( 'available' )
582- )
583- } catch ( error ) {
584- throw new Error ( error )
585- }
511+ const response : Health = await client . health ( )
512+ expect ( response ) . toHaveProperty (
513+ 'status' ,
514+ expect . stringMatching ( 'available' )
515+ )
586516 } )
587517
588518 test ( `${ permission } key: try to get version and be denied` , async ( ) => {
0 commit comments