From 1391bf39c6988c17b452ba978bab99131bbdacdc Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Mon, 10 Feb 2020 17:52:15 -0800 Subject: [PATCH] :zap: Make sure that Test-Webhooks use the current data not from DB --- packages/cli/src/TestWebhooks.ts | 33 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/packages/cli/src/TestWebhooks.ts b/packages/cli/src/TestWebhooks.ts index 8631f259ab..8c24f228b6 100644 --- a/packages/cli/src/TestWebhooks.ts +++ b/packages/cli/src/TestWebhooks.ts @@ -1,11 +1,6 @@ import * as express from 'express'; -import { - In as findIn, - FindManyOptions, -} from 'typeorm'; import { - Db, IResponseCallbackData, IWorkflowDb, NodeTypes, @@ -67,10 +62,9 @@ export class TestWebhooks { throw new ResponseHelper.ResponseError('The requested webhook is not registred.', 404, 404); } - const workflowData = await Db.collections.Workflow!.findOne(webhookData.workflowId); - if (workflowData === undefined) { - throw new ResponseHelper.ResponseError(`Could not find workflow with id "${webhookData.workflowId}"`, 404, 404); - } + const webhookKey = this.activeWebhooks!.getWebhookKey(webhookData.httpMethod, webhookData.path); + + const workflowData = this.testWebhookData[webhookKey].workflowData; const nodeTypes = NodeTypes(); const workflow = new Workflow(webhookData.workflowId, workflowData.nodes, workflowData.connections, workflowData.active, nodeTypes, workflowData.staticData, workflowData.settings); @@ -82,8 +76,6 @@ export class TestWebhooks { throw new ResponseHelper.ResponseError('Could not find node to process webhook.', 404, 404); } - const webhookKey = this.activeWebhooks!.getWebhookKey(webhookData.httpMethod, webhookData.path); - return new Promise(async (resolve, reject) => { try { const executionMode = 'manual'; @@ -206,19 +198,18 @@ export class TestWebhooks { if (this.activeWebhooks === null) { return; } + const nodeTypes = NodeTypes(); - const findQuery = { - where: { - id: findIn(this.activeWebhooks.getWorkflowIds()) - }, - } as FindManyOptions; - - const workflowsDb = await Db.collections.Workflow!.find(findQuery); + let workflowData: IWorkflowDb; + let workflow: Workflow; const workflows: Workflow[] = []; - for (const workflowData of workflowsDb) { - const workflow = new Workflow(workflowData.id.toString(), workflowData.nodes, workflowData.connections, workflowData.active, nodeTypes, workflowData.staticData, workflowData.settings); - workflows.push(workflow); + for (const webhookKey of Object.keys(this.testWebhookData)) { + console.log('webhookKey: ' + webhookKey); + + workflowData = this.testWebhookData[webhookKey].workflowData; + workflow = new Workflow(workflowData.id.toString(), workflowData.nodes, workflowData.connections, workflowData.active, nodeTypes, workflowData.staticData, workflowData.settings); + workflows.push(); } return this.activeWebhooks.removeAll(workflows);