fix(client): honor page_size in get_all when page is not passed (#6900)

This commit is contained in:
Kartik
2026-08-14 16:49:58 +05:30
committed by GitHub
parent a133287015
commit bfb51c6b93
4 changed files with 206 additions and 14 deletions
+4 -4
View File
@@ -404,10 +404,10 @@ export default class MemoryClient {
...(filters && { filters }),
};
let url = `${this.host}/v3/memories/`;
if (page && pageSize) {
url += `?page=${page}&page_size=${pageSize}`;
}
const queryParams: string[] = [];
if (page !== undefined) queryParams.push(`page=${page}`);
if (pageSize !== undefined) queryParams.push(`page_size=${pageSize}`);
const url = `${this.host}/v3/memories/${queryParams.length ? `?${queryParams.join("&")}` : ""}`;
const response = await this._fetchWithErrorHandling(url, {
method: "POST",
@@ -373,3 +373,56 @@ describe("MemoryClient - getAll() entity param rejection", () => {
expect(getFetchBody(call!).show_expired).toBe(true);
});
});
describe("MemoryClient - getAll() page/pageSize query params", () => {
test("sends no query params when neither page nor pageSize is provided", async () => {
const extra = new Map<string, { status: number; body: unknown }>();
extra.set("/v3/memories/", { status: 200, body: { results: [] } });
const mock = setupMockFetch(extra);
const client = new MemoryClient({ apiKey: TEST_API_KEY });
await client.getAll({ filters: { user_id: "u1" } });
const call = findFetchCall(mock, "/v3/memories/", "POST");
expect(call![0]).not.toContain("?");
});
test("sends page alone as a query param", async () => {
const extra = new Map<string, { status: number; body: unknown }>();
extra.set("/v3/memories/", { status: 200, body: { results: [] } });
const mock = setupMockFetch(extra);
const client = new MemoryClient({ apiKey: TEST_API_KEY });
await client.getAll({ filters: { user_id: "u1" }, page: 2 });
const call = findFetchCall(mock, "/v3/memories/", "POST");
expect(call![0]).toContain("?page=2");
expect(call![0]).not.toContain("page_size");
});
test("sends pageSize alone as a query param", async () => {
const extra = new Map<string, { status: number; body: unknown }>();
extra.set("/v3/memories/", { status: 200, body: { results: [] } });
const mock = setupMockFetch(extra);
const client = new MemoryClient({ apiKey: TEST_API_KEY });
await client.getAll({ filters: { user_id: "u1" }, pageSize: 50 });
const call = findFetchCall(mock, "/v3/memories/", "POST");
expect(call![0]).toContain("?page_size=50");
expect(call![0]).not.toContain("?page=50");
});
test("sends both page and pageSize when provided, including falsy 0 values", async () => {
const extra = new Map<string, { status: number; body: unknown }>();
extra.set("/v3/memories/", { status: 200, body: { results: [] } });
const mock = setupMockFetch(extra);
const client = new MemoryClient({ apiKey: TEST_API_KEY });
await client.getAll({ filters: { user_id: "u1" }, page: 0, pageSize: 0 });
const call = findFetchCall(mock, "/v3/memories/", "POST");
expect(call![0]).toContain("page=0");
expect(call![0]).toContain("page_size=0");
});
});