98 lines
2.6 KiB
TypeScript
98 lines
2.6 KiB
TypeScript
/*
|
|
* @Date: 2026-01-07 09:11:08
|
|
* @LastEditors: 陈子健
|
|
* @LastEditTime: 2026-01-07 10:04:45
|
|
* @FilePath: /cloud-mcp/tests/unit/tools/common/notes.test.ts
|
|
*/
|
|
/**
|
|
* Notes tools tests
|
|
*/
|
|
|
|
import { describe, test, expect, beforeEach, afterEach } from "bun:test";
|
|
import { registerNoteTools } from "../../../../src/tools/common/notes.js";
|
|
import { callTool } from "../../../helpers/tool-helper.js";
|
|
import { createTempDir } from "../../../helpers/test-utils.js";
|
|
import { setupTestDatabase } from "../../../helpers/database-helper.js";
|
|
|
|
describe("Notes Tools", () => {
|
|
let testContext: ReturnType<typeof createTempDir>;
|
|
let cleanupDb: () => void;
|
|
|
|
beforeEach(() => {
|
|
testContext = createTempDir();
|
|
cleanupDb = setupTestDatabase(testContext);
|
|
registerNoteTools();
|
|
});
|
|
|
|
afterEach(() => {
|
|
cleanupDb();
|
|
testContext.cleanup();
|
|
});
|
|
|
|
test("should create note", async () => {
|
|
const result = await callTool("note_create", {
|
|
title: "Test Note",
|
|
content: "This is a test note",
|
|
tags: ["test"],
|
|
});
|
|
|
|
expect(result.content[0].text).toContain("saved successfully");
|
|
expect(result.content[0].text).toContain("Test Note");
|
|
});
|
|
|
|
test("should search notes", async () => {
|
|
// Create a note first
|
|
await callTool("note_create", {
|
|
title: "Test Note",
|
|
content: "This is a test note",
|
|
tags: ["test"],
|
|
});
|
|
|
|
const result = await callTool("note_search", {
|
|
query: "Test",
|
|
});
|
|
|
|
expect(result.content[0].text).toContain("Found");
|
|
expect(result.content[0].text).toContain("Test Note");
|
|
});
|
|
|
|
test("should list notes", async () => {
|
|
// Create a note
|
|
await callTool("note_create", {
|
|
title: "Test Note",
|
|
content: "This is a test note",
|
|
});
|
|
|
|
const result = await callTool("note_list", {});
|
|
|
|
expect(result.content[0].text).toContain("Total");
|
|
expect(result.content[0].text).toContain("Test Note");
|
|
});
|
|
|
|
test("should delete note", async () => {
|
|
// Create a note
|
|
const createResult = await callTool("note_create", {
|
|
title: "Test Note",
|
|
content: "This is a test note",
|
|
});
|
|
|
|
// Extract ID
|
|
const idMatch = createResult.content[0].text.match(/ID: ([a-f0-9-]+)/);
|
|
if (!idMatch) {
|
|
throw new Error("Could not extract ID");
|
|
}
|
|
const id = idMatch[1];
|
|
|
|
// Delete it
|
|
const result = await callTool("note_delete", { id });
|
|
|
|
expect(result.content[0].text).toContain("deleted successfully");
|
|
});
|
|
|
|
test("should handle empty notes list", async () => {
|
|
const result = await callTool("note_list", {});
|
|
|
|
expect(result.content[0].text).toMatch(/No notes found|Use note_create/i);
|
|
});
|
|
});
|