Skip to content

Commit d728f7f

Browse files
norwindijkmantharropoulos
authored andcommitted
rename multisearch to multi_search and prevent double query params
1 parent 752145a commit d728f7f

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

src/http/fetch/multisearch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async function multisearch<const Searches extends readonly object[]>(
6565
const urlParams = new URLSearchParams(normalizeQueryParams(queryParams));
6666

6767
return await makeRequest({
68-
endpoint: `/multisearch?${urlParams.toString()}`,
68+
endpoint: `/multi_search`,
6969
config: getConfiguration(config),
7070
method: "POST",
7171
body: searchParams,

tests/multisearch.test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { configure } from "@/config";
2+
import { RequestError } from "@/error";
23
import { collection } from "@/http/fetch";
34
import { multisearch } from "@/http/fetch/multisearch";
45
import { multisearchEntry } from "@/multisearch";
@@ -1009,4 +1010,58 @@ describe("multisearch tests", () => {
10091010
});
10101011
});
10111012
});
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+
});
10121067
});

0 commit comments

Comments
 (0)