mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-02-06 13:33:11 +00:00
feat(tests): implement Phase 2 integration testing - workflow creation tests
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>
This commit is contained in:
@@ -62,13 +62,22 @@ export async function cleanupOrphanedWorkflows(): Promise<string[]> {
|
||||
throw error;
|
||||
}
|
||||
|
||||
// Find test workflows
|
||||
const testWorkflows = allWorkflows.filter(w =>
|
||||
w.tags?.includes(creds.cleanup.tag) ||
|
||||
w.name?.startsWith(creds.cleanup.namePrefix)
|
||||
);
|
||||
// Pre-activated webhook workflow that should NOT be deleted
|
||||
// This is needed for webhook trigger integration tests
|
||||
// Note: Single webhook accepts all HTTP methods (GET, POST, PUT, DELETE)
|
||||
const preservedWorkflowNames = new Set([
|
||||
'[MCP-TEST] Webhook All Methods'
|
||||
]);
|
||||
|
||||
logger.info(`Found ${testWorkflows.length} orphaned test workflow(s)`);
|
||||
// Find test workflows but exclude pre-activated webhook workflows
|
||||
const testWorkflows = allWorkflows.filter(w => {
|
||||
const isTestWorkflow = w.tags?.includes(creds.cleanup.tag) || w.name?.startsWith(creds.cleanup.namePrefix);
|
||||
const isPreserved = preservedWorkflowNames.has(w.name);
|
||||
|
||||
return isTestWorkflow && !isPreserved;
|
||||
});
|
||||
|
||||
logger.info(`Found ${testWorkflows.length} orphaned test workflow(s) (excluding ${preservedWorkflowNames.size} preserved webhook workflow)`);
|
||||
|
||||
if (testWorkflows.length === 0) {
|
||||
return deleted;
|
||||
|
||||
@@ -15,7 +15,7 @@ dotenv.config({ path: path.resolve(process.cwd(), '.env') });
|
||||
export interface N8nTestCredentials {
|
||||
url: string;
|
||||
apiKey: string;
|
||||
webhookWorkflows: {
|
||||
webhookUrls: {
|
||||
get: string;
|
||||
post: string;
|
||||
put: string;
|
||||
@@ -55,11 +55,11 @@ export function getN8nCredentials(): N8nTestCredentials {
|
||||
return {
|
||||
url,
|
||||
apiKey,
|
||||
webhookWorkflows: {
|
||||
get: process.env.N8N_TEST_WEBHOOK_GET_ID || '',
|
||||
post: process.env.N8N_TEST_WEBHOOK_POST_ID || '',
|
||||
put: process.env.N8N_TEST_WEBHOOK_PUT_ID || '',
|
||||
delete: process.env.N8N_TEST_WEBHOOK_DELETE_ID || ''
|
||||
webhookUrls: {
|
||||
get: process.env.N8N_TEST_WEBHOOK_GET_URL || '',
|
||||
post: process.env.N8N_TEST_WEBHOOK_POST_URL || '',
|
||||
put: process.env.N8N_TEST_WEBHOOK_PUT_URL || '',
|
||||
delete: process.env.N8N_TEST_WEBHOOK_DELETE_URL || ''
|
||||
},
|
||||
cleanup: {
|
||||
enabled: true,
|
||||
@@ -85,11 +85,11 @@ export function getN8nCredentials(): N8nTestCredentials {
|
||||
return {
|
||||
url,
|
||||
apiKey,
|
||||
webhookWorkflows: {
|
||||
get: process.env.N8N_TEST_WEBHOOK_GET_ID || '',
|
||||
post: process.env.N8N_TEST_WEBHOOK_POST_ID || '',
|
||||
put: process.env.N8N_TEST_WEBHOOK_PUT_ID || '',
|
||||
delete: process.env.N8N_TEST_WEBHOOK_DELETE_ID || ''
|
||||
webhookUrls: {
|
||||
get: process.env.N8N_TEST_WEBHOOK_GET_URL || '',
|
||||
post: process.env.N8N_TEST_WEBHOOK_POST_URL || '',
|
||||
put: process.env.N8N_TEST_WEBHOOK_PUT_URL || '',
|
||||
delete: process.env.N8N_TEST_WEBHOOK_DELETE_URL || ''
|
||||
},
|
||||
cleanup: {
|
||||
enabled: process.env.N8N_TEST_CLEANUP_ENABLED !== 'false',
|
||||
@@ -127,24 +127,24 @@ export function validateCredentials(creds: N8nTestCredentials): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that webhook workflow IDs are configured
|
||||
* Validate that webhook URLs are configured
|
||||
*
|
||||
* @param creds - Credentials to validate
|
||||
* @throws Error with setup instructions if webhook workflows are missing
|
||||
* @throws Error with setup instructions if webhook URLs are missing
|
||||
*/
|
||||
export function validateWebhookWorkflows(creds: N8nTestCredentials): void {
|
||||
export function validateWebhookUrls(creds: N8nTestCredentials): void {
|
||||
const missing: string[] = [];
|
||||
|
||||
if (!creds.webhookWorkflows.get) missing.push('GET');
|
||||
if (!creds.webhookWorkflows.post) missing.push('POST');
|
||||
if (!creds.webhookWorkflows.put) missing.push('PUT');
|
||||
if (!creds.webhookWorkflows.delete) missing.push('DELETE');
|
||||
if (!creds.webhookUrls.get) missing.push('GET');
|
||||
if (!creds.webhookUrls.post) missing.push('POST');
|
||||
if (!creds.webhookUrls.put) missing.push('PUT');
|
||||
if (!creds.webhookUrls.delete) missing.push('DELETE');
|
||||
|
||||
if (missing.length > 0) {
|
||||
const envVars = missing.map(m => `N8N_TEST_WEBHOOK_${m}_ID`);
|
||||
const envVars = missing.map(m => `N8N_TEST_WEBHOOK_${m}_URL`);
|
||||
|
||||
throw new Error(
|
||||
`Missing webhook workflow IDs for HTTP methods: ${missing.join(', ')}\n\n` +
|
||||
`Missing webhook URLs for HTTP methods: ${missing.join(', ')}\n\n` +
|
||||
`Webhook testing requires pre-activated workflows in n8n.\n` +
|
||||
`n8n API doesn't support workflow activation, so these must be created manually.\n\n` +
|
||||
`Setup Instructions:\n` +
|
||||
@@ -153,8 +153,9 @@ export function validateWebhookWorkflows(creds: N8nTestCredentials): void {
|
||||
`3. Configure webhook paths:\n` +
|
||||
missing.map(m => ` - ${m}: mcp-test-${m.toLowerCase()}`).join('\n') + '\n' +
|
||||
`4. ACTIVATE each workflow in n8n UI\n` +
|
||||
`5. Set the following environment variables with workflow IDs:\n` +
|
||||
envVars.map(v => ` ${v}=<workflow-id>`).join('\n') + '\n\n' +
|
||||
`5. Set the following environment variables with full webhook URLs:\n` +
|
||||
envVars.map(v => ` ${v}=<full-webhook-url>`).join('\n') + '\n\n' +
|
||||
`Example: N8N_TEST_WEBHOOK_GET_URL=https://n8n-test.n8n-mcp.com/webhook/mcp-test-get\n\n` +
|
||||
`See docs/local/integration-testing-plan.md for detailed instructions.`
|
||||
);
|
||||
}
|
||||
@@ -175,18 +176,18 @@ export function hasCredentials(): boolean {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if webhook workflows are configured (non-throwing version)
|
||||
* Check if webhook URLs are configured (non-throwing version)
|
||||
*
|
||||
* @returns true if all webhook workflow IDs are available
|
||||
* @returns true if all webhook URLs are available
|
||||
*/
|
||||
export function hasWebhookWorkflows(): boolean {
|
||||
export function hasWebhookUrls(): boolean {
|
||||
try {
|
||||
const creds = getN8nCredentials();
|
||||
return !!(
|
||||
creds.webhookWorkflows.get &&
|
||||
creds.webhookWorkflows.post &&
|
||||
creds.webhookWorkflows.put &&
|
||||
creds.webhookWorkflows.delete
|
||||
creds.webhookUrls.get &&
|
||||
creds.webhookUrls.post &&
|
||||
creds.webhookUrls.put &&
|
||||
creds.webhookUrls.delete
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
|
||||
@@ -29,7 +29,9 @@ export function getTestN8nClient(): N8nApiClient {
|
||||
validateCredentials(creds);
|
||||
client = new N8nApiClient({
|
||||
baseUrl: creds.url,
|
||||
apiKey: creds.apiKey
|
||||
apiKey: creds.apiKey,
|
||||
timeout: 30000,
|
||||
maxRetries: 3
|
||||
});
|
||||
}
|
||||
return client;
|
||||
|
||||
Reference in New Issue
Block a user