test: add Phase 4 database integration tests (partial)
- Add comprehensive test utilities for database testing - Implement connection management tests for in-memory and file databases - Add transaction tests including nested transactions and savepoints - Test database lifecycle, error handling, and performance - Include tests for WAL mode, connection pooling, and constraints Part of Phase 4: Integration Testing
This commit is contained in:
49
tests/mocks/n8n-api/data/credentials.ts
Normal file
49
tests/mocks/n8n-api/data/credentials.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Mock credential data for MSW handlers
|
||||
*/
|
||||
|
||||
export interface MockCredential {
|
||||
id: string;
|
||||
name: string;
|
||||
type: string;
|
||||
data?: Record<string, any>; // Usually encrypted in real n8n
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export const mockCredentials: MockCredential[] = [
|
||||
{
|
||||
id: 'cred_1',
|
||||
name: 'Slack Account',
|
||||
type: 'slackApi',
|
||||
createdAt: '2024-01-01T00:00:00.000Z',
|
||||
updatedAt: '2024-01-01T00:00:00.000Z'
|
||||
},
|
||||
{
|
||||
id: 'cred_2',
|
||||
name: 'HTTP Header Auth',
|
||||
type: 'httpHeaderAuth',
|
||||
createdAt: '2024-01-01T00:00:00.000Z',
|
||||
updatedAt: '2024-01-01T00:00:00.000Z'
|
||||
},
|
||||
{
|
||||
id: 'cred_3',
|
||||
name: 'OpenAI API',
|
||||
type: 'openAiApi',
|
||||
createdAt: '2024-01-01T00:00:00.000Z',
|
||||
updatedAt: '2024-01-01T00:00:00.000Z'
|
||||
}
|
||||
];
|
||||
|
||||
/**
|
||||
* Factory for creating mock credentials
|
||||
*/
|
||||
export const credentialFactory = {
|
||||
create: (type: string, name?: string): MockCredential => ({
|
||||
id: `cred_${Date.now()}`,
|
||||
name: name || `${type} Credential`,
|
||||
type,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString()
|
||||
})
|
||||
};
|
||||
159
tests/mocks/n8n-api/data/executions.ts
Normal file
159
tests/mocks/n8n-api/data/executions.ts
Normal file
@@ -0,0 +1,159 @@
|
||||
/**
|
||||
* Mock execution data for MSW handlers
|
||||
*/
|
||||
|
||||
export interface MockExecution {
|
||||
id: string;
|
||||
workflowId: string;
|
||||
status: 'success' | 'error' | 'waiting' | 'running';
|
||||
mode: 'manual' | 'trigger' | 'webhook' | 'internal';
|
||||
startedAt: string;
|
||||
stoppedAt?: string;
|
||||
data?: any;
|
||||
error?: any;
|
||||
}
|
||||
|
||||
export const mockExecutions: MockExecution[] = [
|
||||
{
|
||||
id: 'exec_1',
|
||||
workflowId: 'workflow_1',
|
||||
status: 'success',
|
||||
mode: 'manual',
|
||||
startedAt: '2024-01-01T10:00:00.000Z',
|
||||
stoppedAt: '2024-01-01T10:00:05.000Z',
|
||||
data: {
|
||||
resultData: {
|
||||
runData: {
|
||||
'node_2': [
|
||||
{
|
||||
startTime: 1704106800000,
|
||||
executionTime: 234,
|
||||
data: {
|
||||
main: [[{
|
||||
json: {
|
||||
status: 200,
|
||||
data: { message: 'Success' }
|
||||
}
|
||||
}]]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'exec_2',
|
||||
workflowId: 'workflow_2',
|
||||
status: 'error',
|
||||
mode: 'webhook',
|
||||
startedAt: '2024-01-01T11:00:00.000Z',
|
||||
stoppedAt: '2024-01-01T11:00:02.000Z',
|
||||
error: {
|
||||
message: 'Could not send message to Slack',
|
||||
stack: 'Error: Could not send message to Slack\n at SlackNode.execute',
|
||||
node: 'slack_1'
|
||||
},
|
||||
data: {
|
||||
resultData: {
|
||||
runData: {
|
||||
'webhook_1': [
|
||||
{
|
||||
startTime: 1704110400000,
|
||||
executionTime: 10,
|
||||
data: {
|
||||
main: [[{
|
||||
json: {
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: { message: 'Test webhook' }
|
||||
}
|
||||
}]]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'exec_3',
|
||||
workflowId: 'workflow_3',
|
||||
status: 'waiting',
|
||||
mode: 'trigger',
|
||||
startedAt: '2024-01-01T12:00:00.000Z',
|
||||
data: {
|
||||
resultData: {
|
||||
runData: {}
|
||||
},
|
||||
waitingExecutions: {
|
||||
'agent_1': {
|
||||
reason: 'Waiting for user input'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
/**
|
||||
* Factory functions for creating mock executions
|
||||
*/
|
||||
export const executionFactory = {
|
||||
/**
|
||||
* Create a successful execution
|
||||
*/
|
||||
success: (workflowId: string, data?: any): MockExecution => ({
|
||||
id: `exec_${Date.now()}`,
|
||||
workflowId,
|
||||
status: 'success',
|
||||
mode: 'manual',
|
||||
startedAt: new Date().toISOString(),
|
||||
stoppedAt: new Date(Date.now() + 5000).toISOString(),
|
||||
data: data || {
|
||||
resultData: {
|
||||
runData: {
|
||||
'node_1': [{
|
||||
startTime: Date.now(),
|
||||
executionTime: 100,
|
||||
data: {
|
||||
main: [[{ json: { success: true } }]]
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
/**
|
||||
* Create a failed execution
|
||||
*/
|
||||
error: (workflowId: string, error: { message: string; node?: string }): MockExecution => ({
|
||||
id: `exec_${Date.now()}`,
|
||||
workflowId,
|
||||
status: 'error',
|
||||
mode: 'manual',
|
||||
startedAt: new Date().toISOString(),
|
||||
stoppedAt: new Date(Date.now() + 2000).toISOString(),
|
||||
error: {
|
||||
message: error.message,
|
||||
stack: `Error: ${error.message}\n at Node.execute`,
|
||||
node: error.node
|
||||
},
|
||||
data: {
|
||||
resultData: {
|
||||
runData: {}
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
/**
|
||||
* Create a custom execution
|
||||
*/
|
||||
custom: (config: Partial<MockExecution>): MockExecution => ({
|
||||
id: `exec_${Date.now()}`,
|
||||
workflowId: 'workflow_1',
|
||||
status: 'success',
|
||||
mode: 'manual',
|
||||
startedAt: new Date().toISOString(),
|
||||
...config
|
||||
})
|
||||
};
|
||||
219
tests/mocks/n8n-api/data/workflows.ts
Normal file
219
tests/mocks/n8n-api/data/workflows.ts
Normal file
@@ -0,0 +1,219 @@
|
||||
/**
|
||||
* Mock workflow data for MSW handlers
|
||||
* These represent typical n8n workflows used in tests
|
||||
*/
|
||||
|
||||
export interface MockWorkflow {
|
||||
id: string;
|
||||
name: string;
|
||||
active: boolean;
|
||||
nodes: any[];
|
||||
connections: any;
|
||||
settings?: any;
|
||||
tags?: string[];
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
versionId: string;
|
||||
}
|
||||
|
||||
export const mockWorkflows: MockWorkflow[] = [
|
||||
{
|
||||
id: 'workflow_1',
|
||||
name: 'Test HTTP Workflow',
|
||||
active: true,
|
||||
nodes: [
|
||||
{
|
||||
id: 'node_1',
|
||||
name: 'Start',
|
||||
type: 'n8n-nodes-base.start',
|
||||
typeVersion: 1,
|
||||
position: [250, 300],
|
||||
parameters: {}
|
||||
},
|
||||
{
|
||||
id: 'node_2',
|
||||
name: 'HTTP Request',
|
||||
type: 'n8n-nodes-base.httpRequest',
|
||||
typeVersion: 4.2,
|
||||
position: [450, 300],
|
||||
parameters: {
|
||||
method: 'GET',
|
||||
url: 'https://api.example.com/data',
|
||||
authentication: 'none',
|
||||
options: {}
|
||||
}
|
||||
}
|
||||
],
|
||||
connections: {
|
||||
'node_1': {
|
||||
main: [[{ node: 'node_2', type: 'main', index: 0 }]]
|
||||
}
|
||||
},
|
||||
settings: {
|
||||
executionOrder: 'v1',
|
||||
timezone: 'UTC'
|
||||
},
|
||||
tags: ['http', 'api'],
|
||||
createdAt: '2024-01-01T00:00:00.000Z',
|
||||
updatedAt: '2024-01-01T00:00:00.000Z',
|
||||
versionId: '1'
|
||||
},
|
||||
{
|
||||
id: 'workflow_2',
|
||||
name: 'Webhook to Slack',
|
||||
active: false,
|
||||
nodes: [
|
||||
{
|
||||
id: 'webhook_1',
|
||||
name: 'Webhook',
|
||||
type: 'n8n-nodes-base.webhook',
|
||||
typeVersion: 2,
|
||||
position: [250, 300],
|
||||
parameters: {
|
||||
httpMethod: 'POST',
|
||||
path: 'test-webhook',
|
||||
responseMode: 'onReceived',
|
||||
responseData: 'firstEntryJson'
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'slack_1',
|
||||
name: 'Slack',
|
||||
type: 'n8n-nodes-base.slack',
|
||||
typeVersion: 2.2,
|
||||
position: [450, 300],
|
||||
parameters: {
|
||||
resource: 'message',
|
||||
operation: 'post',
|
||||
channel: '#general',
|
||||
text: '={{ $json.message }}',
|
||||
authentication: 'accessToken'
|
||||
},
|
||||
credentials: {
|
||||
slackApi: {
|
||||
id: 'cred_1',
|
||||
name: 'Slack Account'
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
connections: {
|
||||
'webhook_1': {
|
||||
main: [[{ node: 'slack_1', type: 'main', index: 0 }]]
|
||||
}
|
||||
},
|
||||
settings: {},
|
||||
tags: ['webhook', 'slack', 'notification'],
|
||||
createdAt: '2024-01-02T00:00:00.000Z',
|
||||
updatedAt: '2024-01-02T00:00:00.000Z',
|
||||
versionId: '1'
|
||||
},
|
||||
{
|
||||
id: 'workflow_3',
|
||||
name: 'AI Agent Workflow',
|
||||
active: true,
|
||||
nodes: [
|
||||
{
|
||||
id: 'agent_1',
|
||||
name: 'AI Agent',
|
||||
type: '@n8n/n8n-nodes-langchain.agent',
|
||||
typeVersion: 1.7,
|
||||
position: [250, 300],
|
||||
parameters: {
|
||||
agent: 'openAiFunctionsAgent',
|
||||
prompt: 'You are a helpful assistant',
|
||||
temperature: 0.7
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'tool_1',
|
||||
name: 'HTTP Tool',
|
||||
type: 'n8n-nodes-base.httpRequest',
|
||||
typeVersion: 4.2,
|
||||
position: [450, 200],
|
||||
parameters: {
|
||||
method: 'GET',
|
||||
url: 'https://api.example.com/search',
|
||||
sendQuery: true,
|
||||
queryParameters: {
|
||||
parameters: [
|
||||
{
|
||||
name: 'q',
|
||||
value: '={{ $json.query }}'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
connections: {
|
||||
'tool_1': {
|
||||
ai_tool: [[{ node: 'agent_1', type: 'ai_tool', index: 0 }]]
|
||||
}
|
||||
},
|
||||
settings: {},
|
||||
tags: ['ai', 'agent', 'langchain'],
|
||||
createdAt: '2024-01-03T00:00:00.000Z',
|
||||
updatedAt: '2024-01-03T00:00:00.000Z',
|
||||
versionId: '1'
|
||||
}
|
||||
];
|
||||
|
||||
/**
|
||||
* Factory functions for creating mock workflows
|
||||
*/
|
||||
export const workflowFactory = {
|
||||
/**
|
||||
* Create a simple workflow with Start and one other node
|
||||
*/
|
||||
simple: (nodeType: string, nodeParams: any = {}): MockWorkflow => ({
|
||||
id: `workflow_${Date.now()}`,
|
||||
name: `Test ${nodeType} Workflow`,
|
||||
active: true,
|
||||
nodes: [
|
||||
{
|
||||
id: 'start_1',
|
||||
name: 'Start',
|
||||
type: 'n8n-nodes-base.start',
|
||||
typeVersion: 1,
|
||||
position: [250, 300],
|
||||
parameters: {}
|
||||
},
|
||||
{
|
||||
id: 'node_1',
|
||||
name: nodeType.split('.').pop() || nodeType,
|
||||
type: nodeType,
|
||||
typeVersion: 1,
|
||||
position: [450, 300],
|
||||
parameters: nodeParams
|
||||
}
|
||||
],
|
||||
connections: {
|
||||
'start_1': {
|
||||
main: [[{ node: 'node_1', type: 'main', index: 0 }]]
|
||||
}
|
||||
},
|
||||
settings: {},
|
||||
tags: [],
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
versionId: '1'
|
||||
}),
|
||||
|
||||
/**
|
||||
* Create a workflow with specific nodes and connections
|
||||
*/
|
||||
custom: (config: Partial<MockWorkflow>): MockWorkflow => ({
|
||||
id: `workflow_${Date.now()}`,
|
||||
name: 'Custom Workflow',
|
||||
active: false,
|
||||
nodes: [],
|
||||
connections: {},
|
||||
settings: {},
|
||||
tags: [],
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
versionId: '1',
|
||||
...config
|
||||
})
|
||||
};
|
||||
Reference in New Issue
Block a user