test(IF Node): Unit tests (no-changelog) (#5404)

* ️move test files

* ️IF boolean tests

* ️IF string tests

*  IF number tests

*  IF date-time tests

* 🎨 update Test name to make more sense
This commit is contained in:
Marcus 2023-02-08 15:20:17 +01:00 committed by GitHub
parent 14d1743595
commit 269691aa1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 2124 additions and 164 deletions

View file

@ -0,0 +1,306 @@
{
"name": "If node unit test",
"nodes": [
{
"parameters": {},
"id": "cc223c0f-eae7-4647-907a-8e44f1762442",
"name": "On clicking 'execute'",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
-2440,
520
]
},
{
"parameters": {
"jsCode": "return [\n { value: true, value2: false },\n { value: false, value2: true },\n];"
},
"id": "2aa0a57b-b25a-4293-b7bf-fc240d4d21f4",
"name": "Code",
"type": "n8n-nodes-base.code",
"typeVersion": 1,
"position": [
-2240,
520
]
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{ $json[\"value\"] }}",
"value2": true
},
{
"value1": "={{ $json.value2 }}",
"value2": true
}
]
},
"combineOperation": "any"
},
"id": "44d65f81-a358-4ec3-bea6-9760b1dba386",
"name": "IF ANY",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-2000,
700
],
"alwaysOutputData": false
},
{
"parameters": {},
"id": "db5d7a75-18d4-4721-bb81-1a9f8f4fce01",
"name": "On True ANY",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-1760,
620
]
},
{
"parameters": {},
"id": "033fe413-65fe-413d-87d7-53358c8e43a1",
"name": "On False ANY",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-1760,
800
]
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{ $json[\"value\"] }}",
"value2": true
}
]
}
},
"id": "787d9236-d7eb-442b-afef-91e6066b925c",
"name": "IF",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-2000,
340
]
},
{
"parameters": {},
"id": "c46df596-7cec-4a67-a50c-240e992f5c4d",
"name": "On True",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-1760,
260
]
},
{
"parameters": {},
"id": "86510ba2-8744-4383-b5a0-5c6b67625cd8",
"name": "On False",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-1760,
420
]
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{ $json[\"value\"] }}",
"operation": "notEqual",
"value2": true
}
]
}
},
"id": "2b031214-fff5-475b-88f9-a091a48bcc1e",
"name": "IF Not Equal",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-1420,
520
]
},
{
"parameters": {},
"id": "da080483-32b2-429c-8d06-61e40a86c8d5",
"name": "On True Not Equal",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-1180,
420
]
},
{
"parameters": {},
"id": "d373dd92-dede-4629-ab23-61e1dd89bc46",
"name": "On False Not Equal",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-1180,
600
]
}
],
"pinData": {
"On True": [
{
"json": {
"value": true,
"value2": false
}
}
],
"On False": [
{
"json": {
"value": false,
"value2": true
}
}
],
"On True Not Equal": [
{
"json": {
"value": false,
"value2": true
}
}
],
"On False Not Equal": [
{
"json": {
"value": true,
"value2": false
}
}
],
"On True ANY": [
{
"json": {
"value": true,
"value2": false
}
},
{
"json": {
"value": false,
"value2": true
}
}
]
},
"connections": {
"On clicking 'execute'": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"Code": {
"main": [
[
{
"node": "IF",
"type": "main",
"index": 0
},
{
"node": "IF ANY",
"type": "main",
"index": 0
},
{
"node": "IF Not Equal",
"type": "main",
"index": 0
}
]
]
},
"IF ANY": {
"main": [
[
{
"node": "On True ANY",
"type": "main",
"index": 0
}
],
[
{
"node": "On False ANY",
"type": "main",
"index": 0
}
]
]
},
"IF": {
"main": [
[
{
"node": "On True",
"type": "main",
"index": 0
}
],
[
{
"node": "On False",
"type": "main",
"index": 0
}
]
]
},
"IF Not Equal": {
"main": [
[
{
"node": "On True Not Equal",
"type": "main",
"index": 0
}
],
[
{
"node": "On False Not Equal",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {},
"versionId": "5d748d36-ca05-4f7a-b253-70c42e5473ca",
"id": "181",
"meta": {
"instanceId": "104a4d08d8897b8bdeb38aaca515021075e0bd8544c983c2bb8c86e6a8e6081c"
},
"tags": []
}

View file

@ -0,0 +1,221 @@
{
"name": "If node unit tests",
"nodes": [
{
"parameters": {},
"id": "711fa21c-4ac2-4eed-9c35-a79edf18e8af",
"name": "On clicking 'execute'",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
140,
1560
]
},
{
"parameters": {
"jsCode": "return [\n { dayOne: '2023-01-01T00:00:00.000-05:00', dayTwo: '2023-01-02T00:00:00.000-05:00' },\n { dayOne: '2023-01-02T00:00:00.000-05:00', dayTwo: '2023-01-01T00:00:00.000-05:00' },\n];"
},
"id": "c5d906bc-909a-45d9-a990-9ea6279cc807",
"name": "Code",
"type": "n8n-nodes-base.code",
"typeVersion": 1,
"position": [
340,
1560
]
},
{
"parameters": {
"conditions": {
"dateTime": [
{
"value1": "={{ $json.dayOne }}",
"value2": "={{ $json.dayTwo }}"
}
]
}
},
"id": "10431f40-d47d-4bd9-8dd6-d4dbb35d626b",
"name": "IF Occured After",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
560,
1440
]
},
{
"parameters": {},
"id": "2727a2f7-2bda-469b-a548-8df82de433e2",
"name": "On False Occured After",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
980,
1460
]
},
{
"parameters": {},
"id": "40baaffe-9769-4b15-b09f-3553e37f90a5",
"name": "On True Occured After",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
760,
1420
]
},
{
"parameters": {
"conditions": {
"dateTime": [
{
"value1": "={{ $json.dayOne }}",
"operation": "before",
"value2": "={{ $json.dayTwo }}"
}
]
}
},
"id": "29ff421d-d7c5-4cc6-8830-73c0abf1c13f",
"name": "IF Occured Before",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
560,
1680
]
},
{
"parameters": {},
"id": "3347b52a-e513-4900-ab9a-bbcc7a6ec063",
"name": "On True Occured Before",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
760,
1660
]
},
{
"parameters": {},
"id": "d8401e15-f6e5-4347-b885-54798494cb1b",
"name": "On False Occured Before",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
980,
1700
]
}
],
"pinData": {
"On True Occured After": [
{
"json": {
"dayOne": "2023-01-02T00:00:00.000-05:00",
"dayTwo": "2023-01-01T00:00:00.000-05:00"
}
}
],
"On False Occured After": [
{
"json": {
"dayOne": "2023-01-01T00:00:00.000-05:00",
"dayTwo": "2023-01-02T00:00:00.000-05:00"
}
}
],
"On True Occured Before": [
{
"json": {
"dayOne": "2023-01-01T00:00:00.000-05:00",
"dayTwo": "2023-01-02T00:00:00.000-05:00"
}
}
],
"On False Occured Before": [
{
"json": {
"dayOne": "2023-01-02T00:00:00.000-05:00",
"dayTwo": "2023-01-01T00:00:00.000-05:00"
}
}
]
},
"connections": {
"On clicking 'execute'": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"Code": {
"main": [
[
{
"node": "IF Occured After",
"type": "main",
"index": 0
},
{
"node": "IF Occured Before",
"type": "main",
"index": 0
}
]
]
},
"IF Occured After": {
"main": [
[
{
"node": "On True Occured After",
"type": "main",
"index": 0
}
],
[
{
"node": "On False Occured After",
"type": "main",
"index": 0
}
]
]
},
"IF Occured Before": {
"main": [
[
{
"node": "On True Occured Before",
"type": "main",
"index": 0
}
],
[
{
"node": "On False Occured Before",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {},
"versionId": "78121a47-2013-4f79-b0bd-b4d607dc82bf",
"id": "181",
"meta": {
"instanceId": "104a4d08d8897b8bdeb38aaca515021075e0bd8544c983c2bb8c86e6a8e6081c"
},
"tags": []
}

View file

@ -0,0 +1,616 @@
{
"name": "If node unit tests",
"nodes": [
{
"parameters": {},
"id": "11d2c2c8-5690-45e5-a863-8750191acaa7",
"name": "On clicking 'execute'",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
-5180,
3020
]
},
{
"parameters": {
"jsCode": "return [\n { value: 1 },\n { value: 2 },\n];"
},
"id": "77e63f88-e5fc-4662-af2e-6947a4768cf3",
"name": "Code",
"type": "n8n-nodes-base.code",
"typeVersion": 1,
"position": [
-4980,
3020
]
},
{
"parameters": {
"conditions": {
"number": [
{
"value1": "={{ $json.value }}",
"value2": 2
}
]
}
},
"id": "861e29f8-ae3d-4a67-8367-5811b021c129",
"name": "IF Smaller",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-4760,
2480
]
},
{
"parameters": {
"conditions": {
"number": [
{
"value1": "={{ $json.value }}",
"operation": "smallerEqual",
"value2": 2
}
]
}
},
"id": "b5ac7784-9d70-4df9-8451-8157e8ff23e6",
"name": "IF Smaller or Equal",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-4760,
2660
]
},
{
"parameters": {},
"id": "4f5336b3-de6d-4174-b186-f5040af0fa47",
"name": "On True Smaller",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-4560,
2460
]
},
{
"parameters": {},
"id": "f5128cec-4faa-4408-9b00-68d995bd0723",
"name": "On False Smaller",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-4320,
2500
]
},
{
"parameters": {},
"id": "ccf77a6c-e168-4ca3-9ade-ac13d04016f6",
"name": "On True Smaller or Equal",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-4560,
2640
]
},
{
"parameters": {
"conditions": {
"number": [
{
"value1": "={{ $json.value }}",
"operation": "equal",
"value2": 1
}
]
}
},
"id": "d276e794-56bc-4c7c-ab96-a2822ad75b3a",
"name": "IF Equal",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-4760,
2840
]
},
{
"parameters": {},
"id": "bad938c1-2faf-4aef-8059-9d1a33257fbf",
"name": "On True Equal",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-4560,
2820
]
},
{
"parameters": {},
"id": "8ff56c84-4a44-440c-a5cf-8659879b1bb3",
"name": "On False Equal",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-4320,
2860
]
},
{
"parameters": {
"conditions": {
"number": [
{
"value1": "={{ $json.value }}",
"operation": "notEqual",
"value2": 1
}
]
}
},
"id": "bda97a18-aca7-437f-9920-96089067c43c",
"name": "IF Not Equal",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-4760,
3020
]
},
{
"parameters": {},
"id": "7f3a01bd-24c5-43fd-bc1e-8087301f9745",
"name": "On True Not Equal",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-4560,
3000
]
},
{
"parameters": {},
"id": "f956db17-cd53-4222-94ed-100d91dc0c5a",
"name": "On False Not Equal",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-4320,
3040
]
},
{
"parameters": {
"conditions": {
"number": [
{
"value1": "={{ $json.value }}",
"operation": "larger",
"value2": 1
}
]
}
},
"id": "eb01c8b7-43fb-4716-8247-69eabb47ff6b",
"name": "IF Larger",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-4760,
3200
]
},
{
"parameters": {},
"id": "81b6e68d-2536-424d-908f-5bf6f4ee090d",
"name": "On True Larger",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-4560,
3180
]
},
{
"parameters": {},
"id": "d7881e80-93bf-45ba-b831-02534daaa65f",
"name": "On False Larger",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-4320,
3220
]
},
{
"parameters": {
"conditions": {
"number": [
{
"value1": "={{ $json.value }}",
"operation": "largerEqual",
"value2": 1
}
]
}
},
"id": "e328bd99-269b-4f33-aed8-1d9c3289b0ec",
"name": "IF Larger or Equal",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-4760,
3400
]
},
{
"parameters": {},
"id": "e673c174-15b9-4992-b870-6ba127890e47",
"name": "On True Larger or Equal",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-4560,
3380
]
},
{
"parameters": {
"conditions": {
"number": [
{
"value1": "={{ $json.value }}",
"operation": "isEmpty"
}
]
}
},
"id": "d42fa33b-2f5e-4c20-a48a-0a9bec2ad847",
"name": "IF Is Empty",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-4760,
3600
]
},
{
"parameters": {},
"id": "c59fcd54-5b4f-4c68-9ead-8803ac1c9094",
"name": "On False Is Empty",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-4320,
3620
]
},
{
"parameters": {
"conditions": {
"number": [
{
"value1": "={{ $json.value }}",
"operation": "isNotEmpty"
}
]
}
},
"id": "c70d2625-996c-46a0-9c34-f2a1da4a29e5",
"name": "IF Is Not Empty",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-4760,
3780
]
},
{
"parameters": {},
"id": "2430fb5e-8d25-4b70-a517-753e1e32f579",
"name": "On True Is Not Empty",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-4560,
3760
]
}
],
"pinData": {
"On True Smaller": [
{
"json": {
"value": 1
}
}
],
"On False Smaller": [
{
"json": {
"value": 2
}
}
],
"On True Smaller or Equal": [
{
"json": {
"value": 1
}
},
{
"json": {
"value": 2
}
}
],
"On True Equal": [
{
"json": {
"value": 1
}
}
],
"On False Equal": [
{
"json": {
"value": 2
}
}
],
"On True Not Equal": [
{
"json": {
"value": 2
}
}
],
"On False Not Equal": [
{
"json": {
"value": 1
}
}
],
"On True Larger": [
{
"json": {
"value": 2
}
}
],
"On False Larger": [
{
"json": {
"value": 1
}
}
],
"On True Larger or Equal": [
{
"json": {
"value": 1
}
},
{
"json": {
"value": 2
}
}
],
"On False Is Empty": [
{
"json": {
"value": 1
}
},
{
"json": {
"value": 2
}
}
],
"On True Is Not Empty": [
{
"json": {
"value": 1
}
},
{
"json": {
"value": 2
}
}
]
},
"connections": {
"On clicking 'execute'": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"Code": {
"main": [
[
{
"node": "IF Smaller",
"type": "main",
"index": 0
},
{
"node": "IF Smaller or Equal",
"type": "main",
"index": 0
},
{
"node": "IF Equal",
"type": "main",
"index": 0
},
{
"node": "IF Not Equal",
"type": "main",
"index": 0
},
{
"node": "IF Larger",
"type": "main",
"index": 0
},
{
"node": "IF Larger or Equal",
"type": "main",
"index": 0
},
{
"node": "IF Is Empty",
"type": "main",
"index": 0
},
{
"node": "IF Is Not Empty",
"type": "main",
"index": 0
}
]
]
},
"IF Smaller": {
"main": [
[
{
"node": "On True Smaller",
"type": "main",
"index": 0
}
],
[
{
"node": "On False Smaller",
"type": "main",
"index": 0
}
]
]
},
"IF Smaller or Equal": {
"main": [
[
{
"node": "On True Smaller or Equal",
"type": "main",
"index": 0
}
]
]
},
"IF Equal": {
"main": [
[
{
"node": "On True Equal",
"type": "main",
"index": 0
}
],
[
{
"node": "On False Equal",
"type": "main",
"index": 0
}
]
]
},
"IF Not Equal": {
"main": [
[
{
"node": "On True Not Equal",
"type": "main",
"index": 0
}
],
[
{
"node": "On False Not Equal",
"type": "main",
"index": 0
}
]
]
},
"IF Larger": {
"main": [
[
{
"node": "On True Larger",
"type": "main",
"index": 0
}
],
[
{
"node": "On False Larger",
"type": "main",
"index": 0
}
]
]
},
"IF Larger or Equal": {
"main": [
[
{
"node": "On True Larger or Equal",
"type": "main",
"index": 0
}
]
]
},
"IF Is Empty": {
"main": [
[],
[
{
"node": "On False Is Empty",
"type": "main",
"index": 0
}
]
]
},
"IF Is Not Empty": {
"main": [
[
{
"node": "On True Is Not Empty",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {},
"versionId": "ec60bcbc-afef-4aae-91e2-65ffef88234b",
"id": "181",
"meta": {
"instanceId": "104a4d08d8897b8bdeb38aaca515021075e0bd8544c983c2bb8c86e6a8e6081c"
},
"tags": []
}

View file

@ -0,0 +1,976 @@
{
"name": "If node unit tests",
"nodes": [
{
"parameters": {},
"id": "38a682ce-6cde-4f90-bfd0-a80c61e2b22d",
"name": "On clicking 'execute'",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
-3120,
600
]
},
{
"parameters": {
"jsCode": "return [\n { name: \"Elon Musk\" },\n { name: \"Arnold Schwarzenegger\"},\n];"
},
"id": "a35687af-99c1-43b2-aa43-955fcd87ff81",
"name": "Code",
"type": "n8n-nodes-base.code",
"typeVersion": 1,
"position": [
-2920,
600
]
},
{
"parameters": {},
"id": "466a0b11-7826-4ba9-9563-9ac5d6d08457",
"name": "On True",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2460,
-500
]
},
{
"parameters": {},
"id": "91363030-4550-4ee2-9dea-f3adad8c1190",
"name": "On False",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2220,
-460
]
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json.name }}",
"operation": "contains",
"value2": "Elon"
}
]
}
},
"id": "93db20a4-9781-4de1-a298-87e885a21f31",
"name": "IF Contains",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-2660,
-480
]
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json.name }}",
"operation": "notContains",
"value2": "Elon"
}
]
}
},
"id": "9f286ba6-f2a6-4aa1-895a-65992c1d5eae",
"name": "IF Not Contains",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-2660,
-300
]
},
{
"parameters": {},
"id": "45be466f-da36-40da-993c-fb6f3de313e2",
"name": "On True Contains",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2460,
-320
]
},
{
"parameters": {},
"id": "578dc9f0-0224-475e-89bb-af8b474c5d4e",
"name": "On False Contains",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2220,
-280
]
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json.name }}",
"operation": "endsWith",
"value2": "Musk"
}
]
}
},
"id": "715f2210-7dd0-47e9-bcd7-3a62728d993e",
"name": "IF Ends With",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-2660,
-120
]
},
{
"parameters": {},
"id": "847291c1-3040-4289-a8f9-a23e82b8ff85",
"name": "On True Ends With",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2460,
-140
]
},
{
"parameters": {},
"id": "bb312b9d-5bda-4869-a790-932a85374bf1",
"name": "On False Ends With",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2220,
-100
]
},
{
"parameters": {},
"id": "1f507ed5-1602-40c0-ba3d-7b0095f1c346",
"name": "On True Not Ends With",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2460,
20
]
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json.name }}",
"operation": "notEndsWith",
"value2": "Musk"
}
]
}
},
"id": "c9423daa-de29-4f05-9dde-5b90006fe1a0",
"name": "IF Not Ends With",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-2660,
40
]
},
{
"parameters": {},
"id": "ad89d258-3fc4-4f96-93f4-0c4c4d0b4aca",
"name": "On False Not Ends With",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2220,
60
]
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json.name }}",
"value2": "Elon Musk"
}
]
}
},
"id": "ac91ef56-3bab-42db-b800-13f53be03a43",
"name": "IF Equal",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-2660,
240
]
},
{
"parameters": {},
"id": "db00d63e-0e74-4d89-a8f4-4de3492fe5e6",
"name": "On True Equal",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2460,
220
]
},
{
"parameters": {},
"id": "3314da40-e56a-4a6b-932e-8a31335f2535",
"name": "On False Equal",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2220,
260
]
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json.name }}",
"operation": "notEqual",
"value2": "Elon Musk"
}
]
}
},
"id": "765195fc-6cba-4918-89b8-ad5ca456e89e",
"name": "IF Not Equal",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-2660,
420
]
},
{
"parameters": {},
"id": "e720d65f-13f5-4888-ab14-8b022b2fc08e",
"name": "On True Not Equal",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2460,
400
]
},
{
"parameters": {},
"id": "f14a2032-b734-4f40-84a3-42426eec932e",
"name": "On False Not Equal",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2220,
440
]
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json.name }}",
"operation": "regex",
"value2": "([E])"
}
]
}
},
"id": "caa56347-323c-4671-abae-71a0d6586315",
"name": "IF Regex",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-2660,
600
]
},
{
"parameters": {},
"id": "5a83ee44-5b71-472d-8a6c-ee3fddd78482",
"name": "On True Regex",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2460,
580
]
},
{
"parameters": {},
"id": "a82388fc-6b93-4327-bb99-da6b0b0824cd",
"name": "On False Regex",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2220,
620
]
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json.name }}",
"operation": "notRegex",
"value2": "([E])"
}
]
}
},
"id": "6139ed77-889d-4b89-8c2f-c26601ffb54a",
"name": "IF Not Regex",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-2660,
780
]
},
{
"parameters": {},
"id": "f61258e3-44aa-4fd5-9602-a135ad4a8e6b",
"name": "On True Not Regex",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2460,
760
]
},
{
"parameters": {},
"id": "d547895d-5dd2-4fba-9076-dbd21db7559d",
"name": "On False Not Regex",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2220,
800
]
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json.name }}",
"operation": "startsWith",
"value2": "Elon"
}
]
}
},
"id": "45ea72ae-6ee0-492f-9f6c-237b95c5516f",
"name": "IF Starts With",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-2660,
980
]
},
{
"parameters": {},
"id": "7102319b-10d2-46af-a04f-84dcee678038",
"name": "On True Starts With",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2460,
960
]
},
{
"parameters": {},
"id": "1f986310-a6b1-40a5-aff3-c595b414c3cd",
"name": "On False Starts With",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2220,
1000
]
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json.name }}",
"operation": "notStartsWith",
"value2": "Elon"
}
]
}
},
"id": "16513014-99f8-4d36-b5ef-1c8c28aa1d1d",
"name": "IF Not Starts With",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-2660,
1180
]
},
{
"parameters": {},
"id": "31b15c96-9075-4892-baa1-683d7ce802d1",
"name": "On True Not Starts With",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2460,
1160
]
},
{
"parameters": {},
"id": "33786edf-86af-4769-9fa2-f8ba78b67588",
"name": "On False Not Starts With",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2220,
1200
]
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json.name }}",
"operation": "isEmpty"
}
]
}
},
"id": "7e90e29c-186c-4c22-a7a9-e1a7a620a53f",
"name": "IF Is Empty",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-2660,
1380
]
},
{
"parameters": {},
"id": "adde8115-8279-43e6-b5b3-211378ccb56a",
"name": "On False Is Empty",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2220,
1400
]
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json.name }}",
"operation": "isNotEmpty"
}
]
}
},
"id": "2e0f102e-b1a0-42c3-a523-47095233b357",
"name": "IF Is Not Empty",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-2660,
1560
]
},
{
"parameters": {},
"id": "37a9085f-89e0-4b15-93a9-69f583330f2b",
"name": "On True Is Not Empty",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
-2460,
1540
]
}
],
"pinData": {
"On True": [
{
"json": {
"name": "Elon Musk"
}
}
],
"On False": [
{
"json": {
"name": "Arnold Schwarzenegger"
}
}
],
"On True Contains": [
{
"json": {
"name": "Arnold Schwarzenegger"
}
}
],
"On False Contains": [
{
"json": {
"name": "Elon Musk"
}
}
],
"On True Ends With": [
{
"json": {
"name": "Elon Musk"
}
}
],
"On False Ends With": [
{
"json": {
"name": "Arnold Schwarzenegger"
}
}
],
"On True Not Ends With": [
{
"json": {
"name": "Arnold Schwarzenegger"
}
}
],
"On False Not Ends With": [
{
"json": {
"name": "Elon Musk"
}
}
],
"On True Equal": [
{
"json": {
"name": "Elon Musk"
}
}
],
"On False Equal": [
{
"json": {
"name": "Arnold Schwarzenegger"
}
}
],
"On True Not Equal": [
{
"json": {
"name": "Arnold Schwarzenegger"
}
}
],
"On False Not Equal": [
{
"json": {
"name": "Elon Musk"
}
}
],
"On True Regex": [
{
"json": {
"name": "Elon Musk"
}
}
],
"On False Regex": [
{
"json": {
"name": "Arnold Schwarzenegger"
}
}
],
"On True Not Regex": [
{
"json": {
"name": "Arnold Schwarzenegger"
}
}
],
"On False Not Regex": [
{
"json": {
"name": "Elon Musk"
}
}
],
"On True Starts With": [
{
"json": {
"name": "Elon Musk"
}
}
],
"On False Starts With": [
{
"json": {
"name": "Arnold Schwarzenegger"
}
}
],
"On True Not Starts With": [
{
"json": {
"name": "Arnold Schwarzenegger"
}
}
],
"On False Not Starts With": [
{
"json": {
"name": "Elon Musk"
}
}
],
"On False Is Empty": [
{
"json": {
"name": "Elon Musk"
}
},
{
"json": {
"name": "Arnold Schwarzenegger"
}
}
],
"On True Is Not Empty": [
{
"json": {
"name": "Elon Musk"
}
},
{
"json": {
"name": "Arnold Schwarzenegger"
}
}
]
},
"connections": {
"On clicking 'execute'": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"Code": {
"main": [
[
{
"node": "IF Contains",
"type": "main",
"index": 0
},
{
"node": "IF Not Contains",
"type": "main",
"index": 0
},
{
"node": "IF Ends With",
"type": "main",
"index": 0
},
{
"node": "IF Not Ends With",
"type": "main",
"index": 0
},
{
"node": "IF Equal",
"type": "main",
"index": 0
},
{
"node": "IF Not Equal",
"type": "main",
"index": 0
},
{
"node": "IF Regex",
"type": "main",
"index": 0
},
{
"node": "IF Not Regex",
"type": "main",
"index": 0
},
{
"node": "IF Starts With",
"type": "main",
"index": 0
},
{
"node": "IF Not Starts With",
"type": "main",
"index": 0
},
{
"node": "IF Is Empty",
"type": "main",
"index": 0
},
{
"node": "IF Is Not Empty",
"type": "main",
"index": 0
}
]
]
},
"IF Contains": {
"main": [
[
{
"node": "On True",
"type": "main",
"index": 0
}
],
[
{
"node": "On False",
"type": "main",
"index": 0
}
]
]
},
"IF Not Contains": {
"main": [
[
{
"node": "On True Contains",
"type": "main",
"index": 0
}
],
[
{
"node": "On False Contains",
"type": "main",
"index": 0
}
]
]
},
"IF Ends With": {
"main": [
[
{
"node": "On True Ends With",
"type": "main",
"index": 0
}
],
[
{
"node": "On False Ends With",
"type": "main",
"index": 0
}
]
]
},
"IF Not Ends With": {
"main": [
[
{
"node": "On True Not Ends With",
"type": "main",
"index": 0
}
],
[
{
"node": "On False Not Ends With",
"type": "main",
"index": 0
}
]
]
},
"IF Equal": {
"main": [
[
{
"node": "On True Equal",
"type": "main",
"index": 0
}
],
[
{
"node": "On False Equal",
"type": "main",
"index": 0
}
]
]
},
"IF Not Equal": {
"main": [
[
{
"node": "On True Not Equal",
"type": "main",
"index": 0
}
],
[
{
"node": "On False Not Equal",
"type": "main",
"index": 0
}
]
]
},
"IF Regex": {
"main": [
[
{
"node": "On True Regex",
"type": "main",
"index": 0
}
],
[
{
"node": "On False Regex",
"type": "main",
"index": 0
}
]
]
},
"IF Not Regex": {
"main": [
[
{
"node": "On True Not Regex",
"type": "main",
"index": 0
}
],
[
{
"node": "On False Not Regex",
"type": "main",
"index": 0
}
]
]
},
"IF Starts With": {
"main": [
[
{
"node": "On True Starts With",
"type": "main",
"index": 0
}
],
[
{
"node": "On False Starts With",
"type": "main",
"index": 0
}
]
]
},
"IF Not Starts With": {
"main": [
[
{
"node": "On True Not Starts With",
"type": "main",
"index": 0
}
],
[
{
"node": "On False Not Starts With",
"type": "main",
"index": 0
}
]
]
},
"IF Is Empty": {
"main": [
[],
[
{
"node": "On False Is Empty",
"type": "main",
"index": 0
}
]
]
},
"IF Is Not Empty": {
"main": [
[
{
"node": "On True Is Not Empty",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {},
"versionId": "76683cf0-dd49-4220-b196-88d8b37c7207",
"id": "181",
"meta": {
"instanceId": "104a4d08d8897b8bdeb38aaca515021075e0bd8544c983c2bb8c86e6a8e6081c"
},
"tags": []
}

View file

@ -0,0 +1,5 @@
import { testWorkflows, getWorkflowFilenames } from '../../../test/nodes/Helpers';
const workflows = getWorkflowFilenames(__dirname);
describe('Test IF Node', () => testWorkflows(workflows));

View file

@ -1,49 +0,0 @@
import * as Helpers from '../Helpers';
import { WorkflowTestData } from '../types';
import { executeWorkflow } from '../ExecuteWorkflow';
describe('Execute If Node', () => {
const tests: Array<WorkflowTestData> = [
{
description: 'should execute IF node true/false boolean',
input: {
workflowData: Helpers.readJsonFileSync('test/nodes/If/workflow.json'),
},
output: {
nodeData: {
'On True': [
[
{
value: true,
},
],
],
'On False': [
[
{
value: false,
},
],
],
},
},
},
];
const nodeTypes = Helpers.setup(tests);
for (const testData of tests) {
test(testData.description, async () => {
// execute workflow
const { result } = await executeWorkflow(testData, nodeTypes);
// check if result node data matches expected test data
const resultNodeData = Helpers.getResultNodeData(result, testData);
resultNodeData.forEach(({ nodeName, resultData }) =>
expect(resultData).toEqual(testData.output.nodeData[nodeName]),
);
expect(result.finished).toEqual(true);
});
}
});

View file

@ -1,115 +0,0 @@
{
"meta": {
"instanceId": "104a4d08d8897b8bdeb38aaca515021075e0bd8544c983c2bb8c86e6a8e6081c"
},
"nodes": [
{
"parameters": {},
"id": "47003824-c11f-4ae3-80a5-0e1a6d840b21",
"name": "On clicking 'execute'",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
720,
460
]
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{ $json[\"value\"] }}",
"value2": true
}
]
}
},
"id": "5420fe7d-a216-44e0-b91f-188ba5b6a340",
"name": "IF",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
1160,
460
]
},
{
"parameters": {},
"id": "52d58f32-7faf-4874-afff-e6842bd02430",
"name": "On False",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
1400,
580
]
},
{
"parameters": {},
"id": "9be683ac-cd3f-4ba1-8fa4-052102c3d891",
"name": "On True",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
1400,
340
]
},
{
"parameters": {
"jsCode": "return [\n { value: true },\n { value: false }\n];"
},
"id": "5b3207e7-37e3-43c8-a4da-1ffebb0de134",
"name": "Code",
"type": "n8n-nodes-base.code",
"typeVersion": 1,
"position": [
940,
460
]
}
],
"connections": {
"On clicking 'execute'": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"IF": {
"main": [
[
{
"node": "On True",
"type": "main",
"index": 0
}
],
[
{
"node": "On False",
"type": "main",
"index": 0
}
]
]
},
"Code": {
"main": [
[
{
"node": "IF",
"type": "main",
"index": 0
}
]
]
}
}
}