|
1 | 1 | import { expect, test, describe, vi, beforeEach } from "vitest";
|
2 | 2 | import { NotionClientWrapper } from "./index.js";
|
3 | 3 | import { PageResponse } from "./types/index.js";
|
| 4 | +import { filterTools } from "./index.js"; |
4 | 5 |
|
5 | 6 | vi.mock("./markdown/index.js", () => ({
|
6 | 7 | convertToMarkdown: vi.fn().mockReturnValue("# Test"),
|
7 | 8 | }));
|
8 | 9 |
|
| 10 | +// Mock tool list |
| 11 | +const mockInputSchema = { type: "object" as const } |
| 12 | +const mockTools = [ |
| 13 | + { |
| 14 | + name: "notion_retrieve_block", |
| 15 | + inputSchema: mockInputSchema |
| 16 | + }, |
| 17 | + { |
| 18 | + name: "notion_retrieve_page", |
| 19 | + inputSchema: mockInputSchema |
| 20 | + }, |
| 21 | + { |
| 22 | + name: "notion_query_database", |
| 23 | + inputSchema: mockInputSchema |
| 24 | + } |
| 25 | +]; |
9 | 26 | global.fetch = vi.fn();
|
10 | 27 |
|
11 | 28 | describe("NotionClientWrapper", () => {
|
@@ -162,4 +179,26 @@ describe("NotionClientWrapper", () => {
|
162 | 179 |
|
163 | 180 | expect(convertToMarkdown).toHaveBeenCalledWith(response);
|
164 | 181 | });
|
| 182 | + |
| 183 | + describe("filterTools", () => { |
| 184 | + test("should return all tools when no filter specified", () => { |
| 185 | + const result = filterTools(mockTools); |
| 186 | + expect(result).toEqual(mockTools); |
| 187 | + }); |
| 188 | + |
| 189 | + test("should filter tools based on enabledTools", () => { |
| 190 | + const enabledToolsSet = new Set(["notion_retrieve_block", "notion_query_database"]); |
| 191 | + const result = filterTools(mockTools, enabledToolsSet); |
| 192 | + expect(result).toEqual([ |
| 193 | + { name: "notion_retrieve_block", inputSchema: mockInputSchema }, |
| 194 | + { name: "notion_query_database", inputSchema: mockInputSchema } |
| 195 | + ]); |
| 196 | + }); |
| 197 | + |
| 198 | + test("should return empty array when no tools match", () => { |
| 199 | + const enabledToolsSet = new Set(["non_existent_tool"]); |
| 200 | + const result = filterTools(mockTools, enabledToolsSet); |
| 201 | + expect(result).toEqual([]); |
| 202 | + }); |
| 203 | + }); |
165 | 204 | });
|
0 commit comments