diff --git a/tests/integration/database/template-node-configs.test.ts b/tests/integration/database/template-node-configs.test.ts index fa547a3..4d5b55f 100644 --- a/tests/integration/database/template-node-configs.test.ts +++ b/tests/integration/database/template-node-configs.test.ts @@ -27,6 +27,18 @@ describe('Template Node Configs Database Integration', () => { const migrationPath = path.join(__dirname, '../../../src/database/migrations/add-template-node-configs.sql'); const migration = fs.readFileSync(migrationPath, 'utf-8'); db.exec(migration); + + // Insert test templates with id 1-1000 to satisfy foreign key constraints + // Tests insert configs with various template_id values, so we pre-create many templates + const stmt = db.prepare(` + INSERT INTO templates ( + id, workflow_id, name, description, views, + nodes_used, created_at, updated_at + ) VALUES (?, ?, ?, ?, ?, ?, datetime('now'), datetime('now')) + `); + for (let i = 1; i <= 1000; i++) { + stmt.run(i, i, `Test Template ${i}`, 'Test template for node configs', 100, '[]'); + } }); afterEach(() => { @@ -242,14 +254,7 @@ describe('Template Node Configs Database Integration', () => { beforeEach(() => { // Enable foreign keys db.exec('PRAGMA foreign_keys = ON'); - - // Create a template first - db.prepare(` - INSERT INTO templates ( - id, workflow_id, name, description, views, - nodes_used, created_at, updated_at - ) VALUES (?, ?, ?, ?, ?, ?, datetime('now'), datetime('now')) - `).run(1, 100, 'Test Template', 'Description', 500, '[]'); + // Note: Templates are already created in the main beforeEach }); it('should allow inserting config with valid template_id', () => { diff --git a/tests/integration/mcp-protocol/session-management.test.ts b/tests/integration/mcp-protocol/session-management.test.ts index 1a1fcda..d2778bd 100644 --- a/tests/integration/mcp-protocol/session-management.test.ts +++ b/tests/integration/mcp-protocol/session-management.test.ts @@ -483,10 +483,11 @@ describe('MCP Session Management', { timeout: 15000 }, () => { await client.connect(clientTransport); // Multiple error-inducing requests + // Note: get_node_for_task was removed in v2.15.0 const errorPromises = [ client.callTool({ name: 'get_node_info', arguments: { nodeType: 'invalid1' } }).catch(e => e), client.callTool({ name: 'get_node_info', arguments: { nodeType: 'invalid2' } }).catch(e => e), - client.callTool({ name: 'get_node_for_task', arguments: { task: 'invalid_task' } }).catch(e => e) + client.callTool({ name: 'search_nodes', arguments: { query: '' } }).catch(e => e) // Empty query should error ]; const errors = await Promise.all(errorPromises); diff --git a/tests/integration/mcp-protocol/tool-invocation.test.ts b/tests/integration/mcp-protocol/tool-invocation.test.ts index 6e6840f..ce1ba48 100644 --- a/tests/integration/mcp-protocol/tool-invocation.test.ts +++ b/tests/integration/mcp-protocol/tool-invocation.test.ts @@ -459,30 +459,8 @@ describe('MCP Tool Invocation', () => { }); describe('Task Templates', () => { - describe('get_node_for_task', () => { - it('should return pre-configured node for task', async () => { - const response = await client.callTool({ name: 'get_node_for_task', arguments: { - task: 'post_json_request' - }}); - - const config = JSON.parse(((response as any).content[0]).text); - expect(config).toHaveProperty('task'); - expect(config).toHaveProperty('nodeType'); - expect(config).toHaveProperty('configuration'); - expect(config.configuration.method).toBe('POST'); - }); - - it('should handle unknown tasks', async () => { - try { - await client.callTool({ name: 'get_node_for_task', arguments: { - task: 'unknown_task' - }}); - expect.fail('Should have thrown an error'); - } catch (error: any) { - expect(error.message).toContain('Unknown task'); - } - }); - }); + // get_node_for_task was removed in v2.15.0 + // Use search_nodes({ includeExamples: true }) instead for real-world examples describe('list_tasks', () => { it('should list all available tasks', async () => { diff --git a/tests/integration/mcp/template-examples-e2e.test.ts b/tests/integration/mcp/template-examples-e2e.test.ts index dc7e8b4..d7b3428 100644 --- a/tests/integration/mcp/template-examples-e2e.test.ts +++ b/tests/integration/mcp/template-examples-e2e.test.ts @@ -37,20 +37,24 @@ describe('Template Examples E2E Integration', () => { }); function seedTemplateConfigs() { - // Insert sample template first - db.prepare(` - INSERT INTO templates ( - id, workflow_id, name, description, views, - nodes_used, created_at, updated_at - ) VALUES (?, ?, ?, ?, ?, ?, datetime('now'), datetime('now')) - `).run( - 1, - 1, - 'Test Template', - 'Test Description', - 1000, - JSON.stringify(['n8n-nodes-base.webhook', 'n8n-nodes-base.httpRequest']) - ); + // Insert sample templates first to satisfy foreign key constraints + // The sampleConfigs use template_id 1-4, edge cases use 998-999 + const templateIds = [1, 2, 3, 4, 998, 999]; + for (const id of templateIds) { + db.prepare(` + INSERT INTO templates ( + id, workflow_id, name, description, views, + nodes_used, created_at, updated_at + ) VALUES (?, ?, ?, ?, ?, ?, datetime('now'), datetime('now')) + `).run( + id, + id, + `Test Template ${id}`, + 'Test Description', + 1000, + JSON.stringify(['n8n-nodes-base.webhook', 'n8n-nodes-base.httpRequest']) + ); + } // Insert webhook configs db.prepare(` @@ -189,8 +193,19 @@ describe('Template Examples E2E Integration', () => { describe('Ranked View Functionality', () => { it('should return only top 5 ranked configs per node type from view', () => { + // Insert templates first to satisfy foreign key constraints + // Note: seedTemplateConfigs already created templates 1-4, so start from 5 + for (let i = 5; i <= 14; i++) { + db.prepare(` + INSERT INTO templates ( + id, workflow_id, name, description, views, + nodes_used, created_at, updated_at + ) VALUES (?, ?, ?, ?, ?, ?, datetime('now'), datetime('now')) + `).run(i, i, `Template ${i}`, 'Test', 1000 - (i * 50), '[]'); + } + // Insert 10 configs for same node type - for (let i = 3; i <= 12; i++) { + for (let i = 5; i <= 14; i++) { db.prepare(` INSERT INTO template_node_configs ( node_type, template_id, template_name, template_views, @@ -218,6 +233,16 @@ describe('Template Examples E2E Integration', () => { describe('Performance with Real-World Data Volume', () => { beforeEach(() => { + // Insert templates first to satisfy foreign key constraints + for (let i = 1; i <= 100; i++) { + db.prepare(` + INSERT INTO templates ( + id, workflow_id, name, description, views, + nodes_used, created_at, updated_at + ) VALUES (?, ?, ?, ?, ?, ?, datetime('now'), datetime('now')) + `).run(i + 100, i + 100, `Template ${i}`, 'Test', Math.floor(Math.random() * 10000), '[]'); + } + // Insert 100 configs across 10 different node types const nodeTypes = [ 'n8n-nodes-base.slack', @@ -389,13 +414,13 @@ describe('Template Examples E2E Integration', () => { it('should cascade delete configs when template is deleted', () => { db.exec('PRAGMA foreign_keys = ON'); - // Insert a template and config + // Insert a new template (use id 1000 to avoid conflicts with seedTemplateConfigs) db.prepare(` INSERT INTO templates ( id, workflow_id, name, description, views, nodes_used, created_at, updated_at ) VALUES (?, ?, ?, ?, ?, ?, datetime('now'), datetime('now')) - `).run(2, 2, 'Test Template 2', 'Desc', 100, '[]'); + `).run(1000, 1000, 'Test Template 1000', 'Desc', 100, '[]'); db.prepare(` INSERT INTO template_node_configs ( @@ -404,7 +429,7 @@ describe('Template Examples E2E Integration', () => { ) VALUES (?, ?, ?, ?, ?, ?, ?) `).run( 'n8n-nodes-base.test', - 2, + 1000, 'Test', 100, 'Node', @@ -413,14 +438,14 @@ describe('Template Examples E2E Integration', () => { ); // Verify config exists - let config = db.prepare('SELECT * FROM template_node_configs WHERE template_id = ?').get(2); + let config = db.prepare('SELECT * FROM template_node_configs WHERE template_id = ?').get(1000); expect(config).toBeDefined(); // Delete template - db.prepare('DELETE FROM templates WHERE id = ?').run(2); + db.prepare('DELETE FROM templates WHERE id = ?').run(1000); // Verify config is deleted (CASCADE) - config = db.prepare('SELECT * FROM template_node_configs WHERE template_id = ?').get(2); + config = db.prepare('SELECT * FROM template_node_configs WHERE template_id = ?').get(1000); expect(config).toBeUndefined(); }); });