fix: Prevent undefined issues when restoring binary data (#7419)

Github issue / Community forum post (link here to close automatically):

---------

Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
Omar Ajoue 2023-10-12 16:41:51 +02:00 committed by GitHub
parent 367255ab2c
commit 46977a2aff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View file

@ -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;

View file

@ -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();
});
});
});
}