mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(Webhook Node): Fix handling of form-data files (#8256)
This commit is contained in:
parent
b6c42cc084
commit
fc2903096e
|
@ -99,7 +99,7 @@ export class Webhook extends Node {
|
||||||
const options = context.getNodeParameter('options', {}) as {
|
const options = context.getNodeParameter('options', {}) as {
|
||||||
binaryData: boolean;
|
binaryData: boolean;
|
||||||
ignoreBots: boolean;
|
ignoreBots: boolean;
|
||||||
rawBody: Buffer;
|
rawBody: boolean;
|
||||||
responseData?: string;
|
responseData?: string;
|
||||||
};
|
};
|
||||||
const req = context.getRequestObject();
|
const req = context.getRequestObject();
|
||||||
|
@ -225,7 +225,7 @@ export class Webhook extends Node {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (files?.length) {
|
if (files && Object.keys(files).length) {
|
||||||
returnItem.binary = {};
|
returnItem.binary = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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';
|
import { testWorkflows, getWorkflowFilenames } from '@test/nodes/Helpers';
|
||||||
|
|
||||||
const workflows = getWorkflowFilenames(__dirname);
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue