Skip to main content
Glama
mock-api-client.ts2.27 kB
import type { RawStatusResponse, RawSummaryResponse, RawIncidentsResponse, RawScheduledMaintenancesResponse } from '../../../src/types/api.js'; import statusFixture from '../api-responses/status.json'; import statusDegradedFixture from '../api-responses/status-degraded.json'; import summaryFixture from '../api-responses/summary.json'; import incidentsFixture from '../api-responses/incidents.json'; import maintenanceFixture from '../api-responses/maintenance.json'; /** * Mock APIClient for testing */ export class MockAPIClient { private shouldFail = false; private failureError: Error | null = null; private delay = 0; private callCounts = new Map<string, number>(); // Test control methods setShouldFail(fail: boolean, error?: Error): void { this.shouldFail = fail; this.failureError = error || new Error('API request failed'); } setDelay(ms: number): void { this.delay = ms; } resetCallCounts(): void { this.callCounts.clear(); } getCallCount(method: string): number { return this.callCounts.get(method) || 0; } // Private helper to track calls and handle failures private async executeRequest<T>(method: string, response: T): Promise<T> { this.callCounts.set(method, (this.callCounts.get(method) || 0) + 1); if (this.delay) { await new Promise(resolve => setTimeout(resolve, this.delay)); } if (this.shouldFail) { throw this.failureError; } return response; } async fetchStatus(): Promise<RawStatusResponse> { return this.executeRequest('fetchStatus', statusFixture as RawStatusResponse); } async fetchStatusDegraded(): Promise<RawStatusResponse> { return this.executeRequest('fetchStatusDegraded', statusDegradedFixture as RawStatusResponse); } async fetchSummary(): Promise<RawSummaryResponse> { return this.executeRequest('fetchSummary', summaryFixture as RawSummaryResponse); } async fetchIncidents(): Promise<RawIncidentsResponse> { return this.executeRequest('fetchIncidents', incidentsFixture as RawIncidentsResponse); } async fetchMaintenance(): Promise<RawScheduledMaintenancesResponse> { return this.executeRequest('fetchMaintenance', maintenanceFixture as RawScheduledMaintenancesResponse); } }

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/robinmordasiewicz/f5cloudstatus-mcp'

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