-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Adjust starter node priority for manual executions with pi…
…nned activators (#8386)
- Loading branch information
Showing
2 changed files
with
180 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
packages/cli/test/unit/workflow-execution.service.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import type { INode } from 'n8n-workflow'; | ||
import { WorkflowExecutionService } from '@/workflows/workflowExecution.service'; | ||
import type { IWorkflowDb } from '@/Interfaces'; | ||
import { mock } from 'jest-mock-extended'; | ||
|
||
const webhookNode: INode = { | ||
name: 'Webhook', | ||
type: 'n8n-nodes-base.webhook', | ||
id: '111f1db0-e7be-44c5-9ce9-3e35362490f0', | ||
parameters: {}, | ||
typeVersion: 1, | ||
position: [0, 0], | ||
webhookId: 'de0f8dcb-7b64-4f22-b66d-d8f74d6aefb7', | ||
}; | ||
|
||
const secondWebhookNode = { | ||
...webhookNode, | ||
name: 'Webhook 2', | ||
id: '222f1db0-e7be-44c5-9ce9-3e35362490f1', | ||
}; | ||
|
||
const executeWorkflowTriggerNode: INode = { | ||
name: 'Execute Workflow Trigger', | ||
type: 'n8n-nodes-base.executeWorkflowTrigger', | ||
id: '78d63bca-bb6c-4568-948f-8ed9aacb1fe9', | ||
parameters: {}, | ||
typeVersion: 1, | ||
position: [0, 0], | ||
}; | ||
|
||
const respondToWebhookNode: INode = { | ||
name: 'Respond to Webhook', | ||
type: 'n8n-nodes-base.respondToWebhook', | ||
id: '66d63bca-bb6c-4568-948f-8ed9aacb1fe9', | ||
parameters: {}, | ||
typeVersion: 1, | ||
position: [0, 0], | ||
}; | ||
|
||
const hackerNewsNode: INode = { | ||
name: 'Hacker News', | ||
type: 'n8n-nodes-base.hackerNews', | ||
id: '55d63bca-bb6c-4568-948f-8ed9aacb1fe9', | ||
parameters: {}, | ||
typeVersion: 1, | ||
position: [0, 0], | ||
}; | ||
|
||
describe('WorkflowExecutionService', () => { | ||
let workflowExecutionService: WorkflowExecutionService; | ||
|
||
beforeAll(() => { | ||
workflowExecutionService = new WorkflowExecutionService( | ||
mock(), | ||
mock(), | ||
mock(), | ||
mock(), | ||
mock(), | ||
mock(), | ||
); | ||
}); | ||
|
||
describe('selectPinnedActivatorStarter()', () => { | ||
const workflow = mock<IWorkflowDb>({ | ||
nodes: [], | ||
}); | ||
|
||
const pinData = { | ||
[webhookNode.name]: [{ json: { key: 'value' } }], | ||
[executeWorkflowTriggerNode.name]: [{ json: { key: 'value' } }], | ||
}; | ||
|
||
afterEach(() => { | ||
workflow.nodes = []; | ||
}); | ||
|
||
it('should return `null` if no pindata', () => { | ||
const node = workflowExecutionService.selectPinnedActivatorStarter(workflow, []); | ||
|
||
expect(node).toBeNull(); | ||
}); | ||
|
||
it('should return `null` if no starter nodes', () => { | ||
const node = workflowExecutionService.selectPinnedActivatorStarter(workflow); | ||
|
||
expect(node).toBeNull(); | ||
}); | ||
|
||
it('should select webhook node if only choice', () => { | ||
workflow.nodes.push(webhookNode); | ||
|
||
const node = workflowExecutionService.selectPinnedActivatorStarter(workflow, [], pinData); | ||
|
||
expect(node).toEqual(webhookNode); | ||
}); | ||
|
||
it('should return `null` if no choice', () => { | ||
workflow.nodes.push(hackerNewsNode); | ||
|
||
const node = workflowExecutionService.selectPinnedActivatorStarter(workflow, [], pinData); | ||
|
||
expect(node).toBeNull(); | ||
}); | ||
|
||
it('should return ignore Respond to Webhook', () => { | ||
workflow.nodes.push(respondToWebhookNode); | ||
|
||
const node = workflowExecutionService.selectPinnedActivatorStarter(workflow, [], pinData); | ||
|
||
expect(node).toBeNull(); | ||
}); | ||
|
||
it('should select execute workflow trigger if only choice', () => { | ||
workflow.nodes.push(executeWorkflowTriggerNode); | ||
|
||
const node = workflowExecutionService.selectPinnedActivatorStarter(workflow, [], pinData); | ||
|
||
expect(node).toEqual(executeWorkflowTriggerNode); | ||
}); | ||
|
||
it('should favor webhook node over execute workflow trigger', () => { | ||
workflow.nodes.push(webhookNode, executeWorkflowTriggerNode); | ||
|
||
const node = workflowExecutionService.selectPinnedActivatorStarter(workflow, [], pinData); | ||
|
||
expect(node).toEqual(webhookNode); | ||
}); | ||
|
||
it('should favor first webhook node over second webhook node', () => { | ||
workflow.nodes.push(webhookNode, secondWebhookNode); | ||
|
||
const node = workflowExecutionService.selectPinnedActivatorStarter(workflow, [], pinData); | ||
|
||
expect(node).toEqual(webhookNode); | ||
}); | ||
}); | ||
}); |