初始化提交
This commit is contained in:
commit
887c1f449e
963 files changed
+166869
No files matched your search
@@ -0,0 +1,67 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("./client", () => ({
|
||||
apiDelete: vi.fn(),
|
||||
apiGet: vi.fn(),
|
||||
apiPatch: vi.fn(),
|
||||
apiPost: vi.fn(),
|
||||
}));
|
||||
|
||||
import { apiDelete, apiGet, apiPatch, apiPost } from "./client";
|
||||
import {
|
||||
createMemory,
|
||||
deleteMemory,
|
||||
listMemories,
|
||||
updateMemory,
|
||||
} from "./memory";
|
||||
|
||||
describe("memory api", () => {
|
||||
it("listMemories GET /memory 支持分页与类型过滤", async () => {
|
||||
vi.mocked(apiGet).mockResolvedValue({ items: [], total: 0 });
|
||||
await listMemories({ page: 1, page_size: 20, type: "episodic" });
|
||||
expect(apiGet).toHaveBeenCalledWith("/memory", {
|
||||
page: 1,
|
||||
page_size: 20,
|
||||
type: "episodic",
|
||||
});
|
||||
});
|
||||
|
||||
it("createMemory POST /memory 默认 source=user_explicit", async () => {
|
||||
vi.mocked(apiPost).mockResolvedValue({ id: "mem_1" });
|
||||
await createMemory({ type: "episodic", title: "测试", content: "内容" });
|
||||
expect(apiPost).toHaveBeenCalledWith("/memory", {
|
||||
source: "user_explicit",
|
||||
type: "episodic",
|
||||
title: "测试",
|
||||
content: "内容",
|
||||
});
|
||||
});
|
||||
|
||||
it("createMemory 支持覆盖 source", async () => {
|
||||
vi.mocked(apiPost).mockResolvedValue({ id: "mem_2" });
|
||||
await createMemory({
|
||||
type: "episodic",
|
||||
title: "导入",
|
||||
content: "内容",
|
||||
source: "conversation",
|
||||
});
|
||||
expect(apiPost).toHaveBeenCalledWith("/memory", {
|
||||
source: "conversation",
|
||||
type: "episodic",
|
||||
title: "导入",
|
||||
content: "内容",
|
||||
});
|
||||
});
|
||||
|
||||
it("updateMemory PATCH /memory/:id", async () => {
|
||||
vi.mocked(apiPatch).mockResolvedValue({ id: "mem_1" });
|
||||
await updateMemory("mem_1", { title: "新标题" });
|
||||
expect(apiPatch).toHaveBeenCalledWith("/memory/mem_1", { title: "新标题" });
|
||||
});
|
||||
|
||||
it("deleteMemory DELETE /memory/:id", async () => {
|
||||
vi.mocked(apiDelete).mockResolvedValue(undefined);
|
||||
await deleteMemory("mem_1");
|
||||
expect(apiDelete).toHaveBeenCalledWith("/memory/mem_1");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user