Skip to main content
Glama
README.mdβ€’5.71 kB
# Universal Tool Test Helpers This directory contains centralized helpers and utilities extracted from the oversized universal tool test files. It provides a clean, reusable infrastructure for testing universal tools while maintaining strict separation from production code. ## πŸ“ Structure ``` helpers/ β”œβ”€β”€ index.ts # Main export point for all helpers β”œβ”€β”€ test-constants.ts # Shared constants, budgets, and configuration β”œβ”€β”€ mock-data.ts # Mock data factories following mock factory pattern β”œβ”€β”€ mock-setup.ts # Standardized mock configurations β”œβ”€β”€ test-helpers.ts # Reusable utilities and assertion helpers β”œβ”€β”€ integration-helpers.ts # Real API test patterns and utilities └── README.md # This documentation ``` ## 🎯 Usage Patterns ### Unit Tests (Mocked) ```typescript import { setupUnitTestMocks, MockRecordFactory, assertionHelpers, cleanupMocks } from './helpers'; describe('My Universal Tool Tests', () => { // Setup mocks before tests setupUnitTestMocks(); beforeEach(async () => { await setupMockHandlers(); }); afterEach(() => { cleanupMocks(); }); it('should test something', async () => { const mockData = MockRecordFactory.createCompany(); // ... test logic assertionHelpers.assertValidCompanyRecord(result); }); }); ``` ### Integration Tests (Real API) ```typescript import { IntegrationTestSetup, IntegrationTestDataManager, integrationConfig } from './helpers'; describe('Integration Tests', () => { if (integrationConfig.shouldRun()) { const setup = IntegrationTestSetup.getInstance(); const dataManager = new IntegrationTestDataManager(); beforeAll(async () => { await setup.initializeApiClient(); }); afterAll(async () => { await dataManager.cleanupTrackedRecords(toolConfigs); }); } }); ``` ### Performance Tests ```typescript import { PerformanceTestRunner, PERFORMANCE_BUDGETS, integrationUtils } from './helpers'; describe('Performance Tests', () => { const runner = new PerformanceTestRunner(); it('should complete within budget', async () => { await runner.runPerformanceTest( 'batch create operation', async () => { return await batchCreateHandler(params); }, 'tenRecords' ); }); }); ``` ## πŸ—οΈ Architecture Principles ### Mock Factory Pattern Compliance - **βœ… Test Data Isolation**: All mock data is in `/test/` directory - **βœ… Production Code Separation**: No production imports in test helpers - **βœ… Consistent Interfaces**: All factories follow same patterns - **βœ… Type Safety**: Full TypeScript support with proper interfaces ### Clean Architecture - **Dependency Direction**: Test helpers only depend on test utilities - **Interface Segregation**: Separate helpers for different test types - **Single Responsibility**: Each helper file has a focused purpose - **Open/Closed**: Easy to extend without modifying existing code ### Performance Optimization - **CI/Local Awareness**: Automatic timeout multipliers for different environments - **Batch Operations**: Efficient cleanup and data management - **Resource Management**: Proper tracking and cleanup of test resources ## πŸ“Š Features Extracted ### From `advanced-operations.test.ts` (1065 lines) - βœ… Mock setup patterns for specialized handlers - βœ… Advanced search parameter factories - βœ… Date validation mock utilities - βœ… Complex beforeEach/afterEach patterns ### From `core-operations.test.ts` (935 lines) - βœ… ErrorService mock configurations - βœ… Core operation parameter factories - βœ… Standard assertion patterns - βœ… Universal resource type handling ### From `integration.test.ts` (865 lines) - βœ… Real API client initialization - βœ… Test data creation and tracking - βœ… Integration cleanup patterns - βœ… Environment-specific configuration ### From `performance.test.ts` (753 lines) - βœ… Performance budget management - βœ… CI multiplier calculations - βœ… Batch operation utilities - βœ… Performance measurement tools ## πŸ”§ Customization ### Adding New Mock Types ```typescript // In mock-data.ts export const MockRecordFactory = { // ... existing factories createCustomRecord: (overrides = {}) => { // Your custom mock logic } }; ``` ### Adding New Assertions ```typescript // In test-helpers.ts export const assertionHelpers = { // ... existing assertions assertValidCustomRecord: (record, expectedField) => { // Your custom assertion logic } }; ``` ### Environment-Specific Configuration ```typescript // In test-constants.ts export const CUSTOM_BUDGETS = { myOperation: Math.round(5000 * TEST_ENVIRONMENT.ciMultiplier), }; ``` ## πŸ§ͺ Testing the Helpers The helpers themselves follow the same patterns they provide: - Unit tested with mocks where appropriate - Integration tested with real dependencies - Performance characteristics verified - Clean architecture principles enforced ## πŸš€ Next Steps for Split Test Files When splitting the original oversized test files, use these helpers like this: ```typescript // advanced-operations-search.test.ts import { setupUnitTestMocks, MockParamsFactory, assertionHelpers } from './helpers'; // integration-core-operations.test.ts import { IntegrationTestSetup, IntegrationTestDataManager } from './helpers'; // performance-batch-operations.test.ts import { PerformanceTestRunner, PERFORMANCE_BUDGETS } from './helpers'; ``` This provides a consistent, maintainable foundation for all universal tool tests while eliminating code duplication and ensuring proper separation of concerns.

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/kesslerio/attio-mcp-server'

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