|
6 | 6 | privateClient, |
7 | 7 | publicClient, |
8 | 8 | anonymousClient, |
| 9 | + badHostClient, |
| 10 | + BAD_HOST, |
9 | 11 | } from './meilisearch-test-utils' |
10 | 12 |
|
11 | 13 | const uidNoPrimaryKey = { |
@@ -499,3 +501,98 @@ describe.each([{ client: anonymousClient, permission: 'No' }])( |
499 | 501 | }) |
500 | 502 | } |
501 | 503 | ) |
| 504 | + |
| 505 | +test(`Get request should not add double slash nor a trailing slash`, async () => { |
| 506 | + try { |
| 507 | + const res = await badHostClient.index(uidNoPrimaryKey.uid).getDocuments() |
| 508 | + expect(res).toBe(undefined) // Left here to trigger failed test if error is not thrown |
| 509 | + } catch (e) { |
| 510 | + expect(e.message).toMatch(`${BAD_HOST}/indexes/movies_test/documents`) |
| 511 | + expect(e.message).not.toMatch(`${BAD_HOST}/indexes/movies_test/documents/`) |
| 512 | + expect(e.type).toBe('MeiliSearchCommunicationError') |
| 513 | + } |
| 514 | +}) |
| 515 | + |
| 516 | +test(`Get request with options should not add double slash nor a trailing slash`, async () => { |
| 517 | + try { |
| 518 | + const res = await badHostClient |
| 519 | + .index(uidNoPrimaryKey.uid) |
| 520 | + .getDocuments({ attributesToRetrieve: ['id'] }) |
| 521 | + expect(res).toBe(undefined) // Left here to trigger failed test if error is not thrown |
| 522 | + } catch (e) { |
| 523 | + expect(e.message).toMatch( |
| 524 | + `${BAD_HOST}/indexes/movies_test/documents?attributesToRetrieve=id` |
| 525 | + ) |
| 526 | + expect(e.message).not.toMatch(`${BAD_HOST}/indexes/movies_test/documents/`) |
| 527 | + expect(e.type).toBe('MeiliSearchCommunicationError') |
| 528 | + } |
| 529 | +}) |
| 530 | + |
| 531 | +test(`Update request should not add double slash nor a trailing slash`, async () => { |
| 532 | + try { |
| 533 | + const res = await badHostClient |
| 534 | + .index(uidNoPrimaryKey.uid) |
| 535 | + .updateDocuments([]) |
| 536 | + expect(res).toBe(undefined) // Left here to trigger failed test if error is not thrown |
| 537 | + } catch (e) { |
| 538 | + expect(e.message).toMatch(`${BAD_HOST}/indexes/movies_test/documents`) |
| 539 | + expect(e.message).not.toMatch(`${BAD_HOST}/indexes/movies_test/documents/`) |
| 540 | + expect(e.type).toBe('MeiliSearchCommunicationError') |
| 541 | + } |
| 542 | +}) |
| 543 | + |
| 544 | +test(`Delete batch request should not add double slash nor a trailing slash`, async () => { |
| 545 | + try { |
| 546 | + const res = await badHostClient |
| 547 | + .index(uidNoPrimaryKey.uid) |
| 548 | + .deleteDocuments([]) |
| 549 | + expect(res).toBe(undefined) // Left here to trigger failed test if error is not thrown |
| 550 | + } catch (e) { |
| 551 | + expect(e.message).toMatch( |
| 552 | + `${BAD_HOST}/indexes/movies_test/documents/delete-batch` |
| 553 | + ) |
| 554 | + expect(e.message).not.toMatch( |
| 555 | + `${BAD_HOST}/indexes/movies_test/documents/delete-batch/` |
| 556 | + ) |
| 557 | + expect(e.type).toBe('MeiliSearchCommunicationError') |
| 558 | + } |
| 559 | +}) |
| 560 | + |
| 561 | +test(`Delete all request should not add double slash nor a trailing slash`, async () => { |
| 562 | + try { |
| 563 | + const res = await badHostClient |
| 564 | + .index(uidNoPrimaryKey.uid) |
| 565 | + .deleteAllDocuments() |
| 566 | + expect(res).toBe(undefined) // Left here to trigger failed test if error is not thrown |
| 567 | + } catch (e) { |
| 568 | + expect(e.message).toMatch(`${BAD_HOST}/indexes/movies_test/documents`) |
| 569 | + expect(e.message).not.toMatch(`${BAD_HOST}/indexes/movies_test/documents/`) |
| 570 | + expect(e.type).toBe('MeiliSearchCommunicationError') |
| 571 | + } |
| 572 | +}) |
| 573 | + |
| 574 | +test(`Delete one request should not add double slash nor a trailing slash`, async () => { |
| 575 | + try { |
| 576 | + const res = await badHostClient.index(uidNoPrimaryKey.uid).deleteDocument(1) |
| 577 | + expect(res).toBe(undefined) // Left here to trigger failed test if error is not thrown |
| 578 | + } catch (e) { |
| 579 | + expect(e.message).toMatch(`${BAD_HOST}/indexes/movies_test/documents/1`) |
| 580 | + expect(e.message).not.toMatch( |
| 581 | + `${BAD_HOST}/indexes/movies_test/documents/1/` |
| 582 | + ) |
| 583 | + expect(e.type).toBe('MeiliSearchCommunicationError') |
| 584 | + } |
| 585 | +}) |
| 586 | + |
| 587 | +test(`Get one request should not add double slash nor a trailing slash`, async () => { |
| 588 | + try { |
| 589 | + const res = await badHostClient.index(uidNoPrimaryKey.uid).getDocument(1) |
| 590 | + expect(res).toBe(undefined) // Left here to trigger failed test if error is not thrown |
| 591 | + } catch (e) { |
| 592 | + expect(e.message).toMatch(`${BAD_HOST}/indexes/movies_test/documents/1`) |
| 593 | + expect(e.message).not.toMatch( |
| 594 | + `${BAD_HOST}/indexes/movies_test/documents/1/` |
| 595 | + ) |
| 596 | + expect(e.type).toBe('MeiliSearchCommunicationError') |
| 597 | + } |
| 598 | +}) |
0 commit comments