mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 04:47:29 -08:00
fix(core): Validate values which are intentionally 0 (#12382)
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
parent
25a79ccf40
commit
562506e92a
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -44,7 +44,7 @@ const validateResourceMapperValue = (
|
|||
!skipRequiredCheck &&
|
||||
schemaEntry?.required === true &&
|
||||
schemaEntry.type !== 'boolean' &&
|
||||
!resolvedValue
|
||||
(resolvedValue === undefined || resolvedValue === null)
|
||||
) {
|
||||
return {
|
||||
valid: false,
|
||||
|
|
Loading…
Reference in a new issue