mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 02:21:13 +00:00
fix(n8n Form Node): Use binary response from latest node in execution (#14842)
This commit is contained in:
@@ -19,9 +19,9 @@ export const binaryResponse = async (
|
||||
): Promise<{ data: string | Buffer; fileName: string; type: string }> => {
|
||||
const inputDataFieldName = context.getNodeParameter('inputDataFieldName', '') as string;
|
||||
const parentNodes = context.getParentNodes(context.getNode().name);
|
||||
const binaryNode = parentNodes.find((node) =>
|
||||
getBinaryDataFromNode(context, node?.name)?.hasOwnProperty(inputDataFieldName),
|
||||
);
|
||||
const binaryNode = parentNodes
|
||||
.reverse()
|
||||
.find((node) => getBinaryDataFromNode(context, node?.name)?.hasOwnProperty(inputDataFieldName));
|
||||
if (!binaryNode) {
|
||||
throw new OperationalError(`No binary data with field ${inputDataFieldName} found.`);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { type Response } from 'express';
|
||||
import { type MockProxy, mock } from 'jest-mock-extended';
|
||||
import { type INode, type IWebhookFunctions } from 'n8n-workflow';
|
||||
|
||||
import { renderFormCompletion } from '../formCompletionUtils';
|
||||
import { binaryResponse, renderFormCompletion } from '../formCompletionUtils';
|
||||
|
||||
describe('formCompletionUtils', () => {
|
||||
let mockWebhookFunctions: MockProxy<IWebhookFunctions>;
|
||||
@@ -251,4 +251,54 @@ describe('formCompletionUtils', () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('binaryResponse', () => {
|
||||
it('should get the latest binary data from the parent nodes', async () => {
|
||||
const expectedBinaryResponse = {
|
||||
inputData: {
|
||||
data: 'IyAxLiBHbyBpbiBwb3N0Z3',
|
||||
fileExtension: 'txt',
|
||||
fileName: 'file.txt',
|
||||
fileSize: '458 B',
|
||||
fileType: 'text',
|
||||
mimeType: 'text/plain',
|
||||
},
|
||||
};
|
||||
|
||||
const notExpectedBinaryResponse = {
|
||||
inputData: {
|
||||
data: 'notexpected',
|
||||
fileExtension: 'txt',
|
||||
fileName: 'file.txt',
|
||||
fileSize: '458 B',
|
||||
fileType: 'text',
|
||||
mimeType: 'text/plain',
|
||||
},
|
||||
};
|
||||
|
||||
mockWebhookFunctions.getNodeParameter.mockImplementation((parameterName: string) => {
|
||||
const params: { [key: string]: any } = {
|
||||
inputDataFieldName: 'inputData',
|
||||
};
|
||||
return params[parameterName];
|
||||
});
|
||||
|
||||
mockWebhookFunctions.getParentNodes.mockReturnValueOnce(parentNodesWithMultipleBinaryFiles);
|
||||
mockWebhookFunctions.evaluateExpression.mockImplementation((arg) => {
|
||||
if (arg === `{{ $('${nodeNameWithFile}').first().binary }}`) {
|
||||
return expectedBinaryResponse;
|
||||
} else {
|
||||
return notExpectedBinaryResponse;
|
||||
}
|
||||
});
|
||||
|
||||
const result = await binaryResponse(mockWebhookFunctions);
|
||||
|
||||
expect(result).toEqual({
|
||||
data: atob(expectedBinaryResponse.inputData.data),
|
||||
fileName: expectedBinaryResponse.inputData.fileName,
|
||||
type: expectedBinaryResponse.inputData.mimeType,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user