🐛 Fix Test-Webhook registration issues

This commit is contained in:
Jan Oberhauser
2020-09-16 23:55:34 +02:00
parent 1a411ebef7
commit 2fee4396f1
2 changed files with 13 additions and 18 deletions

View File

@@ -317,6 +317,8 @@ export class ActiveWorkflowRunner {
await workflow.runWebhookMethod('delete', webhookData, NodeExecuteFunctions, mode, false); await workflow.runWebhookMethod('delete', webhookData, NodeExecuteFunctions, mode, false);
} }
await WorkflowHelpers.saveStaticData(workflow);
// if it's a mongo objectId convert it to string // if it's a mongo objectId convert it to string
if (typeof workflowData.id === 'object') { if (typeof workflowData.id === 'object') {
workflowData.id = workflowData.id.toString(); workflowData.id = workflowData.id.toString();

View File

@@ -3,11 +3,9 @@ import * as express from 'express';
import { import {
IResponseCallbackData, IResponseCallbackData,
IWorkflowDb, IWorkflowDb,
NodeTypes,
Push, Push,
ResponseHelper, ResponseHelper,
WebhookHelpers, WebhookHelpers,
WorkflowHelpers,
} from './'; } from './';
import { import {
@@ -31,6 +29,7 @@ export class TestWebhooks {
sessionId?: string; sessionId?: string;
timeout: NodeJS.Timeout, timeout: NodeJS.Timeout,
workflowData: IWorkflowDb; workflowData: IWorkflowDb;
workflow: Workflow;
}; };
} = {}; } = {};
private activeWebhooks: ActiveWebhooks | null = null; private activeWebhooks: ActiveWebhooks | null = null;
@@ -64,10 +63,13 @@ export class TestWebhooks {
const webhookKey = this.activeWebhooks!.getWebhookKey(webhookData.httpMethod, webhookData.path); const webhookKey = this.activeWebhooks!.getWebhookKey(webhookData.httpMethod, webhookData.path);
const workflowData = this.testWebhookData[webhookKey].workflowData; // TODO: Clean that duplication up one day and improve code generally
if (this.testWebhookData[webhookKey] === undefined) {
// The requested webhook is not registered
throw new ResponseHelper.ResponseError(`The requested webhook "${httpMethod} ${path}" is not registered.`, 404, 404);
}
const nodeTypes = NodeTypes(); const workflow = this.testWebhookData[webhookKey].workflow;
const workflow = new Workflow({ id: webhookData.workflowId, name: workflowData.name, nodes: workflowData.nodes, connections: workflowData.connections, active: workflowData.active, nodeTypes, staticData: workflowData.staticData, settings: workflowData.settings});
// Get the node which has the webhook defined to know where to start from and to // Get the node which has the webhook defined to know where to start from and to
// get additional data // get additional data
@@ -157,16 +159,14 @@ export class TestWebhooks {
for (const webhookData of webhooks) { for (const webhookData of webhooks) {
key = this.activeWebhooks!.getWebhookKey(webhookData.httpMethod, webhookData.path); key = this.activeWebhooks!.getWebhookKey(webhookData.httpMethod, webhookData.path);
await this.activeWebhooks!.add(workflow, webhookData, mode);
this.testWebhookData[key] = { this.testWebhookData[key] = {
sessionId, sessionId,
timeout, timeout,
workflow,
workflowData, workflowData,
}; };
// Save static data! await this.activeWebhooks!.add(workflow, webhookData, mode);
this.testWebhookData[key].workflowData.staticData = workflow.staticData;
} }
return true; return true;
@@ -181,8 +181,6 @@ export class TestWebhooks {
* @memberof TestWebhooks * @memberof TestWebhooks
*/ */
cancelTestWebhook(workflowId: string): boolean { cancelTestWebhook(workflowId: string): boolean {
const nodeTypes = NodeTypes();
let foundWebhook = false; let foundWebhook = false;
for (const webhookKey of Object.keys(this.testWebhookData)) { for (const webhookKey of Object.keys(this.testWebhookData)) {
const webhookData = this.testWebhookData[webhookKey]; const webhookData = this.testWebhookData[webhookKey];
@@ -205,8 +203,7 @@ export class TestWebhooks {
} }
} }
const workflowData = webhookData.workflowData; const workflow = this.testWebhookData[webhookKey].workflow;
const workflow = new Workflow({ id: workflowData.id.toString(), name: workflowData.name, nodes: workflowData.nodes, connections: workflowData.connections, active: workflowData.active, nodeTypes, staticData: workflowData.staticData, settings: workflowData.settings });
// Remove the webhook // Remove the webhook
delete this.testWebhookData[webhookKey]; delete this.testWebhookData[webhookKey];
@@ -225,14 +222,10 @@ export class TestWebhooks {
return; return;
} }
const nodeTypes = NodeTypes();
let workflowData: IWorkflowDb;
let workflow: Workflow; let workflow: Workflow;
const workflows: Workflow[] = []; const workflows: Workflow[] = [];
for (const webhookKey of Object.keys(this.testWebhookData)) { for (const webhookKey of Object.keys(this.testWebhookData)) {
workflowData = this.testWebhookData[webhookKey].workflowData; workflow = this.testWebhookData[webhookKey].workflow;
workflow = new Workflow({ id: workflowData.id.toString(), name: workflowData.name, nodes: workflowData.nodes, connections: workflowData.connections, active: workflowData.active, nodeTypes, staticData: workflowData.staticData, settings: workflowData.settings });
workflows.push(workflow); workflows.push(workflow);
} }