|
| 1 | +import { describe, it, expect, beforeAll, afterAll } from "vitest"; |
| 2 | +import type { Client } from "@modelcontextprotocol/sdk/client"; |
| 3 | +import { createClient, createTransport } from "./client"; |
| 4 | +import { configSchema } from "../src/config/schema"; |
| 5 | +import { testConfigSchema } from "./config"; |
| 6 | +import type { ProvidedConfig } from "../src/config/types/config"; |
| 7 | + |
| 8 | +describe("MCP Server Installation E2E Tests", () => { |
| 9 | + const mcpConfig = configSchema.parse(process.env); |
| 10 | + |
| 11 | + const config: ProvidedConfig = { |
| 12 | + KINTONE_BASE_URL: mcpConfig.KINTONE_BASE_URL, |
| 13 | + KINTONE_USERNAME: mcpConfig.KINTONE_USERNAME, |
| 14 | + KINTONE_PASSWORD: mcpConfig.KINTONE_PASSWORD, |
| 15 | + }; |
| 16 | + |
| 17 | + const testConfig = testConfigSchema.parse(process.env); |
| 18 | + |
| 19 | + const appId = testConfig.APP_ID; |
| 20 | + const runtime = testConfig.RUNTIME; |
| 21 | + |
| 22 | + let client: Client; |
| 23 | + |
| 24 | + beforeAll(async () => { |
| 25 | + const transport = createTransport(runtime, config); |
| 26 | + client = await createClient(transport); |
| 27 | + }); |
| 28 | + |
| 29 | + afterAll(async () => { |
| 30 | + await client.close(); |
| 31 | + }); |
| 32 | + |
| 33 | + describe("Tool List Verification", () => { |
| 34 | + it("should list all kintone tools correctly", async () => { |
| 35 | + // Act |
| 36 | + const tools = await client.listTools(); |
| 37 | + const toolNames = tools.tools.map((tool) => tool.name); |
| 38 | + |
| 39 | + // Assert |
| 40 | + expect(tools.tools).toBeInstanceOf(Array); |
| 41 | + expect(tools.tools.length).toBeGreaterThan(0); |
| 42 | + |
| 43 | + // 特定のツールが含まれていることを確認 |
| 44 | + expect(toolNames).toContain("kintone-get-app"); |
| 45 | + |
| 46 | + // すべてのツールがkintoneプレフィックスを持つことを確認 |
| 47 | + tools.tools.forEach((tool) => { |
| 48 | + expect(tool).toHaveProperty("name"); |
| 49 | + expect(tool).toHaveProperty("description"); |
| 50 | + expect(tool).toHaveProperty("inputSchema"); |
| 51 | + expect(tool.name).toMatch(/^kintone-/); |
| 52 | + }); |
| 53 | + }); |
| 54 | + }); |
| 55 | + |
| 56 | + describe("Tool Execution Verification", () => { |
| 57 | + it("should execute kintone-get-app tool correctly", async () => { |
| 58 | + // Act |
| 59 | + const result = await client.callTool({ |
| 60 | + name: "kintone-get-app", |
| 61 | + arguments: { |
| 62 | + appId: appId, |
| 63 | + }, |
| 64 | + }); |
| 65 | + |
| 66 | + // Assert |
| 67 | + expect(result).not.toHaveProperty("isError"); |
| 68 | + expect(result).toHaveProperty("content"); |
| 69 | + expect(result).toHaveProperty("structuredContent"); |
| 70 | + |
| 71 | + // content配列の検証 |
| 72 | + expect(result.content).toBeInstanceOf(Array); |
| 73 | + expect((result.content as unknown[]).length).toBeGreaterThan(0); |
| 74 | + expect((result.content as unknown[])[0]).toHaveProperty("type", "text"); |
| 75 | + expect((result.content as unknown[])[0]).toHaveProperty("text"); |
| 76 | + |
| 77 | + // structuredContentの検証 |
| 78 | + const structuredContent = result.structuredContent as Record< |
| 79 | + string, |
| 80 | + unknown |
| 81 | + >; |
| 82 | + expect(structuredContent).toHaveProperty("appId", appId); |
| 83 | + expect(structuredContent).toHaveProperty("name"); |
| 84 | + expect(structuredContent).toHaveProperty("description"); |
| 85 | + expect(structuredContent).toHaveProperty("createdAt"); |
| 86 | + expect(structuredContent).toHaveProperty("creator"); |
| 87 | + expect(structuredContent).toHaveProperty("modifiedAt"); |
| 88 | + expect(structuredContent).toHaveProperty("modifier"); |
| 89 | + }); |
| 90 | + }); |
| 91 | +}); |
0 commit comments