diff --git a/packages/nodes-base/nodes/Phantombuster/Phantombuster.node.ts b/packages/nodes-base/nodes/Phantombuster/Phantombuster.node.ts index c0dc784e137..4739e0e58c1 100644 --- a/packages/nodes-base/nodes/Phantombuster/Phantombuster.node.ts +++ b/packages/nodes-base/nodes/Phantombuster/Phantombuster.node.ts @@ -216,19 +216,31 @@ export class Phantombuster implements INodeType { const argumentParameters = ((additionalFields.argumentsUi as IDataObject)?.argumentValues as IDataObject[]) || []; - body.arguments = argumentParameters.reduce((object, currentValue) => { + + const argumentsObj = argumentParameters.reduce((object, currentValue) => { object[currentValue.key as string] = currentValue.value; return object; }, {}); + + // Only set arguments if not empty as per API requirements + if (Object.keys(argumentsObj).length > 0) { + body.arguments = argumentsObj; + } delete additionalFields.argumentsUi; const bonusParameters = ((additionalFields.bonusArgumentUi as IDataObject) ?.bonusArgumentValue as IDataObject[]) || []; - body.bonusArgument = bonusParameters.reduce((object, currentValue) => { + + const bonusArgumentObj = bonusParameters.reduce((object, currentValue) => { object[currentValue.key as string] = currentValue.value; return object; }, {}); + + // Only set bonusArgument if not empty as per API requirements + if (Object.keys(bonusArgumentObj).length > 0) { + body.bonusArgument = bonusArgumentObj; + } delete additionalFields.bonusArgumentUi; } diff --git a/packages/nodes-base/nodes/Phantombuster/test/Phantombuster.node.test.ts b/packages/nodes-base/nodes/Phantombuster/test/Phantombuster.node.test.ts new file mode 100644 index 00000000000..519c89b2868 --- /dev/null +++ b/packages/nodes-base/nodes/Phantombuster/test/Phantombuster.node.test.ts @@ -0,0 +1,95 @@ +import { NodeTestHarness } from '@nodes-testing/node-test-harness'; +import nock from 'nock'; + +describe('Phantombuster Node', () => { + const credentials = { + phantombusterApi: { + apiKey: 'test-api-key', + }, + }; + + describe('Launch Agent Without Arguments', () => { + beforeAll(() => { + const mock = nock('https://api.phantombuster.com'); + + mock + .post('/api/v2/agents/launch', (body) => { + return body.id === 'test-agent-123' && !body.arguments && !body.bonusArgument; + }) + .reply(200, { containerId: 'container-456' }); + }); + + new NodeTestHarness().setupTests({ + credentials, + workflowFiles: ['launch-without-arguments.workflow.json'], + }); + }); + + describe('Launch Agent With Arguments No Bonus', () => { + beforeAll(() => { + const mock = nock('https://api.phantombuster.com'); + + mock + .post('/api/v2/agents/launch', (body) => { + return ( + body.id === 'test-agent-123' && + body.arguments && + body.arguments.testKey === 'testValue' && + !body.bonusArgument + ); + }) + .reply(200, { containerId: 'container-456' }); + }); + + new NodeTestHarness().setupTests({ + credentials, + workflowFiles: ['launch-with-arguments-no-bonus.workflow.json'], + }); + }); + + describe('Launch Agent With Bonus Arguments', () => { + beforeAll(() => { + const mock = nock('https://api.phantombuster.com'); + + mock + .post('/api/v2/agents/launch', (body) => { + return ( + body.id === 'test-agent-123' && + body.arguments && + body.arguments.testKey === 'testValue' && + body.bonusArgument && + body.bonusArgument.bonusKey === 'bonusValue' + ); + }) + .reply(200, { containerId: 'container-456' }); + }); + + new NodeTestHarness().setupTests({ + credentials, + workflowFiles: ['launch-with-bonus-arguments.workflow.json'], + }); + }); + + describe('Launch Agent With JSON Arguments', () => { + beforeAll(() => { + const mock = nock('https://api.phantombuster.com'); + + mock + .post('/api/v2/agents/launch', (body) => { + return ( + body.id === 'test-agent-123' && + body.arguments && + body.arguments.complexKey === 'complexValue' && + body.arguments.nestedObject && + body.arguments.nestedObject.nested === 'value' + ); + }) + .reply(200, { containerId: 'container-456' }); + }); + + new NodeTestHarness().setupTests({ + credentials, + workflowFiles: ['launch-with-json-arguments.workflow.json'], + }); + }); +}); diff --git a/packages/nodes-base/nodes/Phantombuster/test/launch-with-arguments-no-bonus.workflow.json b/packages/nodes-base/nodes/Phantombuster/test/launch-with-arguments-no-bonus.workflow.json new file mode 100644 index 00000000000..bbc1112bcc9 --- /dev/null +++ b/packages/nodes-base/nodes/Phantombuster/test/launch-with-arguments-no-bonus.workflow.json @@ -0,0 +1,69 @@ +{ + "name": "Phantombuster Launch With Arguments No Bonus Test", + "nodes": [ + { + "parameters": {}, + "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", + "name": "When clicking 'Execute Workflow'", + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [0, 0] + }, + { + "parameters": { + "resource": "agent", + "operation": "launch", + "agentId": "test-agent-123", + "jsonParameters": false, + "resolveData": false, + "additionalFields": { + "argumentsUi": { + "argumentValues": [ + { + "key": "testKey", + "value": "testValue" + } + ] + } + } + }, + "id": "b2c3d4e5-f6a7-8901-bcde-f12345678901", + "name": "Phantombuster", + "type": "n8n-nodes-base.phantombuster", + "typeVersion": 1, + "position": [220, 0], + "credentials": { + "phantombusterApi": { + "id": "test-cred-id", + "name": "Phantombuster API" + } + } + } + ], + "pinData": { + "Phantombuster": [ + { + "json": { + "containerId": "container-456" + } + } + ] + }, + "connections": { + "When clicking 'Execute Workflow'": { + "main": [ + [ + { + "node": "Phantombuster", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + } +} diff --git a/packages/nodes-base/nodes/Phantombuster/test/launch-with-bonus-arguments.workflow.json b/packages/nodes-base/nodes/Phantombuster/test/launch-with-bonus-arguments.workflow.json new file mode 100644 index 00000000000..41a1afd0959 --- /dev/null +++ b/packages/nodes-base/nodes/Phantombuster/test/launch-with-bonus-arguments.workflow.json @@ -0,0 +1,77 @@ +{ + "name": "Phantombuster Launch With Bonus Arguments Test", + "nodes": [ + { + "parameters": {}, + "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", + "name": "When clicking 'Execute Workflow'", + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [0, 0] + }, + { + "parameters": { + "resource": "agent", + "operation": "launch", + "agentId": "test-agent-123", + "jsonParameters": false, + "resolveData": false, + "additionalFields": { + "argumentsUi": { + "argumentValues": [ + { + "key": "testKey", + "value": "testValue" + } + ] + }, + "bonusArgumentUi": { + "bonusArgumentValue": [ + { + "key": "bonusKey", + "value": "bonusValue" + } + ] + } + } + }, + "id": "b2c3d4e5-f6a7-8901-bcde-f12345678901", + "name": "Phantombuster", + "type": "n8n-nodes-base.phantombuster", + "typeVersion": 1, + "position": [220, 0], + "credentials": { + "phantombusterApi": { + "id": "test-cred-id", + "name": "Phantombuster API" + } + } + } + ], + "pinData": { + "Phantombuster": [ + { + "json": { + "containerId": "container-456" + } + } + ] + }, + "connections": { + "When clicking 'Execute Workflow'": { + "main": [ + [ + { + "node": "Phantombuster", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + } +} diff --git a/packages/nodes-base/nodes/Phantombuster/test/launch-with-json-arguments.workflow.json b/packages/nodes-base/nodes/Phantombuster/test/launch-with-json-arguments.workflow.json new file mode 100644 index 00000000000..243b8eb2f39 --- /dev/null +++ b/packages/nodes-base/nodes/Phantombuster/test/launch-with-json-arguments.workflow.json @@ -0,0 +1,62 @@ +{ + "name": "Phantombuster Launch With JSON Arguments Test", + "nodes": [ + { + "parameters": {}, + "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", + "name": "When clicking 'Execute Workflow'", + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [0, 0] + }, + { + "parameters": { + "resource": "agent", + "operation": "launch", + "agentId": "test-agent-123", + "jsonParameters": true, + "resolveData": false, + "additionalFields": { + "argumentsJson": "{\"complexKey\":\"complexValue\",\"nestedObject\":{\"nested\":\"value\"}}" + } + }, + "id": "b2c3d4e5-f6a7-8901-bcde-f12345678901", + "name": "Phantombuster", + "type": "n8n-nodes-base.phantombuster", + "typeVersion": 1, + "position": [220, 0], + "credentials": { + "phantombusterApi": { + "id": "test-cred-id", + "name": "Phantombuster API" + } + } + } + ], + "pinData": { + "Phantombuster": [ + { + "json": { + "containerId": "container-456" + } + } + ] + }, + "connections": { + "When clicking 'Execute Workflow'": { + "main": [ + [ + { + "node": "Phantombuster", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + } +} diff --git a/packages/nodes-base/nodes/Phantombuster/test/launch-without-arguments.workflow.json b/packages/nodes-base/nodes/Phantombuster/test/launch-without-arguments.workflow.json new file mode 100644 index 00000000000..4b54542770c --- /dev/null +++ b/packages/nodes-base/nodes/Phantombuster/test/launch-without-arguments.workflow.json @@ -0,0 +1,59 @@ +{ + "name": "Phantombuster Launch Without Arguments Test", + "nodes": [ + { + "parameters": {}, + "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", + "name": "When clicking 'Execute Workflow'", + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [0, 0] + }, + { + "parameters": { + "resource": "agent", + "operation": "launch", + "agentId": "test-agent-123", + "jsonParameters": false, + "resolveData": false + }, + "id": "b2c3d4e5-f6a7-8901-bcde-f12345678901", + "name": "Phantombuster", + "type": "n8n-nodes-base.phantombuster", + "typeVersion": 1, + "position": [220, 0], + "credentials": { + "phantombusterApi": { + "id": "test-cred-id", + "name": "Phantombuster API" + } + } + } + ], + "pinData": { + "Phantombuster": [ + { + "json": { + "containerId": "container-456" + } + } + ] + }, + "connections": { + "When clicking 'Execute Workflow'": { + "main": [ + [ + { + "node": "Phantombuster", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": { + "executionOrder": "v1" + } +}