|
| 1 | +// Integration test for Google Researcher MCP Server |
| 2 | +// npx vitest services/marketplace/__tests__/google-researcher-integration.spec.ts |
| 3 | + |
| 4 | +import { RemoteConfigLoader } from "../RemoteConfigLoader" |
| 5 | +import axios from "axios" |
| 6 | + |
| 7 | +// Mock axios to simulate remote API failure |
| 8 | +vi.mock("axios") |
| 9 | +const mockedAxios = axios as any |
| 10 | + |
| 11 | +// Mock the cloud config |
| 12 | +vi.mock("@roo-code/cloud", () => ({ |
| 13 | + getRooCodeApiUrl: () => "https://test.api.com", |
| 14 | +})) |
| 15 | + |
| 16 | +describe("Google Researcher MCP Server Integration", () => { |
| 17 | + let loader: RemoteConfigLoader |
| 18 | + |
| 19 | + beforeEach(() => { |
| 20 | + loader = new RemoteConfigLoader() |
| 21 | + vi.clearAllMocks() |
| 22 | + loader.clearCache() |
| 23 | + }) |
| 24 | + |
| 25 | + it("should load Google Researcher MCP Server from local data when remote fails", async () => { |
| 26 | + // Mock remote API to fail, triggering local fallback |
| 27 | + mockedAxios.get.mockImplementation((url: string) => { |
| 28 | + if (url.includes("/modes")) { |
| 29 | + return Promise.resolve({ data: "items: []" }) |
| 30 | + } |
| 31 | + if (url.includes("/mcps")) { |
| 32 | + return Promise.reject(new Error("Remote API unavailable")) |
| 33 | + } |
| 34 | + return Promise.reject(new Error("Unknown URL")) |
| 35 | + }) |
| 36 | + |
| 37 | + // Load all items - should fallback to local data |
| 38 | + const items = await loader.loadAllItems() |
| 39 | + |
| 40 | + // Should contain at least the Google Researcher MCP |
| 41 | + const googleResearcherMcp = items.find((item) => item.type === "mcp" && item.id === "google-researcher-mcp") |
| 42 | + |
| 43 | + expect(googleResearcherMcp).toBeDefined() |
| 44 | + expect(googleResearcherMcp?.name).toBe("Google Researcher MCP Server") |
| 45 | + expect(googleResearcherMcp?.author).toBe("Zohar Babin") |
| 46 | + |
| 47 | + if (googleResearcherMcp?.type === "mcp") { |
| 48 | + expect(googleResearcherMcp.url).toBe("https://github.com/zoharbabin/google-research-mcp") |
| 49 | + expect(googleResearcherMcp.tags).toContain("research") |
| 50 | + expect(googleResearcherMcp.tags).toContain("google") |
| 51 | + expect(googleResearcherMcp.tags).toContain("search") |
| 52 | + |
| 53 | + // Check parameters |
| 54 | + expect(googleResearcherMcp.parameters).toBeDefined() |
| 55 | + expect(googleResearcherMcp.parameters).toHaveLength(3) |
| 56 | + |
| 57 | + const apiKeyParam = googleResearcherMcp.parameters?.find((p) => p.key === "google_search_api_key") |
| 58 | + expect(apiKeyParam).toBeDefined() |
| 59 | + expect(apiKeyParam?.name).toBe("Google Custom Search API Key") |
| 60 | + |
| 61 | + // Check installation methods |
| 62 | + expect(Array.isArray(googleResearcherMcp.content)).toBe(true) |
| 63 | + const methods = googleResearcherMcp.content as any[] |
| 64 | + expect(methods.length).toBeGreaterThan(0) |
| 65 | + |
| 66 | + const stdioMethod = methods.find((m) => m.name.includes("STDIO")) |
| 67 | + expect(stdioMethod).toBeDefined() |
| 68 | + expect(stdioMethod?.content).toContain("google-researcher") |
| 69 | + expect(stdioMethod?.content).toContain("npx") |
| 70 | + } |
| 71 | + }) |
| 72 | + |
| 73 | + it("should be able to retrieve Google Researcher MCP by ID", async () => { |
| 74 | + // Mock remote API to fail |
| 75 | + mockedAxios.get.mockImplementation((url: string) => { |
| 76 | + if (url.includes("/modes")) { |
| 77 | + return Promise.resolve({ data: "items: []" }) |
| 78 | + } |
| 79 | + if (url.includes("/mcps")) { |
| 80 | + return Promise.reject(new Error("Remote API unavailable")) |
| 81 | + } |
| 82 | + return Promise.reject(new Error("Unknown URL")) |
| 83 | + }) |
| 84 | + |
| 85 | + // Get specific item by ID |
| 86 | + const item = await loader.getItem("google-researcher-mcp", "mcp") |
| 87 | + |
| 88 | + expect(item).not.toBeNull() |
| 89 | + expect(item?.id).toBe("google-researcher-mcp") |
| 90 | + expect(item?.name).toBe("Google Researcher MCP Server") |
| 91 | + expect(item?.description).toContain("Google Search") |
| 92 | + expect(item?.description).toContain("research") |
| 93 | + }) |
| 94 | +}) |
0 commit comments