-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Webhook Node): Fix handling of form-data files (#8256)
- Loading branch information
Showing
2 changed files
with
39 additions
and
3 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
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 |
---|---|---|
@@ -1,4 +1,40 @@ | ||
import type { Request } from 'express'; | ||
import type { IWebhookFunctions } from 'n8n-workflow'; | ||
import { mock } from 'jest-mock-extended'; | ||
import { Webhook } from '../Webhook.node'; | ||
import { testWorkflows, getWorkflowFilenames } from '@test/nodes/Helpers'; | ||
|
||
const workflows = getWorkflowFilenames(__dirname); | ||
|
||
describe('Test Webhook Node', () => testWorkflows(workflows)); | ||
describe('Test Webhook Node', () => { | ||
testWorkflows(workflows); | ||
|
||
describe('handleFormData', () => { | ||
const node = new Webhook(); | ||
const context = mock<IWebhookFunctions>({ | ||
nodeHelpers: mock(), | ||
}); | ||
context.getNodeParameter.calledWith('options').mockReturnValue({}); | ||
const req = mock<Request>(); | ||
req.contentType = 'multipart/form-data'; | ||
context.getRequestObject.mockReturnValue(req); | ||
|
||
it('should handle when no files are present', async () => { | ||
req.body = { | ||
files: {}, | ||
}; | ||
const returnData = await node.webhook(context); | ||
expect(returnData.workflowData?.[0][0].binary).toBeUndefined(); | ||
expect(context.nodeHelpers.copyBinaryFile).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should handle when files are present', async () => { | ||
req.body = { | ||
files: { file1: {} }, | ||
}; | ||
const returnData = await node.webhook(context); | ||
expect(returnData.workflowData?.[0][0].binary).not.toBeUndefined(); | ||
expect(context.nodeHelpers.copyBinaryFile).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |