Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Fix test runs of triggers that rely on static data #8524

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions packages/cli/src/TestWebhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
});
}
Expand Down
8 changes: 8 additions & 0 deletions packages/workflow/src/Workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand All @@ -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.
*
Expand Down
Loading