From 528c07134a6705c8c7a5378f15f5e4a4b93234a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Thu, 1 Feb 2024 18:05:23 +0100 Subject: [PATCH] fix(core): Fix test runs of triggers that rely on static data (#8524) --- packages/cli/src/TestWebhooks.ts | 13 ++++--------- packages/workflow/src/Workflow.ts | 8 ++++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/cli/src/TestWebhooks.ts b/packages/cli/src/TestWebhooks.ts index fef109cb92..b51d38deb8 100644 --- a/packages/cli/src/TestWebhooks.ts +++ b/packages/cli/src/TestWebhooks.ts @@ -91,10 +91,12 @@ export class TestWebhooks implements IWebhookManager { }); } - const { destinationNode, sessionId, workflowEntity } = registration; + const { destinationNode, sessionId, workflowEntity, webhook: testWebhook } = registration; const workflow = this.toWorkflow(workflowEntity); + if (testWebhook.staticData) workflow.setTestStaticData(testWebhook.staticData); + const workflowStartNode = workflow.getNode(webhook.node); if (workflowStartNode === null) { @@ -405,14 +407,7 @@ export class TestWebhooks implements IWebhookManager { connections: workflowEntity.connections, active: false, nodeTypes: this.nodeTypes, - - /** - * `staticData` in the original workflow entity has production webhook IDs. - * Since we are creating here a temporary workflow only for a test webhook, - * `staticData` from the original workflow entity should not be transferred. - */ - staticData: undefined, - + staticData: {}, settings: workflowEntity.settings, }); } diff --git a/packages/workflow/src/Workflow.ts b/packages/workflow/src/Workflow.ts index 65d72a9dcb..0411db82b7 100644 --- a/packages/workflow/src/Workflow.ts +++ b/packages/workflow/src/Workflow.ts @@ -81,6 +81,8 @@ export class Workflow { // ids of registered webhooks of nodes staticData: IDataObject; + testStaticData: IDataObject | undefined; + pinData?: IPinData; // constructor(id: string | undefined, nodes: INode[], connections: IConnections, active: boolean, nodeTypes: INodeTypes, staticData?: IDataObject, settings?: IWorkflowSettings) { @@ -328,6 +330,8 @@ export class Workflow { }); } + if (this.testStaticData?.[key]) return this.testStaticData[key] as IDataObject; + if (this.staticData[key] === undefined) { // Create it as ObservableObject that we can easily check if the data changed // to know if the workflow with its data has to be saved afterwards or not. @@ -337,6 +341,10 @@ export class Workflow { return this.staticData[key] as IDataObject; } + setTestStaticData(testStaticData: IDataObject) { + this.testStaticData = testStaticData; + } + /** * Returns all the trigger nodes in the workflow. *