Skip to main content
Glama
wordpress-client.test.ts2.68 kB
/** * WordPress Client Unit Tests */ import { WordPressClient } from '../../src/services/wordpress-client.js'; import { WordPressConfig } from '../../src/types/wordpress.js'; import axios from 'axios'; // Mock axios jest.mock('axios'); const mockedAxios = axios as jest.Mocked<typeof axios>; describe('WordPressClient', () => { let client: WordPressClient; let config: WordPressConfig; beforeEach(() => { config = { baseUrl: 'https://test-site.com', username: 'testuser', applicationPassword: 'testpass' }; client = new WordPressClient(config); // Reset mocks jest.clearAllMocks(); }); describe('constructor', () => { it('should create client with correct configuration', () => { expect(client).toBeInstanceOf(WordPressClient); }); it('should set up authentication header', () => { const expectedAuth = Buffer.from(`${config.username}:${config.applicationPassword}`).toString('base64'); expect(mockedAxios.create).toHaveBeenCalledWith({ baseURL: config.baseUrl, timeout: 30000, headers: { 'Authorization': `Basic ${expectedAuth}`, 'Content-Type': 'application/json' } }); }); }); describe('getAxiosInstance', () => { it('should return axios instance', () => { const instance = client.getAxiosInstance(); expect(instance).toBeDefined(); }); }); describe('request interceptor', () => { it('should log request details in debug mode', () => { const mockRequest = { method: 'GET', url: '/wp-json/wp/v2/posts', headers: {} }; // Mock process.env.DEBUG_MODE const originalDebugMode = process.env.DEBUG_MODE; process.env.DEBUG_MODE = 'true'; // Test would require more complex setup to test interceptors // This is a placeholder for the actual test process.env.DEBUG_MODE = originalDebugMode; }); }); describe('response interceptor', () => { it('should handle successful responses', () => { const mockResponse = { data: { id: 1, title: 'Test Post' }, status: 200, statusText: 'OK' }; // Test would require more complex setup to test interceptors // This is a placeholder for the actual test }); it('should handle error responses', () => { const mockError = { response: { status: 404, statusText: 'Not Found', data: { message: 'Post not found' } } }; // Test would require more complex setup to test interceptors // This is a placeholder for the actual test }); }); });

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/mbrown1837/Ultimate-Elementor-MCP'

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