Skip to main content
Glama
wordpress-integration.test.ts8.29 kB
/** * WordPress Integration Tests * * Tests end-to-end WordPress operations with real API calls * Note: Requires valid WordPress credentials in .env file */ import { WordPressService } from '../../src/services/wordpress/wordpress-service.js'; import { getWordPressConfig } from '../../src/config/wordpress-config.js'; // Skip these tests if WordPress credentials are not available const describeIfWordPressConfigured = process.env.WORDPRESS_BASE_URL ? describe : describe.skip; describeIfWordPressConfigured('WordPress Integration Tests', () => { let wpService: WordPressService; let testPostId: number; let testPageId: number; beforeAll(() => { const config = getWordPressConfig(); if (!config) { throw new Error('WordPress configuration not available'); } wpService = new WordPressService(config); }); describe('Posts Operations', () => { it('should create a test post', async () => { const postData = { title: 'Integration Test Post - ' + Date.now(), content: 'This is a test post created by integration tests.', status: 'draft' }; const result = await wpService.posts.createPost(postData); expect(result).toBeDefined(); expect(result.id).toBeDefined(); expect(result.title.rendered).toContain('Integration Test Post'); testPostId = result.id; }, 10000); it('should retrieve the created post', async () => { expect(testPostId).toBeDefined(); const result = await wpService.posts.getPost(testPostId); expect(result).toBeDefined(); expect(result.id).toBe(testPostId); expect(result.title.rendered).toContain('Integration Test Post'); }, 10000); it('should update the post', async () => { expect(testPostId).toBeDefined(); const updateData = { title: 'Updated Integration Test Post', content: 'This post has been updated by integration tests.' }; const result = await wpService.posts.updatePost(testPostId, updateData); expect(result).toBeDefined(); expect(result.title.rendered).toBe('Updated Integration Test Post'); }, 10000); it('should list posts', async () => { const result = await wpService.posts.listPosts({ per_page: 5, status: 'any' }); expect(result).toBeDefined(); expect(Array.isArray(result)).toBe(true); expect(result.length).toBeGreaterThan(0); }, 10000); it('should search posts', async () => { const result = await wpService.posts.searchPosts('Integration Test'); expect(result).toBeDefined(); expect(Array.isArray(result)).toBe(true); }, 10000); it('should delete the test post', async () => { expect(testPostId).toBeDefined(); const result = await wpService.posts.deletePost(testPostId, true); expect(result).toBeDefined(); expect(result.deleted).toBe(true); }, 10000); }); describe('Pages Operations', () => { it('should create a test page', async () => { const pageData = { title: 'Integration Test Page - ' + Date.now(), content: 'This is a test page created by integration tests.', status: 'draft' }; const result = await wpService.pages.createPage(pageData); expect(result).toBeDefined(); expect(result.id).toBeDefined(); expect(result.title.rendered).toContain('Integration Test Page'); testPageId = result.id; }, 10000); it('should retrieve the created page', async () => { expect(testPageId).toBeDefined(); const result = await wpService.pages.getPage(testPageId); expect(result).toBeDefined(); expect(result.id).toBe(testPageId); }, 10000); it('should update the page', async () => { expect(testPageId).toBeDefined(); const updateData = { title: 'Updated Integration Test Page', content: 'This page has been updated by integration tests.' }; const result = await wpService.pages.updatePage(testPageId, updateData); expect(result).toBeDefined(); expect(result.title.rendered).toBe('Updated Integration Test Page'); }, 10000); it('should list pages', async () => { const result = await wpService.pages.listPages({ per_page: 5, status: 'any' }); expect(result).toBeDefined(); expect(Array.isArray(result)).toBe(true); expect(result.length).toBeGreaterThan(0); }, 10000); it('should get page by slug', async () => { expect(testPageId).toBeDefined(); // Get the page to find its slug const page = await wpService.pages.getPage(testPageId); const slug = page.slug; const result = await wpService.pages.getPageIdBySlug(slug); expect(result).toBe(testPageId); }, 10000); it('should list all content', async () => { const result = await wpService.pages.listAllContent(); expect(result).toBeDefined(); expect(Array.isArray(result)).toBe(true); }, 10000); it('should delete the test page', async () => { expect(testPageId).toBeDefined(); const result = await wpService.pages.deletePage(testPageId, true); expect(result).toBeDefined(); expect(result.deleted).toBe(true); }, 10000); }); describe('Media Operations', () => { it('should list media files', async () => { const result = await wpService.media.listMedia({ per_page: 5 }); expect(result).toBeDefined(); expect(Array.isArray(result)).toBe(true); }, 10000); it('should get media by ID if available', async () => { const mediaList = await wpService.media.listMedia({ per_page: 1 }); if (mediaList && mediaList.length > 0) { const mediaId = mediaList[0].id; const result = await wpService.media.getMedia(mediaId); expect(result).toBeDefined(); expect(result.id).toBe(mediaId); } }, 10000); }); describe('Users Operations', () => { it('should list users', async () => { const result = await wpService.users.listUsers({ per_page: 5 }); expect(result).toBeDefined(); expect(Array.isArray(result)).toBe(true); expect(result.length).toBeGreaterThan(0); }, 10000); it('should get user by ID', async () => { const usersList = await wpService.users.listUsers({ per_page: 1 }); if (usersList && usersList.length > 0) { const userId = usersList[0].id; const result = await wpService.users.getUser(userId); expect(result).toBeDefined(); expect(result.id).toBe(userId); } }, 10000); it('should search users', async () => { const result = await wpService.users.searchUsers('admin'); expect(result).toBeDefined(); expect(Array.isArray(result)).toBe(true); }, 10000); }); describe('Taxonomy Operations', () => { it('should list categories', async () => { const result = await wpService.taxonomies.getCategories({ per_page: 5 }); expect(result).toBeDefined(); expect(Array.isArray(result)).toBe(true); }, 10000); it('should list tags', async () => { const result = await wpService.taxonomies.getTags({ per_page: 5 }); expect(result).toBeDefined(); expect(Array.isArray(result)).toBe(true); }, 10000); it('should get category by ID if available', async () => { const categories = await wpService.taxonomies.getCategories({ per_page: 1 }); if (categories && categories.length > 0) { const categoryId = categories[0].id; const result = await wpService.taxonomies.getCategory(categoryId); expect(result).toBeDefined(); expect(result.id).toBe(categoryId); } }, 10000); }); describe('Error Handling', () => { it('should handle not found errors', async () => { await expect(wpService.posts.getPost(999999)).rejects.toThrow(); }, 10000); it('should handle invalid data errors', async () => { await expect(wpService.posts.createPost({ title: '', content: '' })).rejects.toThrow(); }, 10000); }); });

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