refactor(core): Improve test-webhooks (no-changelog) (#8069)

Remove duplication, improve readability, and expand tests for
`TestWebhooks.ts` - in anticipation for storing test webhooks in Redis.

---------

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Iván Ovejero
2023-12-19 17:32:02 +01:00
committed by GitHub
parent 38d1336fa7
commit 9dc491c3a5
14 changed files with 486 additions and 416 deletions

View File

@@ -60,7 +60,7 @@ import { WorkflowRunner } from '@/WorkflowRunner';
import { ExternalHooks } from '@/ExternalHooks';
import { whereClause } from './UserManagement/UserManagementHelper';
import { WorkflowService } from './workflows/workflow.service';
import { webhookNotFoundErrorMessage } from './utils';
import { WebhookNotFoundError } from './errors/response-errors/webhook-not-found.error';
import { In } from 'typeorm';
import { WebhookService } from './services/webhook.service';
import { Logger } from './Logger';
@@ -71,9 +71,6 @@ import { ActivationErrorsService } from '@/ActivationErrors.service';
import type { Scope } from '@n8n/permissions';
import { NotFoundError } from './errors/response-errors/not-found.error';
const WEBHOOK_PROD_UNREGISTERED_HINT =
"The workflow must be active for a production URL to run successfully. You can activate the workflow using the toggle in the top-right of the editor. Note that unlike test URL calls, production URL calls aren't shown on the canvas (only in the executions list)";
@Service()
export class ActiveWorkflowRunner implements IWebhookManager {
activeWorkflows = new ActiveWorkflows();
@@ -256,10 +253,7 @@ export class ActiveWorkflowRunner implements IWebhookManager {
const webhook = await this.webhookService.findWebhook(httpMethod, path);
if (webhook === null) {
throw new NotFoundError(
webhookNotFoundErrorMessage(path, httpMethod),
WEBHOOK_PROD_UNREGISTERED_HINT,
);
throw new WebhookNotFoundError({ path, httpMethod }, { hint: 'production' });
}
return webhook;
@@ -383,7 +377,6 @@ export class ActiveWorkflowRunner implements IWebhookManager {
NodeExecuteFunctions,
mode,
activation,
false,
);
} catch (error) {
if (activation === 'init' && error.name === 'QueryFailedError') {
@@ -455,7 +448,7 @@ export class ActiveWorkflowRunner implements IWebhookManager {
const webhooks = WebhookHelpers.getWorkflowWebhooks(workflow, additionalData, undefined, true);
for (const webhookData of webhooks) {
await workflow.deleteWebhook(webhookData, NodeExecuteFunctions, mode, 'update', false);
await workflow.deleteWebhook(webhookData, NodeExecuteFunctions, mode, 'update');
}
await Container.get(WorkflowService).saveStaticData(workflow);