mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-01-30 06:22:04 +00:00
feat: implement integration testing foundation (Phase 1)
Complete implementation of Phase 1 foundation for n8n API integration tests. Establishes core utilities, fixtures, and infrastructure for testing all 17 n8n API handlers against real n8n instance. Changes: - Add integration test environment configuration to .env.example - Create comprehensive test utilities infrastructure: * credentials.ts: Environment-aware credential management (local .env vs CI secrets) * n8n-client.ts: Singleton API client wrapper with health checks * test-context.ts: Resource tracking and automatic cleanup * cleanup-helpers.ts: Multi-level cleanup strategies (orphaned, age-based, tag-based) * fixtures.ts: 6 pre-built workflow templates (webhook, HTTP, multi-node, error handling, AI, expressions) * factories.ts: Dynamic node/workflow builders with 15+ factory functions * webhook-workflows.ts: Webhook workflow configs and setup instructions - Add npm scripts: * test:integration:n8n: Run n8n API integration tests * test:cleanup:orphans: Clean up orphaned test resources - Create cleanup script for CI/manual use Documentation: - Add comprehensive integration testing plan (550 lines) - Add Phase 1 completion summary with lessons learned Key Features: - Automatic credential detection (CI vs local) - Multi-level cleanup (test, suite, CI, orphan) - 6 workflow fixtures covering common scenarios - 15+ factory functions for dynamic test data - Support for 4 HTTP methods (GET, POST, PUT, DELETE) via pre-activated webhook workflows - TypeScript-first with full type safety - Comprehensive error handling with helpful messages Total: ~1,520 lines of production-ready code + 650 lines of documentation Ready for Phase 2: Workflow creation tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
63
tests/integration/n8n-api/utils/n8n-client.ts
Normal file
63
tests/integration/n8n-api/utils/n8n-client.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Pre-configured n8n API Client for Integration Tests
|
||||
*
|
||||
* Provides a singleton API client instance configured with test credentials.
|
||||
* Automatically loads credentials from .env (local) or GitHub secrets (CI).
|
||||
*/
|
||||
|
||||
import { N8nApiClient } from '../../../../src/services/n8n-api-client';
|
||||
import { getN8nCredentials, validateCredentials } from './credentials';
|
||||
|
||||
let client: N8nApiClient | null = null;
|
||||
|
||||
/**
|
||||
* Get or create the test n8n API client
|
||||
*
|
||||
* Creates a singleton instance configured with credentials from
|
||||
* the environment. Validates that required credentials are present.
|
||||
*
|
||||
* @returns Configured N8nApiClient instance
|
||||
* @throws Error if credentials are missing or invalid
|
||||
*
|
||||
* @example
|
||||
* const client = getTestN8nClient();
|
||||
* const workflow = await client.createWorkflow({ ... });
|
||||
*/
|
||||
export function getTestN8nClient(): N8nApiClient {
|
||||
if (!client) {
|
||||
const creds = getN8nCredentials();
|
||||
validateCredentials(creds);
|
||||
client = new N8nApiClient({
|
||||
baseUrl: creds.url,
|
||||
apiKey: creds.apiKey
|
||||
});
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the test client instance
|
||||
*
|
||||
* Forces recreation of the client on next call to getTestN8nClient().
|
||||
* Useful for testing or when credentials change.
|
||||
*/
|
||||
export function resetTestN8nClient(): void {
|
||||
client = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the n8n API is accessible
|
||||
*
|
||||
* Performs a health check to verify API connectivity.
|
||||
*
|
||||
* @returns true if API is accessible, false otherwise
|
||||
*/
|
||||
export async function isN8nApiAccessible(): Promise<boolean> {
|
||||
try {
|
||||
const client = getTestN8nClient();
|
||||
await client.healthCheck();
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user