Skip to main content
Glama
hub-connection-guard.test.ts1.81 kB
import { checkHubConnection } from "./hub-connection-guard.js"; import { HubService, HubConnectionError } from "../services/hub.js"; describe("checkHubConnection", () => { const createMockHubService = ( status: "authenticated" | "unauthenticated", connectionError?: HubConnectionError, ): HubService => ({ status: { status, connectionError }, }) as unknown as HubService; describe("when enforceConnection is false", () => { it("should allow connection regardless of hub status", () => { const hubService = createMockHubService("unauthenticated"); const result = checkHubConnection(hubService, false); expect(result).toEqual({ allowed: true }); }); }); describe("when enforceConnection is true", () => { it("should allow connection when hub is authenticated", () => { const hubService = createMockHubService("authenticated"); const result = checkHubConnection(hubService, true); expect(result).toEqual({ allowed: true }); }); it("should reject connection when hub is unauthenticated", () => { const hubService = createMockHubService("unauthenticated"); const result = checkHubConnection(hubService, true); expect(result).toEqual({ allowed: false, status: "unauthenticated", connectionError: undefined, }); }); it("should include connection error when present", () => { const connectionError = new HubConnectionError("Hub is unavailable"); const hubService = createMockHubService( "unauthenticated", connectionError, ); const result = checkHubConnection(hubService, true); expect(result).toEqual({ allowed: false, status: "unauthenticated", connectionError, }); }); }); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/TheLunarCompany/lunar'

If you have feedback or need assistance with the MCP directory API, please join our Discord server