|
1 | 1 | import { configure } from "@/config"; |
| 2 | +import { RequestError } from "@/error"; |
2 | 3 | import { collection } from "@/http/fetch"; |
3 | 4 | import { multisearch } from "@/http/fetch/multisearch"; |
4 | 5 | import { multisearchEntry } from "@/multisearch"; |
@@ -1009,4 +1010,58 @@ describe("multisearch tests", () => { |
1009 | 1010 | }); |
1010 | 1011 | }); |
1011 | 1012 | }); |
| 1013 | + describe("query parameters", () => { |
| 1014 | + it("is successful when the number of searches equals limit_multi_searches", async () => { |
| 1015 | + const { results } = await multisearch( |
| 1016 | + { |
| 1017 | + searches: [ |
| 1018 | + multisearchEntry({ |
| 1019 | + collection: "multi_search_test_1", |
| 1020 | + q: "q", |
| 1021 | + query_by: ["foo"], |
| 1022 | + }), |
| 1023 | + multisearchEntry({ |
| 1024 | + collection: "multi_search_test_2", |
| 1025 | + q: "q", |
| 1026 | + query_by: ["foo"], |
| 1027 | + }), |
| 1028 | + ], |
| 1029 | + }, |
| 1030 | + config, |
| 1031 | + { limit_multi_searches: 2 }, |
| 1032 | + ); |
| 1033 | + expect(results.length).toEqual(2); |
| 1034 | + }); |
| 1035 | + it("fails when the number of searches exceeds limit_multi_searches", async () => { |
| 1036 | + try { |
| 1037 | + await multisearch( |
| 1038 | + { |
| 1039 | + searches: [ |
| 1040 | + multisearchEntry({ |
| 1041 | + collection: "multi_search_test_1", |
| 1042 | + q: "q", |
| 1043 | + query_by: ["foo"], |
| 1044 | + }), |
| 1045 | + multisearchEntry({ |
| 1046 | + collection: "multi_search_test_2", |
| 1047 | + q: "q", |
| 1048 | + query_by: ["foo"], |
| 1049 | + }), |
| 1050 | + ], |
| 1051 | + }, |
| 1052 | + config, |
| 1053 | + { limit_multi_searches: 1 }, |
| 1054 | + ); |
| 1055 | + |
| 1056 | + throw new Error("Expected multisearch to throw, but it did not"); |
| 1057 | + } catch (error) { |
| 1058 | + expect(error).toBeInstanceOf(RequestError); |
| 1059 | + const reqError = error as RequestError; |
| 1060 | + expect(reqError.status).toBe(400); |
| 1061 | + expect(reqError.message).toContain( |
| 1062 | + "Number of multi searches exceeds `limit_multi_searches` parameter." |
| 1063 | + ); |
| 1064 | + } |
| 1065 | + }); |
| 1066 | + }); |
1012 | 1067 | }); |
0 commit comments