Files
n8n-mcp/tests/integration/n8n-api/scripts/cleanup-orphans.ts
czlonkowski 2305aaab9e 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>
2025-10-03 13:12:42 +02:00

44 lines
1.2 KiB
TypeScript

#!/usr/bin/env tsx
/**
* Cleanup Orphaned Test Resources
*
* Standalone script to clean up orphaned workflows and executions
* from failed test runs. Run this periodically in CI or manually
* to maintain a clean test environment.
*
* Usage:
* npm run test:cleanup:orphans
* tsx tests/integration/n8n-api/scripts/cleanup-orphans.ts
*/
import { cleanupAllTestResources } from '../utils/cleanup-helpers';
import { getN8nCredentials, validateCredentials } from '../utils/credentials';
async function main() {
console.log('Starting cleanup of orphaned test resources...\n');
try {
// Validate credentials
const creds = getN8nCredentials();
validateCredentials(creds);
console.log(`n8n Instance: ${creds.url}`);
console.log(`Cleanup Tag: ${creds.cleanup.tag}`);
console.log(`Cleanup Prefix: ${creds.cleanup.namePrefix}\n`);
// Run cleanup
const result = await cleanupAllTestResources();
console.log('\n✅ Cleanup complete!');
console.log(` Workflows deleted: ${result.workflows}`);
console.log(` Executions deleted: ${result.executions}`);
process.exit(0);
} catch (error) {
console.error('\n❌ Cleanup failed:', error);
process.exit(1);
}
}
main();