From e9c152e369a4c2762bd8e6ad17eaa704bb3771bb Mon Sep 17 00:00:00 2001 From: Charlie Kolb Date: Thu, 16 Jan 2025 13:04:06 +0100 Subject: [PATCH] fix(Execute Workflow Node): Pass binary data to sub-workflow (#12635) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ --- .../GenericFunctions.ts | 5 +- .../__tests__/GenericFunctions.test.ts | 63 +++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 packages/nodes-base/utils/workflowInputsResourceMapping/__tests__/GenericFunctions.test.ts diff --git a/packages/nodes-base/utils/workflowInputsResourceMapping/GenericFunctions.ts b/packages/nodes-base/utils/workflowInputsResourceMapping/GenericFunctions.ts index 964dc7b179..cd12e3be3d 100644 --- a/packages/nodes-base/utils/workflowInputsResourceMapping/GenericFunctions.ts +++ b/packages/nodes-base/utils/workflowInputsResourceMapping/GenericFunctions.ts @@ -97,7 +97,7 @@ export function getFieldEntries(context: IWorkflowNodeContext): FieldValueOption export function getWorkflowInputValues(this: ISupplyDataFunctions): INodeExecutionData[] { const inputData = this.getInputData(); - return inputData.map((item, itemIndex) => { + return inputData.map(({ json, binary }, itemIndex) => { const itemFieldValues = this.getNodeParameter( 'workflowInputs.value', itemIndex, @@ -106,13 +106,14 @@ export function getWorkflowInputValues(this: ISupplyDataFunctions): INodeExecuti return { json: { - ...item.json, + ...json, ...itemFieldValues, }, index: itemIndex, pairedItem: { item: itemIndex, }, + binary, }; }); } diff --git a/packages/nodes-base/utils/workflowInputsResourceMapping/__tests__/GenericFunctions.test.ts b/packages/nodes-base/utils/workflowInputsResourceMapping/__tests__/GenericFunctions.test.ts new file mode 100644 index 0000000000..31b286ac15 --- /dev/null +++ b/packages/nodes-base/utils/workflowInputsResourceMapping/__tests__/GenericFunctions.test.ts @@ -0,0 +1,63 @@ +import { mock } from 'jest-mock-extended'; +import type { ISupplyDataFunctions } from 'n8n-workflow'; + +import { getWorkflowInputValues } from '../GenericFunctions'; + +describe('getWorkflowInputValues', () => { + const supplyDataFunctions = mock(); + + it('should correctly map the binary property', () => { + supplyDataFunctions.getInputData.mockReturnValue([ + { + json: { key1: 'value1' }, + binary: { file1: { data: 'binaryData1', mimeType: 'image/png' } }, + }, + { + json: { key2: 'value2' }, + binary: { file2: { data: 'binaryData2', mimeType: 'image/jpeg' } }, + }, + ]); + + supplyDataFunctions.getNodeParameter + .calledWith('workflowInputs.value', 0) + .mockReturnValueOnce({ additionalKey1: 'additionalValue1' }); + supplyDataFunctions.getNodeParameter + .calledWith('workflowInputs.value', 1) + .mockReturnValueOnce({ additionalKey2: 'additionalValue2' }); + + const result = getWorkflowInputValues.call(supplyDataFunctions); + + expect(result).toEqual([ + { + json: { + key1: 'value1', + additionalKey1: 'additionalValue1', + }, + binary: { file1: { data: 'binaryData1', mimeType: 'image/png' } }, + index: 0, + pairedItem: { item: 0 }, + }, + { + json: { + key2: 'value2', + additionalKey2: 'additionalValue2', + }, + binary: { file2: { data: 'binaryData2', mimeType: 'image/jpeg' } }, + index: 1, + pairedItem: { item: 1 }, + }, + ]); + + expect(supplyDataFunctions.getInputData).toHaveBeenCalled(); + expect(supplyDataFunctions.getNodeParameter).toHaveBeenCalledWith( + 'workflowInputs.value', + 0, + {}, + ); + expect(supplyDataFunctions.getNodeParameter).toHaveBeenCalledWith( + 'workflowInputs.value', + 1, + {}, + ); + }); +});