fix: update search() return type to match v3 response format
Change TS client search() return type from Promise<Array<Memory>>
to Promise<{ results: Array<Memory> }> to match v3 API envelope.
Update unit test mocks to return {results: []} and fix assertions.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
7f19c499ca
commit
7c313add10
@@ -280,7 +280,7 @@ export default class MemoryClient {
|
|||||||
async search(
|
async search(
|
||||||
query: string,
|
query: string,
|
||||||
options?: SearchMemoryOptions,
|
options?: SearchMemoryOptions,
|
||||||
): Promise<Array<Memory>> {
|
): Promise<{ results: Array<Memory> }> {
|
||||||
if (this.telemetryId === "") await this.ping();
|
if (this.telemetryId === "") await this.ping();
|
||||||
const payloadKeys = Object.keys(options || {});
|
const payloadKeys = Object.keys(options || {});
|
||||||
this._captureEvent("search", [payloadKeys]);
|
this._captureEvent("search", [payloadKeys]);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* MemoryClient unit tests — search (v2 default, filters).
|
* MemoryClient unit tests — search (v3 endpoint, filters).
|
||||||
* Tests verify request construction, not mock response echo.
|
* Tests verify request construction, not mock response echo.
|
||||||
*/
|
*/
|
||||||
import { MemoryClient } from "../mem0";
|
import { MemoryClient } from "../mem0";
|
||||||
@@ -17,7 +17,10 @@ installConsoleSuppression();
|
|||||||
describe("MemoryClient - search()", () => {
|
describe("MemoryClient - search()", () => {
|
||||||
test("sends POST to /v3/memories/search/ by default", async () => {
|
test("sends POST to /v3/memories/search/ by default", async () => {
|
||||||
const extra = new Map<string, { status: number; body: unknown }>();
|
const extra = new Map<string, { status: number; body: unknown }>();
|
||||||
extra.set("/v3/memories/search/", { status: 200, body: [] });
|
extra.set("/v3/memories/search/", {
|
||||||
|
status: 200,
|
||||||
|
body: { results: [] },
|
||||||
|
});
|
||||||
const mock = setupMockFetch(extra);
|
const mock = setupMockFetch(extra);
|
||||||
|
|
||||||
const client = new MemoryClient({ apiKey: TEST_API_KEY });
|
const client = new MemoryClient({ apiKey: TEST_API_KEY });
|
||||||
@@ -30,7 +33,10 @@ describe("MemoryClient - search()", () => {
|
|||||||
|
|
||||||
test("includes query in request body", async () => {
|
test("includes query in request body", async () => {
|
||||||
const extra = new Map<string, { status: number; body: unknown }>();
|
const extra = new Map<string, { status: number; body: unknown }>();
|
||||||
extra.set("/v3/memories/search/", { status: 200, body: [] });
|
extra.set("/v3/memories/search/", {
|
||||||
|
status: 200,
|
||||||
|
body: { results: [] },
|
||||||
|
});
|
||||||
const mock = setupMockFetch(extra);
|
const mock = setupMockFetch(extra);
|
||||||
|
|
||||||
const client = new MemoryClient({ apiKey: TEST_API_KEY });
|
const client = new MemoryClient({ apiKey: TEST_API_KEY });
|
||||||
@@ -44,7 +50,10 @@ describe("MemoryClient - search()", () => {
|
|||||||
|
|
||||||
test("passes filters through to the API body", async () => {
|
test("passes filters through to the API body", async () => {
|
||||||
const extra = new Map<string, { status: number; body: unknown }>();
|
const extra = new Map<string, { status: number; body: unknown }>();
|
||||||
extra.set("/v3/memories/search/", { status: 200, body: [] });
|
extra.set("/v3/memories/search/", {
|
||||||
|
status: 200,
|
||||||
|
body: { results: [] },
|
||||||
|
});
|
||||||
const mock = setupMockFetch(extra);
|
const mock = setupMockFetch(extra);
|
||||||
|
|
||||||
const client = new MemoryClient({ apiKey: TEST_API_KEY });
|
const client = new MemoryClient({ apiKey: TEST_API_KEY });
|
||||||
@@ -56,7 +65,10 @@ describe("MemoryClient - search()", () => {
|
|||||||
|
|
||||||
test("passes complex OR filters through to the API body", async () => {
|
test("passes complex OR filters through to the API body", async () => {
|
||||||
const extra = new Map<string, { status: number; body: unknown }>();
|
const extra = new Map<string, { status: number; body: unknown }>();
|
||||||
extra.set("/v3/memories/search/", { status: 200, body: [] });
|
extra.set("/v3/memories/search/", {
|
||||||
|
status: 200,
|
||||||
|
body: { results: [] },
|
||||||
|
});
|
||||||
const mock = setupMockFetch(extra);
|
const mock = setupMockFetch(extra);
|
||||||
|
|
||||||
const client = new MemoryClient({ apiKey: TEST_API_KEY });
|
const client = new MemoryClient({ apiKey: TEST_API_KEY });
|
||||||
@@ -73,23 +85,29 @@ describe("MemoryClient - search()", () => {
|
|||||||
|
|
||||||
test("does not crash when called without options", async () => {
|
test("does not crash when called without options", async () => {
|
||||||
const extra = new Map<string, { status: number; body: unknown }>();
|
const extra = new Map<string, { status: number; body: unknown }>();
|
||||||
extra.set("/v3/memories/search/", { status: 200, body: [] });
|
extra.set("/v3/memories/search/", {
|
||||||
|
status: 200,
|
||||||
|
body: { results: [] },
|
||||||
|
});
|
||||||
setupMockFetch(extra);
|
setupMockFetch(extra);
|
||||||
|
|
||||||
const client = new MemoryClient({ apiKey: TEST_API_KEY });
|
const client = new MemoryClient({ apiKey: TEST_API_KEY });
|
||||||
const result: Memory[] = await client.search("query");
|
const result = await client.search("query");
|
||||||
expect(Array.isArray(result)).toBe(true);
|
expect(result).toHaveProperty("results");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("handles empty results array", async () => {
|
test("handles empty results array", async () => {
|
||||||
const extra = new Map<string, { status: number; body: unknown }>();
|
const extra = new Map<string, { status: number; body: unknown }>();
|
||||||
extra.set("/v3/memories/search/", { status: 200, body: [] });
|
extra.set("/v3/memories/search/", {
|
||||||
|
status: 200,
|
||||||
|
body: { results: [] },
|
||||||
|
});
|
||||||
setupMockFetch(extra);
|
setupMockFetch(extra);
|
||||||
|
|
||||||
const client = new MemoryClient({ apiKey: TEST_API_KEY });
|
const client = new MemoryClient({ apiKey: TEST_API_KEY });
|
||||||
const result: Memory[] = await client.search("nonexistent query", {
|
const result = await client.search("nonexistent query", {
|
||||||
filters: { userId: "u1" },
|
filters: { userId: "u1" },
|
||||||
});
|
});
|
||||||
expect(result).toHaveLength(0);
|
expect(result.results).toHaveLength(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user