From 46977a2aff342bc7568f5a378b78689a5c3d8e95 Mon Sep 17 00:00:00 2001 From: Omar Ajoue Date: Thu, 12 Oct 2023 16:41:51 +0200 Subject: [PATCH] fix: Prevent undefined issues when restoring binary data (#7419) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Github issue / Community forum post (link here to close automatically): --------- Co-authored-by: Iván Ovejero --- .../restoreBinaryDataId.ts | 2 +- .../cli/test/unit/execution.lifecycle.test.ts | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/executionLifecycleHooks/restoreBinaryDataId.ts b/packages/cli/src/executionLifecycleHooks/restoreBinaryDataId.ts index 66c5c91b4f..c43788c094 100644 --- a/packages/cli/src/executionLifecycleHooks/restoreBinaryDataId.ts +++ b/packages/cli/src/executionLifecycleHooks/restoreBinaryDataId.ts @@ -20,7 +20,7 @@ export async function restoreBinaryDataId(run: IRun, executionId: string) { const { runData } = run.data.resultData; const promises = Object.keys(runData).map(async (nodeName) => { - const binaryDataId = runData[nodeName]?.[0]?.data?.main?.[0]?.[0]?.binary?.data.id; + const binaryDataId = runData[nodeName]?.[0]?.data?.main?.[0]?.[0]?.binary?.data?.id; if (!binaryDataId) return; diff --git a/packages/cli/test/unit/execution.lifecycle.test.ts b/packages/cli/test/unit/execution.lifecycle.test.ts index 611c10496d..c41465c8e5 100644 --- a/packages/cli/test/unit/execution.lifecycle.test.ts +++ b/packages/cli/test/unit/execution.lifecycle.test.ts @@ -101,6 +101,32 @@ for (const mode of ['filesystem-v2', 's3'] as const) { expect(binaryDataService.rename).not.toHaveBeenCalled(); expect(getDataId(run, 'json')).toBe(dataId); }); + + it('should do nothing on itemless case', async () => { + const executionId = '999'; + + const promise = restoreBinaryDataId(toIRun(), executionId); + + await expect(promise).resolves.not.toThrow(); + + expect(binaryDataService.rename).not.toHaveBeenCalled(); + }); + + it('should do nothing if data is undefined', async () => { + const executionId = '999'; + + const run = toIRun({ + json: { + data: undefined, + }, + }); + + const promise = restoreBinaryDataId(run, executionId); + + await expect(promise).resolves.not.toThrow(); + + expect(binaryDataService.rename).not.toHaveBeenCalled(); + }); }); }); }