Skip to main content
Glama
client.test.ts2.76 kB
// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors // SPDX-License-Identifier: Apache-2.0 import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'; import { HealthieClient } from './client'; type MockResponse = { json: () => Promise<any>; ok: boolean; status: number; }; describe('HealthieClient', () => { let healthieClient: HealthieClient; const mockBaseUrl = 'https://api.example.com/graphql'; const mockClientSecret = 'test-secret'; let mockFetch: ReturnType<typeof vi.fn>; beforeEach(() => { healthieClient = new HealthieClient(mockBaseUrl, mockClientSecret); // Mock fetch globally mockFetch = vi.fn().mockImplementation((): Promise<MockResponse> => { return Promise.resolve({ json: () => Promise.resolve({}), ok: true, status: 200, }); }); global.fetch = mockFetch as unknown as typeof fetch; }); afterEach(() => { vi.resetAllMocks(); }); describe('constructor', () => { test('creates instance with correct properties', () => { expect(healthieClient).toBeInstanceOf(HealthieClient); }); }); describe('query', () => { test('successful query', async () => { const mockResponse = { data: { users: [{ id: '123', name: 'Test User' }], }, }; mockFetch.mockImplementationOnce( (): Promise<MockResponse> => Promise.resolve({ json: () => Promise.resolve(mockResponse), ok: true, status: 200, }) ); const result = await healthieClient.query('{ users { id name } }'); expect(result).toEqual(mockResponse.data); expect(mockFetch).toHaveBeenCalledWith( mockBaseUrl, expect.objectContaining({ method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${mockClientSecret}`, AuthorizationSource: 'API', }, }) ); }); test('handles GraphQL errors', async () => { const mockResponse = { errors: [{ message: 'GraphQL Error' }], }; mockFetch.mockImplementationOnce( (): Promise<MockResponse> => Promise.resolve({ json: () => Promise.resolve(mockResponse), ok: true, status: 200, }) ); await expect(healthieClient.query('{ users { id name } }')).rejects.toThrow('GraphQL Error'); }); test('handles missing client secret', async () => { const invalidClient = new HealthieClient(mockBaseUrl, ''); await expect(invalidClient.query('{ users { id name } }')).rejects.toThrow('Healthie credentials not provided'); }); }); });

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/medplum/medplum'

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