forked from n8n-io/n8n
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Validate node name when creating
NodeOperationErrror
(n8…
- Loading branch information
Showing
3 changed files
with
58 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { mock } from 'jest-mock-extended'; | ||
import type { INode } from 'n8n-workflow'; | ||
import { NodeOperationError, type Workflow } from 'n8n-workflow'; | ||
|
||
import { objectToError } from '../workflow-execute-additional-data'; | ||
|
||
describe('objectToError', () => { | ||
describe('node error handling', () => { | ||
it('should create `NodeOperationError` when node is found', () => { | ||
const errorObject = { | ||
message: 'Test error', | ||
node: { | ||
name: 'testNode', | ||
}, | ||
}; | ||
const workflow = mock<Workflow>(); | ||
const node = mock<INode>(); | ||
workflow.getNode.mockReturnValue(node); | ||
|
||
const result = objectToError(errorObject, workflow); | ||
|
||
expect(workflow.getNode).toHaveBeenCalledWith('testNode'); | ||
expect(result).toBeInstanceOf(NodeOperationError); | ||
}); | ||
|
||
it('should create `Error` when node is not found', () => { | ||
const errorObject = { | ||
message: 'Test error', | ||
node: { | ||
// missing `name` | ||
}, | ||
}; | ||
const workflow = mock<Workflow>(); | ||
|
||
const result = objectToError(errorObject, workflow); | ||
|
||
expect(workflow.getNode).not.toHaveBeenCalled(); | ||
expect(result).toBeInstanceOf(Error); | ||
expect(result).not.toBeInstanceOf(NodeOperationError); | ||
expect(result.message).toBe('Test error'); | ||
}); | ||
}); | ||
}); |
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
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