deer-flow/frontend/tests/unit/app/api/memory-route.test.ts
PeaceMaker-best b73a4e79bf
feat(memory): scope management API by agent (#5565)
* feat(memory): scope management API by agent

Signed-off-by: PeaceMaker-best <221849497+PeaceMaker-best@users.noreply.github.com>

* fix(memory): preserve scoped management isolation

Signed-off-by: PeaceMaker-best <221849497+PeaceMaker-best@users.noreply.github.com>

---------

Signed-off-by: PeaceMaker-best <221849497+PeaceMaker-best@users.noreply.github.com>
Co-authored-by: PeaceMaker-best <221849497+PeaceMaker-best@users.noreply.github.com>
2026-09-30 16:50:07 +08:00

59 lines
1.8 KiB
TypeScript

import { afterEach, describe, expect, it, rs } from "@rstest/core";
import { NextRequest } from "next/server";
import { POST as postMemoryPath } from "@/app/api/memory/[...path]/route";
import { DELETE as deleteMemory } from "@/app/api/memory/route";
describe("memory API proxy", () => {
afterEach(() => {
rs.restoreAllMocks();
});
it("preserves the selected agent on root destructive requests", async () => {
const fetchMock = rs
.spyOn(globalThis, "fetch")
.mockResolvedValue(new Response("{}", { status: 200 }));
const request = new NextRequest(
"http://deer-flow.test/api/memory?agent_name=Research-Agent",
{ method: "DELETE" },
);
await deleteMemory(request);
const [target] = fetchMock.mock.calls[0]!;
expect(target).toBeInstanceOf(URL);
if (!(target instanceof URL)) {
throw new Error("Memory proxy target must be a URL");
}
expect(target.href).toBe(
"http://127.0.0.1:8001/api/memory?agent_name=Research-Agent",
);
});
it("preserves the full query string on nested memory requests", async () => {
const fetchMock = rs
.spyOn(globalThis, "fetch")
.mockResolvedValue(new Response("{}", { status: 200 }));
const request = new NextRequest(
"http://deer-flow.test/api/memory/import?agent_name=Research-Agent&mode=facts%2Bmetadata",
{
method: "POST",
body: JSON.stringify({ facts: [] }),
},
);
await postMemoryPath(request, {
params: Promise.resolve({ path: ["import"] }),
});
const [target] = fetchMock.mock.calls[0]!;
expect(target).toBeInstanceOf(URL);
if (!(target instanceof URL)) {
throw new Error("Memory proxy target must be a URL");
}
expect(target.href).toBe(
"http://127.0.0.1:8001/api/memory/import?agent_name=Research-Agent&mode=facts%2Bmetadata",
);
});
});