mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
refactor(core): Tear down internal hooks (no-changelog) (#10340)
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { nanoid } from 'nanoid';
|
||||
|
||||
import { InternalHooks } from '@/InternalHooks';
|
||||
import { ImportCredentialsCommand } from '@/commands/import/credentials';
|
||||
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
|
||||
|
||||
@@ -11,7 +10,6 @@ import { getAllCredentials, getAllSharedCredentials } from '../shared/db/credent
|
||||
import { createMember, createOwner } from '../shared/db/users';
|
||||
import { getPersonalProject } from '../shared/db/projects';
|
||||
|
||||
mockInstance(InternalHooks);
|
||||
mockInstance(LoadNodesAndCredentials);
|
||||
const command = setupTestCommand(ImportCredentialsCommand);
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { nanoid } from 'nanoid';
|
||||
|
||||
import { InternalHooks } from '@/InternalHooks';
|
||||
import { ImportWorkflowsCommand } from '@/commands/import/workflow';
|
||||
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
|
||||
|
||||
@@ -11,7 +10,6 @@ import { getAllSharedWorkflows, getAllWorkflows } from '../shared/db/workflows';
|
||||
import { createMember, createOwner } from '../shared/db/users';
|
||||
import { getPersonalProject } from '../shared/db/projects';
|
||||
|
||||
mockInstance(InternalHooks);
|
||||
mockInstance(LoadNodesAndCredentials);
|
||||
const command = setupTestCommand(ImportWorkflowsCommand);
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import { EntityNotFoundError } from '@n8n/typeorm';
|
||||
|
||||
import { Reset } from '@/commands/ldap/reset';
|
||||
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
|
||||
import { InternalHooks } from '@/InternalHooks';
|
||||
import { WorkflowRepository } from '@db/repositories/workflow.repository';
|
||||
import { CredentialsRepository } from '@db/repositories/credentials.repository';
|
||||
import { SharedWorkflowRepository } from '@db/repositories/sharedWorkflow.repository';
|
||||
@@ -26,7 +25,6 @@ import { createTeamProject, findProject, getPersonalProject } from '../../shared
|
||||
mockInstance(Telemetry);
|
||||
|
||||
mockInstance(Push);
|
||||
mockInstance(InternalHooks);
|
||||
mockInstance(LoadNodesAndCredentials);
|
||||
const command = setupTestCommand(Reset);
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { InternalHooks } from '@/InternalHooks';
|
||||
import { License } from '@/License';
|
||||
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
|
||||
import { ClearLicenseCommand } from '@/commands/license/clear';
|
||||
@@ -6,7 +5,6 @@ import { ClearLicenseCommand } from '@/commands/license/clear';
|
||||
import { setupTestCommand } from '@test-integration/utils/testCommand';
|
||||
import { mockInstance } from '../../shared/mocking';
|
||||
|
||||
mockInstance(InternalHooks);
|
||||
mockInstance(LoadNodesAndCredentials);
|
||||
const license = mockInstance(License);
|
||||
const command = setupTestCommand(ClearLicenseCommand);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Container } from 'typedi';
|
||||
|
||||
import { Reset } from '@/commands/user-management/reset';
|
||||
import { InternalHooks } from '@/InternalHooks';
|
||||
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
|
||||
import { NodeTypes } from '@/NodeTypes';
|
||||
import { SharedWorkflowRepository } from '@db/repositories/sharedWorkflow.repository';
|
||||
@@ -20,7 +19,6 @@ import { getPersonalProject } from '../shared/db/projects';
|
||||
import { encryptCredentialData, saveCredential } from '../shared/db/credentials';
|
||||
import { randomCredentialPayload } from '../shared/random';
|
||||
|
||||
mockInstance(InternalHooks);
|
||||
mockInstance(LoadNodesAndCredentials);
|
||||
mockInstance(NodeTypes);
|
||||
const command = setupTestCommand(Reset);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { InternalHooks } from '@/InternalHooks';
|
||||
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
|
||||
import { UpdateWorkflowCommand } from '@/commands/update/workflow';
|
||||
|
||||
@@ -7,7 +6,6 @@ import * as testDb from '../../shared/testDb';
|
||||
import { createWorkflowWithTrigger, getAllWorkflows } from '../../shared/db/workflows';
|
||||
import { mockInstance } from '../../../shared/mocking';
|
||||
|
||||
mockInstance(InternalHooks);
|
||||
mockInstance(LoadNodesAndCredentials);
|
||||
const command = setupTestCommand(UpdateWorkflowCommand);
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import config from '@/config';
|
||||
import { ExternalSecretsManager } from '@/ExternalSecrets/ExternalSecretsManager.ee';
|
||||
import { MessageEventBus } from '@/eventbus/MessageEventBus/MessageEventBus';
|
||||
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
|
||||
import { InternalHooks } from '@/InternalHooks';
|
||||
import { OrchestrationHandlerWorkerService } from '@/services/orchestration/worker/orchestration.handler.worker.service';
|
||||
import { OrchestrationWorkerService } from '@/services/orchestration/worker/orchestration.worker.service';
|
||||
import { License } from '@/License';
|
||||
@@ -18,7 +17,6 @@ import { LogStreamingEventRelay } from '@/events/log-streaming-event-relay';
|
||||
|
||||
config.set('executions.mode', 'queue');
|
||||
config.set('binaryDataManager.availableModes', 'filesystem');
|
||||
mockInstance(InternalHooks);
|
||||
mockInstance(LoadNodesAndCredentials);
|
||||
const binaryDataService = mockInstance(BinaryDataService);
|
||||
const externalHooks = mockInstance(ExternalHooks);
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { mocked } from 'jest-mock';
|
||||
import Container from 'typedi';
|
||||
import { Not } from '@n8n/typeorm';
|
||||
|
||||
import { InternalHooks } from '@/InternalHooks';
|
||||
import { EventService } from '@/events/event.service';
|
||||
import { ExternalHooks } from '@/ExternalHooks';
|
||||
import { UserManagementMailer } from '@/UserManagement/email';
|
||||
import { UserRepository } from '@/databases/repositories/user.repository';
|
||||
@@ -31,7 +29,7 @@ import { ProjectRelationRepository } from '@/databases/repositories/projectRelat
|
||||
describe('InvitationController', () => {
|
||||
const mailer = mockInstance(UserManagementMailer);
|
||||
const externalHooks = mockInstance(ExternalHooks);
|
||||
const internalHooks = mockInstance(InternalHooks);
|
||||
const eventService = mockInstance(EventService);
|
||||
|
||||
const testServer = utils.setupTestServer({ endpointGroups: ['invitations'] });
|
||||
|
||||
@@ -413,14 +411,24 @@ describe('InvitationController', () => {
|
||||
expect(externalHookName).toBe('user.invited');
|
||||
expect(externalHookArg?.[0]).toStrictEqual([newUserEmail]);
|
||||
|
||||
// internal hooks
|
||||
|
||||
const calls = mocked(internalHooks).onUserTransactionalEmail.mock.calls;
|
||||
|
||||
for (const [onUserTransactionalEmailArg] of calls) {
|
||||
expect(onUserTransactionalEmailArg.user_id).toBeDefined();
|
||||
expect(onUserTransactionalEmailArg.message_type).toBe('New user invite');
|
||||
expect(onUserTransactionalEmailArg.public_api).toBe(false);
|
||||
for (const [eventName, payload] of eventService.emit.mock.calls) {
|
||||
if (eventName === 'user-invited') {
|
||||
expect(payload).toEqual({
|
||||
user: expect.objectContaining({ id: expect.any(String) }),
|
||||
targetUserId: expect.arrayContaining([expect.any(String), expect.any(String)]),
|
||||
publicApi: false,
|
||||
emailSent: true,
|
||||
inviteeRole: 'global:member',
|
||||
});
|
||||
} else if (eventName === 'user-transactional-email-sent') {
|
||||
expect(payload).toEqual({
|
||||
userId: expect.any(String),
|
||||
messageType: 'New user invite',
|
||||
publicApi: false,
|
||||
});
|
||||
} else {
|
||||
fail(`Unexpected event name: ${eventName}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@ import type { BaseCommand } from '@/commands/BaseCommand';
|
||||
import * as testDb from '../testDb';
|
||||
import { TelemetryEventRelay } from '@/events/telemetry-event-relay';
|
||||
import { mockInstance } from '@test/mocking';
|
||||
import { InternalHooks } from '@/InternalHooks';
|
||||
|
||||
mockInstance(InternalHooks);
|
||||
|
||||
export const setupTestCommand = <T extends BaseCommand>(Command: Class<T>) => {
|
||||
const config = mock<Config>();
|
||||
|
||||
@@ -14,7 +14,6 @@ import { PostHogClient } from '@/posthog';
|
||||
import { Push } from '@/push';
|
||||
import { License } from '@/License';
|
||||
import { Logger } from '@/Logger';
|
||||
import { InternalHooks } from '@/InternalHooks';
|
||||
import { AuthService } from '@/auth/auth.service';
|
||||
import type { APIRequest } from '@/requests';
|
||||
|
||||
@@ -82,7 +81,6 @@ export const setupTestServer = ({
|
||||
|
||||
// Mock all telemetry and logging
|
||||
mockInstance(Logger);
|
||||
mockInstance(InternalHooks);
|
||||
mockInstance(PostHogClient);
|
||||
mockInstance(Push);
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import type { INodeType, INodeTypeDescription, IWebhookFunctions } from 'n8n-wor
|
||||
|
||||
import { AbstractServer } from '@/AbstractServer';
|
||||
import { ExternalHooks } from '@/ExternalHooks';
|
||||
import { InternalHooks } from '@/InternalHooks';
|
||||
import { NodeTypes } from '@/NodeTypes';
|
||||
import { Push } from '@/push';
|
||||
import type { WorkflowEntity } from '@db/entities/WorkflowEntity';
|
||||
@@ -21,7 +20,6 @@ mockInstance(Telemetry);
|
||||
|
||||
describe('Webhook API', () => {
|
||||
mockInstance(ExternalHooks);
|
||||
mockInstance(InternalHooks);
|
||||
mockInstance(Push);
|
||||
|
||||
let agent: SuperAgentTest;
|
||||
|
||||
@@ -5,7 +5,6 @@ import { mock } from 'jest-mock-extended';
|
||||
import { AbstractServer } from '@/AbstractServer';
|
||||
import { ActiveWebhooks } from '@/webhooks/ActiveWebhooks';
|
||||
import { ExternalHooks } from '@/ExternalHooks';
|
||||
import { InternalHooks } from '@/InternalHooks';
|
||||
import { TestWebhooks } from '@/webhooks/TestWebhooks';
|
||||
import { WaitingWebhooks } from '@/webhooks/WaitingWebhooks';
|
||||
import { WaitingForms } from '@/WaitingForms';
|
||||
@@ -19,7 +18,6 @@ let agent: SuperAgentTest;
|
||||
|
||||
describe('WebhookServer', () => {
|
||||
mockInstance(ExternalHooks);
|
||||
mockInstance(InternalHooks);
|
||||
|
||||
describe('CORS', () => {
|
||||
const corsOrigin = 'https://example.com';
|
||||
|
||||
Reference in New Issue
Block a user