diff --git a/package.json b/package.json index 563cf6227b3e0..fd5d6feab24eb 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "build": "turbo run build", "build:backend": "pnpm --filter=!@n8n/chat --filter=!@n8n/codemirror-lang --filter=!n8n-design-system --filter=!n8n-editor-ui build", "build:frontend": "pnpm --filter=@n8n/chat --filter=@n8n/codemirror-lang --filter=n8n-design-system --filter=n8n-editor-ui build", - "typecheck": "pnpm --filter=!@n8n/storybook --filter=!n8n-core --filter=!n8n-workflow --filter=!n8n typecheck", + "typecheck": "pnpm --filter=!n8n typecheck", "dev": "turbo run dev --parallel --filter=!n8n-design-system --filter=!@n8n/chat", "dev:ai": "turbo run dev --parallel --filter=@n8n/nodes-langchain --filter=n8n --filter=n8n-core", "clean": "turbo run clean --parallel", diff --git a/packages/core/test/helpers/constants.ts b/packages/core/test/helpers/constants.ts index b1bfe740ba0f1..c71044cdb38ba 100644 --- a/packages/core/test/helpers/constants.ts +++ b/packages/core/test/helpers/constants.ts @@ -4,6 +4,7 @@ import type { INodeTypeData, WorkflowTestData, } from 'n8n-workflow'; +import { NodeConnectionType } from 'n8n-workflow'; import { If } from '../../../nodes-base/dist/nodes/If/If.node'; import { Merge } from '../../../nodes-base/dist/nodes/Merge/Merge.node'; import { NoOp } from '../../../nodes-base/dist/nodes/NoOp/NoOp.node'; @@ -264,14 +265,14 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge3', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], [ { node: 'Merge6', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -282,7 +283,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge5', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -293,7 +294,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'NoOp2', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -304,14 +305,14 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge3', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], [ { node: 'IF4', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -322,7 +323,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge4', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -333,14 +334,14 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge2', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], [ { node: 'Merge2', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -351,7 +352,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge7', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -362,7 +363,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge6', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -373,7 +374,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge5', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -384,7 +385,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge4', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -395,14 +396,14 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], [ { node: 'Merge1', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -413,17 +414,17 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'IF1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'IF2', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'IF3', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -434,7 +435,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -615,7 +616,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'IF', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -626,19 +627,19 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Merge1', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], [ { node: 'Merge', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -649,7 +650,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge2', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -660,7 +661,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'IF1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -671,12 +672,12 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Merge1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -687,7 +688,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge2', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -698,17 +699,17 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, { node: 'Set1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Set', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -890,7 +891,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -968,12 +969,12 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Set2', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -984,7 +985,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set2', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -1156,12 +1157,12 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge1', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, { node: 'Merge2', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -1172,7 +1173,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge3', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -1183,7 +1184,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set4', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -1194,7 +1195,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge4', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -1205,7 +1206,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge3', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -1216,7 +1217,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge2', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -1227,12 +1228,12 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Set3', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -1243,17 +1244,17 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Set2', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Merge4', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -1434,7 +1435,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -1445,14 +1446,14 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set2', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], [ { node: 'Merge1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -1463,12 +1464,12 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'IF', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Merge1', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -1479,7 +1480,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -1638,7 +1639,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set0', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -1649,7 +1650,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge1', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -1660,7 +1661,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -1671,7 +1672,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -1682,7 +1683,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -1693,7 +1694,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'IF', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -1813,7 +1814,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -1824,14 +1825,14 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], [ { node: 'Set2', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -1842,7 +1843,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -1853,7 +1854,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'IF', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -1959,7 +1960,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -1970,7 +1971,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'IF', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -1981,19 +1982,19 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'NoOpTrue', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Merge', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], [ { node: 'NoOpFalse', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2004,7 +2005,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2084,7 +2085,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'VersionTest1a', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2095,7 +2096,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'VersionTest1b', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2106,7 +2107,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'VersionTest2a', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2117,7 +2118,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'VersionTest2b', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2460,7 +2461,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2471,7 +2472,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait2', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2482,32 +2483,32 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Wait1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Wait6', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Wait7', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Wait8', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Wait9', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2518,7 +2519,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait4', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2529,12 +2530,12 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait3', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Merge', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -2545,12 +2546,12 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait10', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Wait11', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2561,7 +2562,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait5', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2572,7 +2573,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2583,7 +2584,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait13', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2594,7 +2595,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait12', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2605,7 +2606,7 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait14', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2616,12 +2617,12 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'IF', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'IF1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2632,14 +2633,14 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait15', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], [ { node: 'Wait16', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2650,14 +2651,14 @@ export const legacyWorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait17', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], [ { node: 'Wait18', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2755,12 +2756,12 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Set2', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2771,7 +2772,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set2', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2943,12 +2944,12 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge1', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, { node: 'Merge2', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -2959,7 +2960,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge3', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2970,7 +2971,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set4', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2981,7 +2982,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge4', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -2992,7 +2993,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge3', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -3003,7 +3004,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge2', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -3014,12 +3015,12 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Set3', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -3030,17 +3031,17 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Set2', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Merge4', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -3428,7 +3429,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -3439,7 +3440,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait2', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -3450,32 +3451,32 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Wait1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Wait6', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Wait7', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Wait8', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Wait9', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -3486,7 +3487,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait4', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -3497,12 +3498,12 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait3', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Merge', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -3513,12 +3514,12 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait10', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Wait11', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -3529,7 +3530,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait5', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -3540,7 +3541,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -3551,7 +3552,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait13', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -3562,7 +3563,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait12', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -3573,7 +3574,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait14', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -3584,12 +3585,12 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'IF', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'IF1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -3600,14 +3601,14 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait15', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], [ { node: 'Wait16', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -3618,14 +3619,14 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Wait17', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], [ { node: 'Wait18', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -3778,7 +3779,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'IF', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -3789,19 +3790,19 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Merge1', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], [ { node: 'Merge', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -3812,7 +3813,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge2', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -3823,7 +3824,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'IF1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -3834,12 +3835,12 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Merge1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -3850,7 +3851,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge2', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -3861,17 +3862,17 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, { node: 'Set1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'Set', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -4093,7 +4094,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -4104,7 +4105,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'IF', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -4115,14 +4116,14 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'NoOp', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], [ { node: 'NoOp1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -4133,7 +4134,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -4144,7 +4145,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -4337,14 +4338,14 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge3', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], [ { node: 'Merge6', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -4355,7 +4356,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge5', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -4366,7 +4367,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'NoOp2', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -4377,14 +4378,14 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge3', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], [ { node: 'IF4', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -4395,7 +4396,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge4', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -4406,14 +4407,14 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge2', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], [ { node: 'Merge2', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -4424,7 +4425,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge7', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -4435,7 +4436,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge6', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -4446,7 +4447,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge5', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -4457,7 +4458,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge4', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -4468,14 +4469,14 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Merge1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], [ { node: 'Merge1', - type: 'main', + type: NodeConnectionType.Main, index: 1, }, ], @@ -4486,17 +4487,17 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'IF1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'IF2', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, { node: 'IF3', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -4507,7 +4508,7 @@ export const v1WorkflowExecuteTests: WorkflowTestData[] = [ [ { node: 'Set1', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], diff --git a/packages/editor-ui/src/components/FilterConditions/utils.ts b/packages/editor-ui/src/components/FilterConditions/utils.ts index d9d115abcd6d4..bff4b4e902933 100644 --- a/packages/editor-ui/src/components/FilterConditions/utils.ts +++ b/packages/editor-ui/src/components/FilterConditions/utils.ts @@ -23,7 +23,10 @@ const getTargetType = (type: FilterOperatorType) => { return 'string'; }; -const convertToType = (value: NodeParameterValue, type: FilterOperatorType): NodeParameterValue => { +const convertToType = ( + value: NodeParameterValue | NodeParameterValue[], + type: FilterOperatorType, +): NodeParameterValue | NodeParameterValue[] => { if (type === 'any') return value; const fallback = type === 'boolean' ? false : value; diff --git a/packages/workflow/src/Interfaces.ts b/packages/workflow/src/Interfaces.ts index 2b05f5fa04cb3..fdc6716b64f2e 100644 --- a/packages/workflow/src/Interfaces.ts +++ b/packages/workflow/src/Interfaces.ts @@ -2474,9 +2474,9 @@ export interface FilterOperatorValue { export type FilterConditionValue = { id: string; - leftValue: NodeParameterValue; + leftValue: NodeParameterValue | NodeParameterValue[]; operator: FilterOperatorValue; - rightValue: NodeParameterValue; + rightValue: NodeParameterValue | NodeParameterValue[]; }; export type FilterOptionsValue = { diff --git a/packages/workflow/test/FilterParameter.test.ts b/packages/workflow/test/FilterParameter.test.ts index 4e81e2e9a7b88..d08e41ba3221d 100644 --- a/packages/workflow/test/FilterParameter.test.ts +++ b/packages/workflow/test/FilterParameter.test.ts @@ -7,6 +7,12 @@ type DeepPartial = { [P in keyof T]?: T[P] extends object ? DeepPartial : T[P]; }; +type Tests = Array<{ + left: FilterConditionValue['leftValue']; + right: FilterConditionValue['rightValue']; + expected: boolean; +}>; + const filterFactory = (data: DeepPartial = {}): FilterValue => merge( { @@ -832,21 +838,24 @@ describe('FilterParameter', () => { right: '1-Feb-2024', expected: false, }, - ])('dateTime:after("$left", "$right") === $expected', ({ left, right, expected }) => { - const result = executeFilter( - filterFactory({ - conditions: [ - { - id: '1', - leftValue: left, - rightValue: right, - operator: { operation: 'after', type: 'dateTime' }, - }, - ], - }), - ); - expect(result).toBe(expected); - }); + ] as Tests)( + 'dateTime:after("$left", "$right") === $expected', + ({ left, right, expected }) => { + const result = executeFilter( + filterFactory({ + conditions: [ + { + id: '1', + leftValue: left, + rightValue: right, + operator: { operation: 'after', type: 'dateTime' }, + }, + ], + }), + ); + expect(result).toBe(expected); + }, + ); it.each([ { left: '2023-11-15T17:10:49.113Z', right: '2023-11-15T17:10:49.113Z', expected: false }, @@ -1035,7 +1044,7 @@ describe('FilterParameter', () => { it.each([ { left: ['foo', 'bar'], right: 'foo', expected: true }, { left: ['foo', 'bar'], right: 'ba', expected: false }, - ])('array:contains($left,$right) === $expected', ({ left, right, expected }) => { + ] as Tests)('array:contains($left,$right) === $expected', ({ left, right, expected }) => { const result = executeFilter( filterFactory({ conditions: [ @@ -1054,67 +1063,76 @@ describe('FilterParameter', () => { it.each([ { left: ['foo', 'bar'], right: 'foo', expected: false }, { left: ['foo', 'bar'], right: 'ba', expected: true }, - ])('array:notContains($left,$right) === $expected', ({ left, right, expected }) => { - const result = executeFilter( - filterFactory({ - conditions: [ - { - id: '1', - leftValue: left, - rightValue: right, - operator: { operation: 'notContains', type: 'array', rightType: 'any' }, - }, - ], - }), - ); - expect(result).toBe(expected); - }); + ] as Tests)( + 'array:notContains($left,$right) === $expected', + ({ left, right, expected }) => { + const result = executeFilter( + filterFactory({ + conditions: [ + { + id: '1', + leftValue: left, + rightValue: right, + operator: { operation: 'notContains', type: 'array', rightType: 'any' }, + }, + ], + }), + ); + expect(result).toBe(expected); + }, + ); it.each([ { left: ['foo', 'bar'], right: 2, expected: true }, { left: [], right: 0, expected: true }, { left: ['foo', 'bar'], right: 1, expected: false }, - ])('array:lengthEquals($left,$right) === $expected', ({ left, right, expected }) => { - const result = executeFilter( - filterFactory({ - conditions: [ - { - id: '1', - leftValue: left, - rightValue: right, - operator: { operation: 'lengthEquals', type: 'array', rightType: 'number' }, - }, - ], - }), - ); - expect(result).toBe(expected); - }); + ] as Tests)( + 'array:lengthEquals($left,$right) === $expected', + ({ left, right, expected }) => { + const result = executeFilter( + filterFactory({ + conditions: [ + { + id: '1', + leftValue: left, + rightValue: right, + operator: { operation: 'lengthEquals', type: 'array', rightType: 'number' }, + }, + ], + }), + ); + expect(result).toBe(expected); + }, + ); it.each([ { left: ['foo', 'bar'], right: 2, expected: false }, { left: [], right: 0, expected: false }, { left: ['foo', 'bar'], right: 1, expected: true }, - ])('array:lengthNotEquals($left,$right) === $expected', ({ left, right, expected }) => { - const result = executeFilter( - filterFactory({ - conditions: [ - { - id: '1', - leftValue: left, - rightValue: right, - operator: { operation: 'lengthNotEquals', type: 'array', rightType: 'number' }, - }, - ], - }), - ); - expect(result).toBe(expected); - }); + ] as Tests)( + 'array:lengthNotEquals($left,$right) === $expected', + ({ left, right, expected }) => { + const result = executeFilter( + filterFactory({ + conditions: [ + { + id: '1', + leftValue: left, + rightValue: right, + operator: { operation: 'lengthNotEquals', type: 'array', rightType: 'number' }, + }, + ], + }), + ); + expect(result).toBe(expected); + }, + ); it.each([ { left: ['foo', 'bar'], right: 2, expected: false }, { left: [], right: 0, expected: false }, { left: ['foo', 'bar'], right: 1, expected: true }, - ])('array:lengthGt($left,$right) === $expected', ({ left, right, expected }) => { + ] as Tests)('array:lengthGt($left,$right) === $expected', ({ left, right, expected }) => { const result = executeFilter( filterFactory({ conditions: [ @@ -1135,7 +1153,7 @@ describe('FilterParameter', () => { { left: [], right: 0, expected: false }, { left: ['foo', 'bar'], right: 1, expected: false }, { left: ['foo', 'bar'], right: 3, expected: true }, - ])('array:lengthLt($left,$right) === $expected', ({ left, right, expected }) => { + ] as Tests)('array:lengthLt($left,$right) === $expected', ({ left, right, expected }) => { const result = executeFilter( filterFactory({ conditions: [ @@ -1156,7 +1174,7 @@ describe('FilterParameter', () => { { left: [], right: 0, expected: true }, { left: ['foo', 'bar'], right: 1, expected: true }, { left: ['foo', 'bar'], right: 3, expected: false }, - ])('array:lengthGte($left,$right) === $expected', ({ left, right, expected }) => { + ] as Tests)('array:lengthGte($left,$right) === $expected', ({ left, right, expected }) => { const result = executeFilter( filterFactory({ conditions: [ @@ -1177,7 +1195,7 @@ describe('FilterParameter', () => { { left: [], right: 0, expected: true }, { left: ['foo', 'bar'], right: 1, expected: false }, { left: ['foo', 'bar'], right: 3, expected: true }, - ])('array:lengthLte($left,$right) === $expected', ({ left, right, expected }) => { + ] as Tests)('array:lengthLte($left,$right) === $expected', ({ left, right, expected }) => { const result = executeFilter( filterFactory({ conditions: [ diff --git a/packages/workflow/test/TelemetryHelpers.test.ts b/packages/workflow/test/TelemetryHelpers.test.ts index 90bddbdcdd8f2..c1f46d2d66140 100644 --- a/packages/workflow/test/TelemetryHelpers.test.ts +++ b/packages/workflow/test/TelemetryHelpers.test.ts @@ -9,7 +9,7 @@ import { } from '@/TelemetryHelpers'; import { nodeTypes } from './ExpressionExtensions/Helpers'; import * as nodeHelpers from '@/NodeHelpers'; -import type { IWorkflowBase } from '@/Interfaces'; +import { NodeConnectionType, type IWorkflowBase } from '@/Interfaces'; import { STICKY_NODE_TYPE } from '@/Constants'; import { ApplicationError } from '@/errors'; import { randomInt } from '@/utils'; @@ -111,7 +111,7 @@ describe('generateNodesGraph', () => { ], connections: { 'When clicking "Execute Workflow"': { - main: [[{ node: 'Google Sheets', type: 'main', index: 0 }]], + main: [[{ node: 'Google Sheets', type: NodeConnectionType.Main, index: 0 }]], }, }, settings: { executionOrder: 'v1' }, @@ -215,7 +215,7 @@ describe('generateNodesGraph', () => { ], connections: { 'When clicking "Execute Workflow"': { - main: [[{ node: 'Google Sheets', type: 'main', index: 0 }]], + main: [[{ node: 'Google Sheets', type: NodeConnectionType.Main, index: 0 }]], }, }, settings: { executionOrder: 'v1' }, @@ -291,7 +291,7 @@ describe('generateNodesGraph', () => { ], connections: { 'When clicking "Execute Workflow"': { - main: [[{ node: 'Google Sheets', type: 'main', index: 0 }]], + main: [[{ node: 'Google Sheets', type: NodeConnectionType.Main, index: 0 }]], }, }, settings: { executionOrder: 'v1' }, @@ -369,7 +369,7 @@ describe('generateNodesGraph', () => { ], connections: { 'When clicking "Execute Workflow"': { - main: [[{ node: 'Google Sheets', type: 'main', index: 0 }]], + main: [[{ node: 'Google Sheets', type: NodeConnectionType.Main, index: 0 }]], }, }, settings: { executionOrder: 'v1' }, @@ -701,7 +701,7 @@ describe('generateNodesGraph', () => { [ { node: 'Chain', - type: 'main', + type: NodeConnectionType.Main, index: 0, }, ], @@ -712,7 +712,7 @@ describe('generateNodesGraph', () => { [ { node: 'Chain', - type: 'ai_languageModel', + type: NodeConnectionType.AiLanguageModel, index: 0, }, ], diff --git a/packages/workflow/test/TypeValidation.test.ts b/packages/workflow/test/TypeValidation.test.ts index 1a1e99afac181..eb50b434376b5 100644 --- a/packages/workflow/test/TypeValidation.test.ts +++ b/packages/workflow/test/TypeValidation.test.ts @@ -1,179 +1,212 @@ -import { getValueDescription, validateFieldType } from '@/TypeValidation'; import { DateTime } from 'luxon'; - -const VALID_ISO_DATES = [ - '1994-11-05T08:15:30-05:00', - '1994-11-05T13:15:30Z', - '1997-07-16T19:20+01:00', - '1997-07-16T19:20:30+01:00', - '1997-07-16T19:20:30.45+01:00', - '2018-05-16', - '1972-06-30T23:59:40Z', - '2019-03-26T14:00:00.9Z', - '2019-03-26T14:00:00.4999Z', - '2023-05-17T10:52:32+0000', - '2023-05-17T10:52:32+0000', -]; - -const VALID_HTTP_DATES = [ - 'Wed, 21 Oct 2015 07:28:00 GMT', - 'Wed, 01 Jun 2022 08:00:00 GMT', - 'Tue, 15 Nov 1994 12:45:26 GMT', - 'Wed, 1 Jun 2022 08:00:00 GMT', -]; - -const VALID_RFC_DATES = [ - 'Tue, 04 Jun 2013 07:40:03 -0400', - 'Tue, 4 Jun 2013 02:24:39 +0530', - 'Wed, 17 May 2023 10:52:32 +0000', -]; - -const VALID_SQL_DATES = ['2008-11-11', '2008-11-11 13:23:44']; - -const OTHER_VALID_DATES = [ - 'Wed, 17 May 2023 10:52:32', - 'SMT, 17 May 2023 10:52:32', - '1-Feb-2024', - new Date(), - DateTime.now(), -]; - -const INVALID_DATES = [ - '1994-11-05M08:15:30-05:00', - '18-05-2020', - '', - '1685084980', // We are not supporting timestamps - '1685085012135', - 1685084980, - 1685085012135, - true, - [], -]; +import { getValueDescription, validateFieldType } from '@/TypeValidation'; describe('Type Validation', () => { describe('Dates', () => { - test.each(VALID_ISO_DATES)('should validate and cast ISO date "%s"', (date) => { - const validationResult = validateFieldType('date', date, 'dateTime'); - expect(validationResult.valid).toBe(true); - expect((validationResult.newValue as DateTime).isValid).toBe(true); + test('should validate and cast ISO dates', () => { + const VALID_ISO_DATES = [ + '1994-11-05T08:15:30-05:00', + '1994-11-05T13:15:30Z', + '1997-07-16T19:20+01:00', + '1997-07-16T19:20:30+01:00', + '1997-07-16T19:20:30.45+01:00', + '2018-05-16', + '1972-06-30T23:59:40Z', + '2019-03-26T14:00:00.9Z', + '2019-03-26T14:00:00.4999Z', + '2023-05-17T10:52:32+0000', + '2023-05-17T10:52:32+0000', + ]; + VALID_ISO_DATES.forEach((date) => + expect(validateFieldType('date', date, 'dateTime')).toEqual({ + valid: true, + newValue: expect.any(DateTime), + }), + ); }); - test.each(VALID_RFC_DATES)('should validate and cast RFC2822 date "%s"', (date) => { - const validationResult = validateFieldType('date', date, 'dateTime'); - expect(validationResult.valid).toBe(true); - expect((validationResult.newValue as DateTime).isValid).toBe(true); + test('should validate and cast RFC2822 dates', () => { + const VALID_RFC_DATES = [ + 'Tue, 04 Jun 2013 07:40:03 -0400', + 'Tue, 4 Jun 2013 02:24:39 +0530', + 'Wed, 17 May 2023 10:52:32 +0000', + ]; + VALID_RFC_DATES.forEach((date) => + expect(validateFieldType('date', date, 'dateTime')).toEqual({ + valid: true, + newValue: expect.any(DateTime), + }), + ); }); - test.each(VALID_HTTP_DATES)('should validate and cast HTTP date "%s"', (date) => { - const validationResult = validateFieldType('date', date, 'dateTime'); - expect(validationResult.valid).toBe(true); - expect((validationResult.newValue as DateTime).isValid).toBe(true); + test('should validate and cast HTTP dates', () => { + const VALID_HTTP_DATES = [ + 'Wed, 21 Oct 2015 07:28:00 GMT', + 'Wed, 01 Jun 2022 08:00:00 GMT', + 'Tue, 15 Nov 1994 12:45:26 GMT', + 'Wed, 1 Jun 2022 08:00:00 GMT', + ]; + VALID_HTTP_DATES.forEach((date) => + expect(validateFieldType('date', date, 'dateTime')).toEqual({ + valid: true, + newValue: expect.any(DateTime), + }), + ); }); - test.each(VALID_SQL_DATES)('should validate and cast SQL date "%s"', (date) => { - const validationResult = validateFieldType('date', date, 'dateTime'); - expect(validationResult.valid).toBe(true); - expect((validationResult.newValue as DateTime).isValid).toBe(true); + test('should validate and cast SQL dates', () => { + const VALID_SQL_DATES = ['2008-11-11', '2008-11-11 13:23:44']; + VALID_SQL_DATES.forEach((date) => + expect(validateFieldType('date', date, 'dateTime')).toEqual({ + valid: true, + newValue: expect.any(DateTime), + }), + ); }); - test.each(OTHER_VALID_DATES)('should validate and cast date "%s"', (date) => { - const validationResult = validateFieldType('date', date, 'dateTime'); - expect(validationResult.valid).toBe(true); - expect((validationResult.newValue as DateTime).isValid).toBe(true); + test('should validate and cast other valid dates', () => { + const OTHER_VALID_DATES = [ + 'Wed, 17 May 2023 10:52:32', + 'SMT, 17 May 2023 10:52:32', + '1-Feb-2024', + new Date(), + DateTime.now(), + ]; + OTHER_VALID_DATES.forEach((date) => + expect(validateFieldType('date', date, 'dateTime')).toEqual({ + valid: true, + newValue: expect.any(DateTime), + }), + ); }); - test.each(INVALID_DATES)('should not validate invalid date "%s"', (date) => { - const validationResult = validateFieldType('date', date, 'dateTime'); - expect(validationResult.valid).toBe(false); + test('should not validate invalid dates', () => { + const INVALID_DATES = [ + '1994-11-05M08:15:30-05:00', + '18-05-2020', + '', + '1685084980', // We are not supporting timestamps + '1685085012135', + 1685084980, + 1685085012135, + true, + [], + ]; + INVALID_DATES.forEach((date) => + expect(validateFieldType('date', date, 'dateTime').valid).toBe(false), + ); }); }); it('should validate boolean values properly', () => { - expect(validateFieldType('boolean', 'true', 'boolean').newValue).toBe(true); - expect(validateFieldType('boolean', 'TRUE', 'boolean').newValue).toBe(true); - expect(validateFieldType('boolean', 1, 'boolean').newValue).toBe(true); - expect(validateFieldType('boolean', '1', 'boolean').newValue).toBe(true); - expect(validateFieldType('boolean', '01', 'boolean').newValue).toBe(true); - expect(validateFieldType('boolean', 'false', 'boolean').newValue).toBe(false); - expect(validateFieldType('boolean', 'FALSE', 'boolean').newValue).toBe(false); - expect(validateFieldType('boolean', '0', 'boolean').newValue).toBe(false); - expect(validateFieldType('boolean', '000', 'boolean').newValue).toBe(false); - expect(validateFieldType('boolean', '0000', 'boolean').newValue).toBe(false); - expect(validateFieldType('boolean', 0, 'boolean').newValue).toBe(false); + const TRUE_VALUES = ['true', 'TRUE', 1, '1', '01']; + TRUE_VALUES.forEach((value) => + expect(validateFieldType('boolean', value, 'boolean')).toEqual({ + valid: true, + newValue: true, + }), + ); + + const FALSE_VALUES = ['false', 'FALSE', 0, '0', '000', '0000']; + FALSE_VALUES.forEach((value) => + expect(validateFieldType('boolean', value, 'boolean')).toEqual({ + valid: true, + newValue: false, + }), + ); }); it('should not validate invalid boolean values', () => { - expect(validateFieldType('boolean', 'tru', 'boolean').valid).toBe(false); - expect(validateFieldType('boolean', 'fals', 'boolean').valid).toBe(false); - expect(validateFieldType('boolean', 1111, 'boolean').valid).toBe(false); - expect(validateFieldType('boolean', 2, 'boolean').valid).toBe(false); - expect(validateFieldType('boolean', -1, 'boolean').valid).toBe(false); - expect(validateFieldType('boolean', 'yes', 'boolean').valid).toBe(false); - expect(validateFieldType('boolean', 'no', 'boolean').valid).toBe(false); + const INVALID_VALUES = ['tru', 'fals', 1111, 2, -1, 'yes', 'no']; + INVALID_VALUES.forEach((value) => + expect(validateFieldType('boolean', value, 'boolean').valid).toEqual(false), + ); }); it('should validate and cast numbers', () => { - expect(validateFieldType('number', '1', 'number').newValue).toBe(1); - expect(validateFieldType('number', '-1', 'number').newValue).toBe(-1); - expect(validateFieldType('number', '1.1', 'number').newValue).toBe(1.1); - expect(validateFieldType('number', '-1.1', 'number').newValue).toBe(-1.1); - expect(validateFieldType('number', 1, 'number').newValue).toBe(1); - expect(validateFieldType('number', 'A', 'number').valid).toBe(false); - expect(validateFieldType('number', '1,1', 'number').valid).toBe(false); - expect(validateFieldType('number', true, 'number').valid).toBe(true); - expect(validateFieldType('number', '1972-06-30T23:59:40Z', 'number').valid).toBe(false); - expect(validateFieldType('number', [1, 2], 'number').valid).toBe(false); + const VALID_NUMBERS = [ + ['1', 1], + ['-1', -1], + ['1.1', 1.1], + ['-1.1', -1.1], + [1, 1], + [true, 1], + ]; + VALID_NUMBERS.forEach(([value, expected]) => + expect(validateFieldType('number', value, 'number')).toEqual({ + valid: true, + newValue: expected, + }), + ); + + const INVALID_NUMBERS = ['A', '1,1', '1972-06-30T23:59:40Z', [1, 2]]; + INVALID_NUMBERS.forEach((value) => + expect(validateFieldType('number', value, 'number').valid).toEqual(false), + ); }); it('should validate and cast JSON properly', () => { - expect(validateFieldType('json', '{"a": 1}', 'object').newValue).toEqual({ a: 1 }); - expect( - validateFieldType('json', '{"a": 1, "b": { "c": 10, "d": "test"}}', 'object').valid, - ).toEqual(true); - expect(validateFieldType('json', { name: 'John' }, 'object').valid).toEqual(true); - expect( - validateFieldType( - 'json', + const VALID_OBJECTS = [ + ['{"a": 1}', { a: 1 }], + ['{"a": 1, "b": { "c": 10, "d": "test"}}', { a: 1, b: { c: 10, d: 'test' } }], + [{ name: 'John' }, { name: 'John' }], + [ { name: 'John', address: { street: 'Via Roma', city: 'Milano' } }, - 'object', - ).valid, - ).toEqual(true); - // Invalid value: - expect(validateFieldType('json', ['one', 'two'], 'object').valid).toEqual(false); - expect(validateFieldType('json', ['one', 'two'], 'object').valid).toEqual(false); - expect(validateFieldType('json', '1', 'object').valid).toEqual(false); - expect(validateFieldType('json', '[1]', 'object').valid).toEqual(false); - expect(validateFieldType('json', '1.1', 'object').valid).toEqual(false); - expect(validateFieldType('json', 1.1, 'object').valid).toEqual(false); - expect(validateFieldType('json', '"a"', 'object').valid).toEqual(false); - expect(validateFieldType('json', '{a: 1}', 'object').valid).toEqual(false); - expect(validateFieldType('json', '["apples", "oranges"]', 'object').valid).toEqual(false); - expect(validateFieldType('json', [{ name: 'john' }, { name: 'bob' }], 'object').valid).toEqual( - false, + { name: 'John', address: { street: 'Via Roma', city: 'Milano' } }, + ], + ]; + VALID_OBJECTS.forEach(([value, expected]) => + expect(validateFieldType('json', value, 'object')).toEqual({ + valid: true, + newValue: expected, + }), + ); + + const INVALID_JSON = [ + ['one', 'two'], + '1', + '[1]', + '1.1', + 1.1, + '"a"', + '{a: 1}', + '["apples", "oranges"]', + [{ name: 'john' }, { name: 'bob' }], + '[ { name: "john" }, { name: "bob" } ]', + ]; + INVALID_JSON.forEach((value) => + expect(validateFieldType('json', value, 'object').valid).toEqual(false), ); - expect( - validateFieldType('json', '[ { name: "john" }, { name: "bob" } ]', 'object').valid, - ).toEqual(false); }); it('should validate and cast arrays properly', () => { - expect(validateFieldType('array', '["apples", "oranges"]', 'array').newValue).toEqual([ - 'apples', - 'oranges', - ]); - expect(validateFieldType('array', '[1]', 'array').newValue).toEqual([1]); - expect(validateFieldType('array', '[1, 2]', 'array').newValue).toEqual([1, 2]); - // Invalid values: - expect(validateFieldType('array', '"apples", "oranges"', 'array').valid).toEqual(false); - expect(validateFieldType('array', '1', 'array').valid).toEqual(false); - expect(validateFieldType('array', '1.1', 'array').valid).toEqual(false); - expect(validateFieldType('array', '1, 2', 'array').valid).toEqual(false); - expect(validateFieldType('array', '1. 2. 3', 'array').valid).toEqual(false); - expect(validateFieldType('array', '[1, 2, 3', 'array').valid).toEqual(false); - expect(validateFieldType('array', '1, 2, 3]', 'array').valid).toEqual(false); - expect(validateFieldType('array', '{1, 2, {3, 4}, 5}', 'array').valid).toEqual(false); - expect(validateFieldType('array', '1, 2, {3, 4}, 5', 'array').valid).toEqual(false); - expect(validateFieldType('array', { name: 'John' }, 'array').valid).toEqual(false); + const VALID_ARRAYS = [ + ['["apples", "oranges"]', ['apples', 'oranges']], + ['[1]', [1]], + ['[1, 2]', [1, 2]], + ]; + VALID_ARRAYS.forEach(([value, expected]) => + expect(validateFieldType('array', value, 'array')).toEqual({ + valid: true, + newValue: expected, + }), + ); + + const INVALID_ARRAYS = [ + '"apples", "oranges"', + '1', + '1.1', + '1, 2', + '1. 2. 3', + '[1, 2, 3', + '1, 2, 3]', + '{1, 2, {3, 4}, 5}', + '1, 2, {3, 4}, 5', + { name: 'John' }, + ]; + INVALID_ARRAYS.forEach((value) => + expect(validateFieldType('array', value, 'array').valid).toEqual(false), + ); }); it('should validate options properly', () => { @@ -196,19 +229,27 @@ describe('Type Validation', () => { }); it('should validate and cast time properly', () => { - expect(validateFieldType('time', '23:23', 'time').valid).toEqual(true); - expect(validateFieldType('time', '23:23:23', 'time').valid).toEqual(true); - expect(validateFieldType('time', '23:23:23+1000', 'time').valid).toEqual(true); - expect(validateFieldType('time', '23:23:23-1000', 'time').valid).toEqual(true); - expect(validateFieldType('time', '22:00:00+01:00', 'time').valid).toEqual(true); - expect(validateFieldType('time', '22:00:00-01:00', 'time').valid).toEqual(true); - expect(validateFieldType('time', '22:00:00+01', 'time').valid).toEqual(true); - expect(validateFieldType('time', '22:00:00-01', 'time').valid).toEqual(true); - expect(validateFieldType('time', '23:23:23:23', 'time').valid).toEqual(false); - expect(validateFieldType('time', '23', 'time').valid).toEqual(false); - expect(validateFieldType('time', 'foo', 'time').valid).toEqual(false); - expect(validateFieldType('time', '23:23:', 'time').valid).toEqual(false); - expect(validateFieldType('time', '23::23::23', 'time').valid).toEqual(false); + const VALID_TIMES = [ + ['23:23', '23:23'], + ['23:23:23', '23:23:23'], + ['23:23:23+1000', '23:23:23+1000'], + ['23:23:23-1000', '23:23:23-1000'], + ['22:00:00+01:00', '22:00:00+01:00'], + ['22:00:00-01:00', '22:00:00-01:00'], + ['22:00:00+01', '22:00:00+01'], + ['22:00:00-01', '22:00:00-01'], + ]; + VALID_TIMES.forEach(([value, expected]) => + expect(validateFieldType('time', value, 'time')).toEqual({ + valid: true, + newValue: expected, + }), + ); + + const INVALID_TIMES = ['23:23:23:23', '23', 'foo', '23:23:', '23::23::23']; + INVALID_TIMES.forEach((value) => + expect(validateFieldType('time', value, 'time').valid).toEqual(false), + ); }); describe('options', () => { @@ -224,9 +265,15 @@ describe('Type Validation', () => { describe('parseStrings=true', () => { it('should parse strings from other types', () => { const options = { parseStrings: true }; - expect(validateFieldType('test', 42, 'string').newValue).toBe(42); - expect(validateFieldType('test', 42, 'string', options).newValue).toBe('42'); - expect(validateFieldType('test', true, 'string', options).newValue).toBe('true'); + expect(validateFieldType('test', 42, 'string')).toEqual({ valid: true, newValue: 42 }); + expect(validateFieldType('test', 42, 'string', options)).toEqual({ + valid: true, + newValue: '42', + }); + expect(validateFieldType('test', true, 'string', options)).toEqual({ + valid: true, + newValue: 'true', + }); }); }); });