fix: resolve all TypeScript and lint errors in integration tests
- Fixed InMemoryTransport destructuring (object → array) - Updated all callTool calls to new object syntax - Changed getServerInfo() to getServerVersion() - Added type assertions for response objects - Fixed import paths and missing imports - Corrected template and performance test type issues - All 56 TypeScript errors resolved Both 'npm run lint' and 'npm run typecheck' now pass successfully
This commit is contained in:
@@ -5,6 +5,7 @@ import { TemplateRepository } from '../../../src/templates/template-repository';
|
||||
import { DatabaseAdapter } from '../../../src/database/database-adapter';
|
||||
import { TestDatabase, TestDataGenerator, PerformanceMonitor, createTestDatabaseAdapter } from './test-utils';
|
||||
import { ParsedNode } from '../../../src/parsers/node-parser';
|
||||
import { TemplateWorkflow, TemplateDetail } from '../../../src/templates/template-fetcher';
|
||||
|
||||
describe('Database Performance Tests', () => {
|
||||
let testDb: TestDatabase;
|
||||
@@ -152,7 +153,21 @@ describe('Database Performance Tests', () => {
|
||||
|
||||
const stop1 = monitor.start('insert_templates_with_fts');
|
||||
const transaction = db.transaction((templates: any[]) => {
|
||||
templates.forEach(t => templateRepo.saveTemplate(t));
|
||||
templates.forEach(t => {
|
||||
const detail: TemplateDetail = {
|
||||
id: t.id,
|
||||
name: t.name,
|
||||
description: t.description || '',
|
||||
views: t.totalViews,
|
||||
createdAt: t.createdAt,
|
||||
workflow: {
|
||||
nodes: [],
|
||||
connections: {},
|
||||
settings: {}
|
||||
}
|
||||
};
|
||||
templateRepo.saveTemplate(t, detail);
|
||||
});
|
||||
});
|
||||
transaction(templates);
|
||||
stop1();
|
||||
@@ -192,36 +207,53 @@ describe('Database Performance Tests', () => {
|
||||
'n8n-nodes-base.mongodb'
|
||||
];
|
||||
|
||||
const templates = Array.from({ length: 5000 }, (_, i) => ({
|
||||
id: i + 1,
|
||||
name: `Template ${i}`,
|
||||
workflow: {
|
||||
nodes: Array.from({ length: 3 }, (_, j) => ({
|
||||
id: `node${j}`,
|
||||
name: `Node ${j}`,
|
||||
type: nodeTypes[(i + j) % nodeTypes.length],
|
||||
typeVersion: 1,
|
||||
position: [100 * j, 100],
|
||||
parameters: {}
|
||||
})),
|
||||
connections: {},
|
||||
settings: {}
|
||||
},
|
||||
user: { username: 'user' },
|
||||
views: 100,
|
||||
totalViews: 100,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString()
|
||||
}));
|
||||
const templates = Array.from({ length: 5000 }, (_, i) => {
|
||||
const workflow: TemplateWorkflow = {
|
||||
id: i + 1,
|
||||
name: `Template ${i}`,
|
||||
description: `Template description ${i}`,
|
||||
totalViews: 100,
|
||||
createdAt: new Date().toISOString(),
|
||||
user: {
|
||||
id: 1,
|
||||
name: 'Test User',
|
||||
username: 'user',
|
||||
verified: false
|
||||
},
|
||||
nodes: []
|
||||
};
|
||||
|
||||
const detail: TemplateDetail = {
|
||||
id: i + 1,
|
||||
name: `Template ${i}`,
|
||||
description: `Template description ${i}`,
|
||||
views: 100,
|
||||
createdAt: new Date().toISOString(),
|
||||
workflow: {
|
||||
nodes: Array.from({ length: 3 }, (_, j) => ({
|
||||
id: `node${j}`,
|
||||
name: `Node ${j}`,
|
||||
type: nodeTypes[(i + j) % nodeTypes.length],
|
||||
typeVersion: 1,
|
||||
position: [100 * j, 100],
|
||||
parameters: {}
|
||||
})),
|
||||
connections: {},
|
||||
settings: {}
|
||||
}
|
||||
};
|
||||
|
||||
return { workflow, detail };
|
||||
});
|
||||
|
||||
const insertTransaction = db.transaction((templates: any[]) => {
|
||||
templates.forEach(t => templateRepo.saveTemplate(t));
|
||||
const insertTransaction = db.transaction((items: any[]) => {
|
||||
items.forEach(({ workflow, detail }) => templateRepo.saveTemplate(workflow, detail));
|
||||
});
|
||||
insertTransaction(templates);
|
||||
|
||||
// Test searching by node types
|
||||
const stop = monitor.start('search_by_node_types');
|
||||
const results = templateRepo.getTemplatesByNodeTypes([
|
||||
const results = templateRepo.getTemplatesByNodes([
|
||||
'n8n-nodes-base.webhook',
|
||||
'n8n-nodes-base.slack'
|
||||
], 100);
|
||||
@@ -397,7 +429,7 @@ function generateNodes(count: number, startId: number = 0): ParsedNode[] {
|
||||
isWebhook: i % 5 === 0,
|
||||
isVersioned: true,
|
||||
version: '1',
|
||||
documentation: i % 3 === 0 ? `Documentation for node ${i}` : null,
|
||||
documentation: i % 3 === 0 ? `Documentation for node ${i}` : undefined,
|
||||
properties: Array.from({ length: 5 }, (_, j) => ({
|
||||
displayName: `Property ${j}`,
|
||||
name: `prop${j}`,
|
||||
|
||||
@@ -55,38 +55,39 @@ describe('TemplateRepository Integration Tests', () => {
|
||||
|
||||
it('should handle templates with complex node types', () => {
|
||||
const template = createTemplateWorkflow({
|
||||
id: 1,
|
||||
nodes: [
|
||||
{
|
||||
id: 'node1',
|
||||
name: 'Webhook',
|
||||
type: 'n8n-nodes-base.webhook',
|
||||
typeVersion: 1,
|
||||
position: [100, 100],
|
||||
parameters: {}
|
||||
},
|
||||
{
|
||||
id: 'node2',
|
||||
name: 'HTTP Request',
|
||||
type: 'n8n-nodes-base.httpRequest',
|
||||
typeVersion: 3,
|
||||
position: [300, 100],
|
||||
parameters: {
|
||||
url: 'https://api.example.com',
|
||||
method: 'POST'
|
||||
}
|
||||
}
|
||||
]
|
||||
id: 1
|
||||
});
|
||||
|
||||
const nodes = [
|
||||
{
|
||||
id: 'node1',
|
||||
name: 'Webhook',
|
||||
type: 'n8n-nodes-base.webhook',
|
||||
typeVersion: 1,
|
||||
position: [100, 100],
|
||||
parameters: {}
|
||||
},
|
||||
{
|
||||
id: 'node2',
|
||||
name: 'HTTP Request',
|
||||
type: 'n8n-nodes-base.httpRequest',
|
||||
typeVersion: 3,
|
||||
position: [300, 100],
|
||||
parameters: {
|
||||
url: 'https://api.example.com',
|
||||
method: 'POST'
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
const detail = createTemplateDetail({
|
||||
id: template.id,
|
||||
workflow: {
|
||||
id: template.id.toString(),
|
||||
name: template.name,
|
||||
nodes: template.workflow.nodes,
|
||||
connections: template.workflow.connections,
|
||||
settings: template.workflow.settings
|
||||
nodes: nodes,
|
||||
connections: {},
|
||||
settings: {}
|
||||
}
|
||||
});
|
||||
repository.saveTemplate(template, detail);
|
||||
@@ -101,13 +102,7 @@ describe('TemplateRepository Integration Tests', () => {
|
||||
|
||||
it('should sanitize workflow data before saving', () => {
|
||||
const template = createTemplateWorkflow({
|
||||
workflowInfo: {
|
||||
nodeCount: 5,
|
||||
webhookCount: 1,
|
||||
// Add some data that should be sanitized
|
||||
executionId: 'should-be-removed',
|
||||
pinData: { node1: { data: 'sensitive' } }
|
||||
}
|
||||
id: 5
|
||||
});
|
||||
|
||||
const detail = createTemplateDetail({
|
||||
@@ -115,9 +110,20 @@ describe('TemplateRepository Integration Tests', () => {
|
||||
workflow: {
|
||||
id: template.id.toString(),
|
||||
name: template.name,
|
||||
nodes: template.workflow.nodes,
|
||||
connections: template.workflow.connections,
|
||||
settings: template.workflow.settings
|
||||
nodes: [
|
||||
{
|
||||
id: 'node1',
|
||||
name: 'Start',
|
||||
type: 'n8n-nodes-base.start',
|
||||
typeVersion: 1,
|
||||
position: [100, 100],
|
||||
parameters: {}
|
||||
}
|
||||
],
|
||||
connections: {},
|
||||
settings: {},
|
||||
pinData: { node1: { data: 'sensitive' } },
|
||||
executionId: 'should-be-removed'
|
||||
}
|
||||
});
|
||||
repository.saveTemplate(template, detail);
|
||||
@@ -502,9 +508,6 @@ function createTemplateDetail(overrides: any = {}): TemplateDetail {
|
||||
connections: overrides.connections || {},
|
||||
settings: overrides.settings || {},
|
||||
pinData: overrides.pinData
|
||||
},
|
||||
categories: overrides.categories || [
|
||||
{ id: 1, name: 'automation' }
|
||||
]
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import Database from 'better-sqlite3';
|
||||
import { execSync } from 'child_process';
|
||||
import type { DatabaseAdapter } from '../../../src/database/database-adapter';
|
||||
|
||||
export interface TestDatabaseOptions {
|
||||
mode: 'memory' | 'file';
|
||||
@@ -274,7 +275,7 @@ export function checkDatabaseIntegrity(db: Database.Database): {
|
||||
|
||||
try {
|
||||
// Run integrity check
|
||||
const result = db.prepare('PRAGMA integrity_check').all();
|
||||
const result = db.prepare('PRAGMA integrity_check').all() as Array<{ integrity_check: string }>;
|
||||
if (result.length !== 1 || result[0].integrity_check !== 'ok') {
|
||||
errors.push('Database integrity check failed');
|
||||
}
|
||||
@@ -315,10 +316,12 @@ export function createTestDatabaseAdapter(db: Database.Database): DatabaseAdapte
|
||||
get: (...params: any[]) => stmt.get(...params),
|
||||
all: (...params: any[]) => stmt.all(...params),
|
||||
iterate: (...params: any[]) => stmt.iterate(...params),
|
||||
pluck: (enabled?: boolean) => stmt.pluck(enabled),
|
||||
finalize: () => stmt,
|
||||
bind: (...params: any[]) => stmt.bind(...params)
|
||||
};
|
||||
pluck: function(enabled?: boolean) { stmt.pluck(enabled); return this; },
|
||||
expand: function(enabled?: boolean) { stmt.expand?.(enabled); return this; },
|
||||
raw: function(enabled?: boolean) { stmt.raw?.(enabled); return this; },
|
||||
columns: () => stmt.columns?.() || [],
|
||||
bind: function(...params: any[]) { stmt.bind(...params); return this; }
|
||||
} as any;
|
||||
},
|
||||
exec: (sql: string) => db.exec(sql),
|
||||
close: () => db.close(),
|
||||
|
||||
Reference in New Issue
Block a user