From 562506e92aeb26423145801bff80037e5ce2ac46 Mon Sep 17 00:00:00 2001 From: Dana <152518854+dana-gill@users.noreply.github.com> Date: Fri, 10 Jan 2025 16:11:19 +0100 Subject: [PATCH] fix(core): Validate values which are intentionally 0 (#12382) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ --- .../validateValueAgainstSchema.test.ts | 63 +++++++++++++++++++ .../utils/validateValueAgainstSchema.ts | 2 +- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/packages/core/src/node-execution-context/utils/__tests__/validateValueAgainstSchema.test.ts b/packages/core/src/node-execution-context/utils/__tests__/validateValueAgainstSchema.test.ts index e09299a457..d4b96fa41d 100644 --- a/packages/core/src/node-execution-context/utils/__tests__/validateValueAgainstSchema.test.ts +++ b/packages/core/src/node-execution-context/utils/__tests__/validateValueAgainstSchema.test.ts @@ -246,4 +246,67 @@ describe('validateValueAgainstSchema', () => { // value should be type number expect(typeof result).toEqual('number'); }); + + describe('when the mode is in Fixed mode, and the node is a resource mapper', () => { + const nodeType = { + description: { + properties: [ + { + name: 'operation', + type: 'resourceMapper', + typeOptions: { + resourceMapper: { + mode: 'add', + }, + }, + }, + ], + }, + } as unknown as INodeType; + + const node = { + parameters: { + operation: { + schema: [ + { id: 'num', type: 'number', required: true }, + { id: 'str', type: 'string', required: true }, + { id: 'obj', type: 'object', required: true }, + { id: 'arr', type: 'array', required: true }, + ], + attemptToConvertTypes: true, + mappingMode: '', + value: '', + }, + }, + } as unknown as INode; + + const parameterName = 'operation.value'; + + describe('should correctly validate values for', () => { + test.each([ + { num: 0 }, + { num: 23 }, + { num: -0 }, + { num: -Infinity }, + { num: Infinity }, + { str: '' }, + { str: ' ' }, + { str: 'hello' }, + { arr: [] }, + { obj: {} }, + ])('%s', (value) => { + expect(() => + validateValueAgainstSchema(node, nodeType, value, parameterName, 0, 0), + ).not.toThrow(); + }); + }); + + describe('should throw an error for', () => { + test.each([{ num: NaN }, { num: undefined }, { num: null }])('%s', (value) => { + expect(() => + validateValueAgainstSchema(node, nodeType, value, parameterName, 0, 0), + ).toThrow(); + }); + }); + }); }); diff --git a/packages/core/src/node-execution-context/utils/validateValueAgainstSchema.ts b/packages/core/src/node-execution-context/utils/validateValueAgainstSchema.ts index d058c50a52..a4c1b211e7 100644 --- a/packages/core/src/node-execution-context/utils/validateValueAgainstSchema.ts +++ b/packages/core/src/node-execution-context/utils/validateValueAgainstSchema.ts @@ -44,7 +44,7 @@ const validateResourceMapperValue = ( !skipRequiredCheck && schemaEntry?.required === true && schemaEntry.type !== 'boolean' && - !resolvedValue + (resolvedValue === undefined || resolvedValue === null) ) { return { valid: false,