mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-01-29 22:12:05 +00:00
Implements comprehensive workflow creation tests against real n8n instance with 15 test scenarios covering P0 bugs, base nodes, advanced features, error scenarios, and edge cases. Key Changes: - Added 15 workflow creation test scenarios in create-workflow.test.ts - Fixed critical MSW interference with real API calls - Fixed environment loading priority (.env before test defaults) - Implemented multi-level cleanup with webhook workflow preservation - Migrated from webhook IDs to webhook URLs configuration - Added TypeScript type safety fixes (26 errors resolved) - Updated test names to reflect actual n8n API behavior Bug Fixes: - Removed MSW from integration test setup (was blocking real API calls) - Fixed .env loading order to preserve real credentials over test defaults - Added type guards for undefined workflow IDs - Fixed position arrays to use proper tuple types [number, number] - Added literal types for executionOrder and settings values Test Coverage: - P0: Critical bug verification (FULL vs SHORT node type format) - P1: Base n8n nodes (webhook, HTTP, langchain, multi-node) - P2: Advanced features (connections, settings, expressions, error handling) - Error scenarios (documents actual n8n API validation behavior) - Edge cases (minimal workflows, empty connections, no settings) Technical Improvements: - Cleanup strategy preserves pre-activated webhook workflows - Single webhook URL accepts all HTTP methods (GET, POST, PUT, DELETE) - Environment-aware credential loading with validation - Comprehensive test context for resource tracking All 15 tests passing ✅ TypeScript: 0 errors ✅ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
/**
|
|
* 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,
|
|
timeout: 30000,
|
|
maxRetries: 3
|
|
});
|
|
}
|
|
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;
|
|
}
|
|
}
|