-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathclient.test.ts
842 lines (728 loc) · 27.6 KB
/
client.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
import { ErrorStatusCode, Health, Version, Stats, TaskTypes } from '../src'
import { PACKAGE_VERSION } from '../src/package-version'
import {
clearAllIndexes,
getKey,
getClient,
config,
MeiliSearch,
BAD_HOST,
HOST,
} from './utils/meilisearch-test-utils'
const indexNoPk = {
uid: 'movies_test',
}
const indexPk = {
uid: 'movies_test2',
primaryKey: 'id',
}
const index = {
uid: 'movies_test',
}
const index2 = {
uid: 'movies_test2',
}
afterAll(() => {
return clearAllIndexes(config)
})
describe.each([
{ permission: 'Master' },
{ permission: 'Admin' },
{ permission: 'Search' },
])('Test on client instance', ({ permission }) => {
beforeEach(() => {
return clearAllIndexes(config)
})
test(`${permission} key: Create client with api key`, async () => {
const key = await getKey(permission)
const client = new MeiliSearch({
...config,
apiKey: key,
})
const health = await client.isHealthy()
expect(health).toBe(true)
})
test(`${permission} key: Create client with custom headers (object)`, async () => {
const key = await getKey(permission)
const client = new MeiliSearch({
...config,
apiKey: key,
requestConfig: {
headers: {
Expect: '200-OK',
},
},
})
expect(client.httpRequest.headers['Expect']).toBe('200-OK')
const health = await client.isHealthy()
expect(health).toBe(true)
})
test(`${permission} key: Create client with custom headers (array)`, async () => {
const key = await getKey(permission)
const client = new MeiliSearch({
...config,
apiKey: key,
requestConfig: {
headers: [['Expect', '200-OK']],
},
})
expect(client.httpRequest.headers['Expect']).toBe('200-OK')
const health = await client.isHealthy()
expect(health).toBe(true)
})
test(`${permission} key: Create client with custom headers (Headers)`, async () => {
const key = await getKey(permission)
const headers = new Headers()
headers.append('Expect', '200-OK')
const client = new MeiliSearch({
...config,
apiKey: key,
requestConfig: {
headers,
},
})
expect(client.httpRequest.headers.expect).toBe('200-OK')
const health = await client.isHealthy()
expect(health).toBe(true)
})
test(`${permission} key: No double slash when on host with domain and path and trailing slash`, async () => {
const key = await getKey(permission)
try {
const customHost = `${BAD_HOST}/api/`
const client = new MeiliSearch({
host: customHost,
apiKey: key,
})
const health = await client.isHealthy()
expect(health).toBe(false) // Left here to trigger failed test if error is not thrown
} catch (e: any) {
expect(e.message).toMatch(`${BAD_HOST}/api/health`)
expect(e.name).toBe('MeiliSearchCommunicationError')
}
})
test(`${permission} key: No double slash when on host with domain and path and no trailing slash`, async () => {
const key = await getKey(permission)
try {
const customHost = `${BAD_HOST}/api`
const client = new MeiliSearch({
host: customHost,
apiKey: key,
})
const health = await client.isHealthy()
expect(health).toBe(false) // Left here to trigger failed test if error is not thrown
} catch (e: any) {
expect(e.message).toMatch(`${BAD_HOST}/api/health`)
expect(e.name).toBe('MeiliSearchCommunicationError')
}
})
test(`${permission} key: host with double slash should keep double slash`, async () => {
const key = await getKey(permission)
try {
const customHost = `${BAD_HOST}//`
const client = new MeiliSearch({
host: customHost,
apiKey: key,
})
const health = await client.isHealthy()
expect(health).toBe(false) // Left here to trigger failed test if error is not thrown
} catch (e: any) {
expect(e.message).toMatch(`${BAD_HOST}//health`)
expect(e.name).toBe('MeiliSearchCommunicationError')
}
})
test(`${permission} key: host with one slash should not double slash`, async () => {
const key = await getKey(permission)
try {
const customHost = `${BAD_HOST}/`
const client = new MeiliSearch({
host: customHost,
apiKey: key,
})
const health = await client.isHealthy()
expect(health).toBe(false) // Left here to trigger failed test if error is not thrown
} catch (e: any) {
expect(e.message).toMatch(`${BAD_HOST}/health`)
expect(e.name).toBe('MeiliSearchCommunicationError')
}
})
test(`${permission} key: bad host raise CommunicationError`, async () => {
const client = new MeiliSearch({ host: 'http://localhost:9345' })
try {
await client.health()
} catch (e: any) {
expect(e.name).toEqual('MeiliSearchCommunicationError')
}
})
test(`${permission} key: host without HTTP should not throw Invalid URL Error`, () => {
const strippedHost = HOST.replace('http://', '')
expect(() => {
new MeiliSearch({ host: strippedHost })
}).not.toThrow('The provided host is not valid.')
})
test(`${permission} key: host without HTTP and port should not throw Invalid URL Error`, () => {
const strippedHost = HOST.replace('http://', '').replace(':7700', '')
expect(() => {
new MeiliSearch({ host: strippedHost })
}).not.toThrow('The provided host is not valid.')
})
test(`${permission} key: Empty string host should throw an error`, () => {
expect(() => {
new MeiliSearch({ host: '' })
}).toThrow('The provided host is not valid.')
})
})
describe.each([{ permission: 'Master' }, { permission: 'Admin' }])(
'Test on client w/ master and admin key',
({ permission }) => {
beforeEach(() => {
return clearAllIndexes(config)
})
test(`${permission} key: Create client with custom headers`, async () => {
const key = await getKey(permission)
const client = new MeiliSearch({
...config,
apiKey: key,
requestConfig: {
headers: {
Expect: '200-OK',
},
},
})
expect(client.config.requestConfig?.headers).toStrictEqual({
Expect: '200-OK',
})
const health = await client.isHealthy()
expect(health).toBe(true)
const task = await client.createIndex('test')
await client.waitForTask(task.taskUid)
const { results } = await client.getIndexes()
expect(results.length).toBe(1)
})
test(`${permission} key: Create client with custom http client`, async () => {
const key = await getKey(permission)
const client = new MeiliSearch({
...config,
apiKey: key,
async httpClient(url, init) {
const result = await fetch(url, init)
return result.json()
},
})
const health = await client.isHealthy()
expect(health).toBe(true)
const task = await client.createIndex('test')
await client.waitForTask(task.taskUid)
const { results } = await client.getIndexes()
expect(results.length).toBe(1)
const index = await client.getIndex('test')
const { taskUid } = await index.addDocuments([
{ id: 1, title: 'index_2' },
])
await client.waitForTask(taskUid)
const { results: documents } = await index.getDocuments()
expect(documents.length).toBe(1)
})
test(`${permission} key: Create client with no custom client agents`, async () => {
const key = await getKey(permission)
const client = new MeiliSearch({
...config,
apiKey: key,
requestConfig: {
headers: {},
},
})
expect(client.httpRequest.headers['X-Meilisearch-Client']).toStrictEqual(
`Meilisearch JavaScript (v${PACKAGE_VERSION})`
)
})
test(`${permission} key: Create client with empty custom client agents`, async () => {
const key = await getKey(permission)
const client = new MeiliSearch({
...config,
apiKey: key,
clientAgents: [],
})
expect(client.httpRequest.headers['X-Meilisearch-Client']).toStrictEqual(
`Meilisearch JavaScript (v${PACKAGE_VERSION})`
)
})
test(`${permission} key: Create client with custom client agents`, async () => {
const key = await getKey(permission)
const client = new MeiliSearch({
...config,
apiKey: key,
clientAgents: ['random plugin 1', 'random plugin 2'],
})
expect(client.httpRequest.headers['X-Meilisearch-Client']).toStrictEqual(
`random plugin 1 ; random plugin 2 ; Meilisearch JavaScript (v${PACKAGE_VERSION})`
)
})
describe('Test on indexes methods', () => {
test(`${permission} key: create with no primary key`, async () => {
const client = await getClient(permission)
const task = await client.createIndex(indexNoPk.uid)
await client.waitForTask(task.taskUid)
const newIndex = await client.getIndex(indexNoPk.uid)
expect(newIndex).toHaveProperty('uid', indexNoPk.uid)
expect(newIndex).toHaveProperty('primaryKey', null)
const rawIndex = await client.index(indexNoPk.uid).getRawInfo()
expect(rawIndex).toHaveProperty('uid', indexNoPk.uid)
expect(rawIndex).toHaveProperty('primaryKey', null)
expect(rawIndex).toHaveProperty('createdAt', expect.any(String))
expect(rawIndex).toHaveProperty('updatedAt', expect.any(String))
const response = await client.getIndex(indexNoPk.uid)
expect(response.primaryKey).toBe(null)
expect(response.uid).toBe(indexNoPk.uid)
})
test(`${permission} key: create with primary key`, async () => {
const client = await getClient(permission)
const { taskUid } = await client.createIndex(indexPk.uid, {
primaryKey: indexPk.primaryKey,
})
await client.waitForTask(taskUid)
const newIndex = await client.getIndex(indexPk.uid)
expect(newIndex).toHaveProperty('uid', indexPk.uid)
expect(newIndex).toHaveProperty('primaryKey', indexPk.primaryKey)
const rawIndex = await client.index(indexPk.uid).getRawInfo()
expect(rawIndex).toHaveProperty('primaryKey', indexPk.primaryKey)
expect(rawIndex).toHaveProperty('createdAt', expect.any(String))
expect(rawIndex).toHaveProperty('updatedAt', expect.any(String))
const response = await client.getIndex(indexPk.uid)
expect(response.primaryKey).toBe(indexPk.primaryKey)
expect(response.uid).toBe(indexPk.uid)
})
test(`${permission} key: get all indexes when not empty`, async () => {
const client = await getClient(permission)
const { taskUid } = await client.createIndex(indexPk.uid)
await client.waitForTask(taskUid)
const { results } = await client.getRawIndexes()
const indexes = results.map((index) => index.uid)
expect(indexes).toEqual(expect.arrayContaining([indexPk.uid]))
expect(indexes.length).toEqual(1)
})
test(`${permission} key: Get index that exists`, async () => {
const client = await getClient(permission)
const { taskUid } = await client.createIndex(indexPk.uid)
await client.waitForTask(taskUid)
const response = await client.getIndex(indexPk.uid)
expect(response).toHaveProperty('uid', indexPk.uid)
})
test(`${permission} key: Get index that does not exist`, async () => {
const client = await getClient(permission)
await expect(client.getIndex('does_not_exist')).rejects.toHaveProperty(
'code',
ErrorStatusCode.INDEX_NOT_FOUND
)
})
test(`${permission} key: update primary key`, async () => {
const client = await getClient(permission)
const { taskUid: createTask } = await client.createIndex(indexPk.uid)
await client.waitForTask(createTask)
const { taskUid: updateTask } = await client.updateIndex(indexPk.uid, {
primaryKey: 'newPrimaryKey',
})
await client.waitForTask(updateTask)
const index = await client.getIndex(indexPk.uid)
expect(index).toHaveProperty('uid', indexPk.uid)
expect(index).toHaveProperty('primaryKey', 'newPrimaryKey')
})
test(`${permission} key: update primary key that already exists`, async () => {
const client = await getClient(permission)
const { taskUid: createTask } = await client.createIndex(indexPk.uid, {
primaryKey: indexPk.primaryKey,
})
await client.waitForTask(createTask)
const { taskUid: updateTask } = await client.updateIndex(indexPk.uid, {
primaryKey: 'newPrimaryKey',
})
await client.waitForTask(updateTask)
const index = await client.getIndex(indexPk.uid)
expect(index).toHaveProperty('uid', indexPk.uid)
expect(index).toHaveProperty('primaryKey', 'newPrimaryKey')
})
test(`${permission} key: delete index`, async () => {
const client = await getClient(permission)
const { taskUid: createTask } = await client.createIndex(indexNoPk.uid)
await client.waitForTask(createTask)
const { taskUid: deleteTask } = await client.deleteIndex(indexNoPk.uid)
await client.waitForTask(deleteTask)
const { results } = await client.getIndexes()
expect(results).toHaveLength(0)
})
test(`${permission} key: create index with already existing uid should fail`, async () => {
const client = await getClient(permission)
const { taskUid: firstCreate } = await client.createIndex(indexPk.uid)
await client.waitForTask(firstCreate)
const { taskUid: secondCreate } = await client.createIndex(indexPk.uid)
const task = await client.waitForTask(secondCreate)
expect(task.status).toBe('failed')
})
test(`${permission} key: delete index with uid that does not exist should fail`, async () => {
const client = await getClient(permission)
const index = client.index(indexNoPk.uid)
const { taskUid } = await index.delete()
const task = await client.waitForTask(taskUid)
expect(task.status).toEqual('failed')
})
test(`${permission} key: fetch deleted index should fail`, async () => {
const client = await getClient(permission)
const index = client.index(indexPk.uid)
await expect(index.getRawInfo()).rejects.toHaveProperty(
'code',
ErrorStatusCode.INDEX_NOT_FOUND
)
})
test(`${permission} key: Swap two indexes`, async () => {
const client = await getClient(permission)
await client
.index(index.uid)
.addDocuments([{ id: 1, title: `index_1` }])
const { taskUid } = await client
.index(index2.uid)
.addDocuments([{ id: 1, title: 'index_2' }])
await client.waitForTask(taskUid)
const swaps = [
{
indexes: [index.uid, index2.uid],
},
]
const swapTask = await client.swapIndexes(swaps)
const resolvedTask = await client.waitForTask(swapTask.taskUid)
const docIndex1 = await client.index(index.uid).getDocument(1)
const docIndex2 = await client.index(index2.uid).getDocument(1)
expect(docIndex1.title).toEqual('index_2')
expect(docIndex2.title).toEqual('index_1')
expect(resolvedTask.type).toEqual(TaskTypes.INDEXES_SWAP)
expect(resolvedTask.details.swaps).toEqual(swaps)
})
test(`${permission} key: Swap two indexes with one that does not exist`, async () => {
const client = await getClient(permission)
const { taskUid } = await client
.index(index2.uid)
.addDocuments([{ id: 1, title: 'index_2' }])
await client.waitForTask(taskUid)
const swaps = [
{
indexes: ['does_not_exist', index2.uid],
},
]
const swapTask = await client.swapIndexes(swaps)
const resolvedTask = await client.waitForTask(swapTask.taskUid)
expect(resolvedTask.type).toEqual(TaskTypes.INDEXES_SWAP)
expect(resolvedTask.error?.code).toEqual(
ErrorStatusCode.INDEX_NOT_FOUND
)
expect(resolvedTask.details.swaps).toEqual(swaps)
})
// Should be fixed by rc1
test(`${permission} key: Swap two one index with itself`, async () => {
const client = await getClient(permission)
const swaps = [
{
indexes: [index.uid, index.uid],
},
]
await expect(client.swapIndexes(swaps)).rejects.toHaveProperty(
'code',
ErrorStatusCode.INVALID_SWAP_DUPLICATE_INDEX_FOUND
)
})
})
describe('Test on base routes', () => {
test(`${permission} key: get health`, async () => {
const client = await getClient(permission)
const response: Health = await client.health()
expect(response).toHaveProperty(
'status',
expect.stringMatching('available')
)
})
test(`${permission} key: is server healthy`, async () => {
const client = await getClient(permission)
const response: boolean = await client.isHealthy()
expect(response).toBe(true)
})
test(`${permission} key: is healthy return false on bad host`, async () => {
const client = new MeiliSearch({ host: 'http://localhost:9345' })
const response: boolean = await client.isHealthy()
expect(response).toBe(false)
})
test(`${permission} key: get version`, async () => {
const client = await getClient(permission)
const response: Version = await client.getVersion()
expect(response).toHaveProperty('commitSha', expect.any(String))
expect(response).toHaveProperty('commitDate', expect.any(String))
expect(response).toHaveProperty('pkgVersion', expect.any(String))
})
test(`${permission} key: get /stats information`, async () => {
const client = await getClient(permission)
const response: Stats = await client.getStats()
expect(response).toHaveProperty('databaseSize', expect.any(Number))
expect(response).toHaveProperty('lastUpdate') // TODO: Could be null, find out why
expect(response).toHaveProperty('indexes', expect.any(Object))
})
})
}
)
describe.each([{ permission: 'Search' }])(
'Test on misc client methods w/ search apikey',
({ permission }) => {
beforeEach(() => {
return clearAllIndexes(config)
})
describe('Test on indexes methods', () => {
test(`${permission} key: try to get all indexes and be denied`, async () => {
const client = await getClient(permission)
await expect(client.getIndexes()).rejects.toHaveProperty(
'code',
ErrorStatusCode.INVALID_API_KEY
)
})
test(`${permission} key: try to create Index with primary key and be denied`, async () => {
const client = await getClient(permission)
await expect(
client.createIndex(indexPk.uid, {
primaryKey: indexPk.primaryKey,
})
).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY)
})
test(`${permission} key: try to create Index with NO primary key and be denied`, async () => {
const client = await getClient(permission)
await expect(client.createIndex(indexNoPk.uid)).rejects.toHaveProperty(
'code',
ErrorStatusCode.INVALID_API_KEY
)
})
test(`${permission} key: try to delete index and be denied`, async () => {
const client = await getClient(permission)
await expect(client.deleteIndex(indexPk.uid)).rejects.toHaveProperty(
'code',
ErrorStatusCode.INVALID_API_KEY
)
})
test(`${permission} key: try to update index and be denied`, async () => {
const client = await getClient(permission)
await expect(
client.updateIndex(indexPk.uid, {
primaryKey: indexPk.primaryKey,
})
).rejects.toHaveProperty('code', ErrorStatusCode.INVALID_API_KEY)
})
})
describe('Test on misc client methods', () => {
test(`${permission} key: get health`, async () => {
const client = await getClient(permission)
const response: Health = await client.health()
expect(response).toHaveProperty(
'status',
expect.stringMatching('available')
)
})
test(`${permission} key: try to get version and be denied`, async () => {
const client = await getClient(permission)
await expect(client.getVersion()).rejects.toHaveProperty(
'code',
ErrorStatusCode.INVALID_API_KEY
)
})
test(`${permission} key: try to get /stats information and be denied`, async () => {
const client = await getClient(permission)
await expect(client.getStats()).rejects.toHaveProperty(
'code',
ErrorStatusCode.INVALID_API_KEY
)
})
})
}
)
describe.each([{ permission: 'No' }])(
'Test on misc client methods w/ no apiKey client',
({ permission }) => {
beforeEach(() => {
return clearAllIndexes(config)
})
describe('Test on indexes methods', () => {
test(`${permission} key: try to get all indexes and be denied`, async () => {
const client = await getClient(permission)
await expect(client.getIndexes()).rejects.toHaveProperty(
'code',
ErrorStatusCode.MISSING_AUTHORIZATION_HEADER
)
})
test(`${permission} key: try to create Index with primary key and be denied`, async () => {
const client = await getClient(permission)
await expect(
client.createIndex(indexPk.uid, {
primaryKey: indexPk.primaryKey,
})
).rejects.toHaveProperty(
'code',
ErrorStatusCode.MISSING_AUTHORIZATION_HEADER
)
})
test(`${permission} key: try to create Index with NO primary key and be denied`, async () => {
const client = await getClient(permission)
await expect(client.createIndex(indexNoPk.uid)).rejects.toHaveProperty(
'code',
ErrorStatusCode.MISSING_AUTHORIZATION_HEADER
)
})
test(`${permission} key: try to delete index and be denied`, async () => {
const client = await getClient(permission)
await expect(client.deleteIndex(indexPk.uid)).rejects.toHaveProperty(
'code',
ErrorStatusCode.MISSING_AUTHORIZATION_HEADER
)
})
test(`${permission} key: try to update index and be denied`, async () => {
const client = await getClient(permission)
await expect(
client.updateIndex(indexPk.uid, {
primaryKey: indexPk.primaryKey,
})
).rejects.toHaveProperty(
'code',
ErrorStatusCode.MISSING_AUTHORIZATION_HEADER
)
})
})
describe('Test on misc client methods', () => {
test(`${permission} key: get health`, async () => {
const client = await getClient(permission)
const response: Health = await client.health()
expect(response).toHaveProperty(
'status',
expect.stringMatching('available')
)
})
test(`${permission} key: try to get version and be denied`, async () => {
const client = await getClient(permission)
await expect(client.getVersion()).rejects.toHaveProperty(
'code',
ErrorStatusCode.MISSING_AUTHORIZATION_HEADER
)
})
test(`${permission} key: try to get /stats information and be denied`, async () => {
const client = await getClient(permission)
await expect(client.getStats()).rejects.toHaveProperty(
'code',
ErrorStatusCode.MISSING_AUTHORIZATION_HEADER
)
})
})
}
)
describe.each([
{ host: BAD_HOST, trailing: false },
{ host: `${BAD_HOST}/api`, trailing: false },
{ host: `${BAD_HOST}/trailing/`, trailing: true },
])('Tests on url construction', ({ host, trailing }) => {
test(`Test getIndex route`, async () => {
const route = `indexes/${indexPk.uid}`
const client = new MeiliSearch({ host })
const strippedHost = trailing ? host.slice(0, -1) : host
await expect(client.getIndex(indexPk.uid)).rejects.toHaveProperty(
'message',
`request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace(
'http://',
''
)}`
)
})
test(`Test createIndex route`, async () => {
const route = `indexes`
const client = new MeiliSearch({ host })
const strippedHost = trailing ? host.slice(0, -1) : host
await expect(client.createIndex(indexPk.uid)).rejects.toHaveProperty(
'message',
`request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace(
'http://',
''
)}`
)
})
test(`Test updateIndex route`, async () => {
const route = `indexes/${indexPk.uid}`
const client = new MeiliSearch({ host })
const strippedHost = trailing ? host.slice(0, -1) : host
await expect(client.updateIndex(indexPk.uid)).rejects.toHaveProperty(
'message',
`request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace(
'http://',
''
)}`
)
})
test(`Test deleteIndex route`, async () => {
const route = `indexes/${indexPk.uid}`
const client = new MeiliSearch({ host })
const strippedHost = trailing ? host.slice(0, -1) : host
await expect(client.deleteIndex(indexPk.uid)).rejects.toHaveProperty(
'message',
`request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace(
'http://',
''
)}`
)
})
test(`Test get indexes route`, async () => {
const route = `indexes`
const client = new MeiliSearch({ host })
const strippedHost = trailing ? host.slice(0, -1) : host
await expect(client.getIndexes()).rejects.toHaveProperty(
'message',
`request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace(
'http://',
''
)}`
)
})
test(`Test getKeys route`, async () => {
const route = `keys`
const client = new MeiliSearch({ host })
const strippedHost = trailing ? host.slice(0, -1) : host
await expect(client.getKeys()).rejects.toHaveProperty(
'message',
`request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace(
'http://',
''
)}`
)
})
test(`Test health route`, async () => {
const route = `health`
const client = new MeiliSearch({ host })
const strippedHost = trailing ? host.slice(0, -1) : host
await expect(client.health()).rejects.toHaveProperty(
'message',
`request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace(
'http://',
''
)}`
)
})
test(`Test stats route`, async () => {
const route = `stats`
const client = new MeiliSearch({ host })
const strippedHost = trailing ? host.slice(0, -1) : host
await expect(client.getStats()).rejects.toHaveProperty(
'message',
`request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace(
'http://',
''
)}`
)
})
test(`Test version route`, async () => {
const route = `version`
const client = new MeiliSearch({ host })
const strippedHost = trailing ? host.slice(0, -1) : host
await expect(client.getVersion()).rejects.toHaveProperty(
'message',
`request to ${strippedHost}/${route} failed, reason: connect ECONNREFUSED ${BAD_HOST.replace(
'http://',
''
)}`
)
})
})