refactor(core): Move all code related to onServerStarted into InternalHooks (no-changelog) (#8500)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-01-31 13:29:17 +01:00
committed by GitHub
parent 0e9a5a2ab2
commit 839dd96c7d
4 changed files with 131 additions and 175 deletions

View File

@@ -1,67 +1,80 @@
import { Telemetry } from '@/telemetry';
import { InternalHooks } from '@/InternalHooks';
import { mockInstance } from '../shared/mocking';
import type { IDiagnosticInfo } from '@/Interfaces';
import { mock } from 'jest-mock-extended';
import { N8N_VERSION } from '@/constants';
import { InternalHooks } from '@/InternalHooks';
import type { License } from '@/License';
import type { Telemetry } from '@/telemetry';
jest.mock('@/telemetry');
let internalHooks: InternalHooks;
let telemetry: Telemetry;
jest.mock('@/eventbus');
jest.mock('node:os', () => ({
tmpdir: () => '',
cpus: () => [{ model: 'MIPS R3000', speed: 40_000_000 }],
type: () => 'TempleOS',
version: () => '5.03',
totalmem: () => 1024 * 1024,
}));
describe('InternalHooks', () => {
beforeAll(() => {
telemetry = mockInstance(Telemetry);
internalHooks = new InternalHooks(telemetry, mock(), mock(), mock(), mock(), mock());
});
const telemetry = mock<Telemetry>();
const license = mock<License>();
const internalHooks = new InternalHooks(
telemetry,
mock(),
mock(),
mock(),
mock(),
mock(),
mock(),
license,
);
beforeEach(() => jest.clearAllMocks());
it('Should be defined', () => {
expect(internalHooks).toBeDefined();
});
it('Should forward license plan name and tenant id to identify when provided', async () => {
const licensePlanName = 'license-plan-name';
const licenseTenantId = 1001;
license.getPlanName.mockReturnValue('Best Plan');
const diagnosticInfo: IDiagnosticInfo = {
versionCli: '1.2.3',
databaseType: 'sqlite',
notificationsEnabled: true,
disableProductionWebhooksOnMainProcess: false,
systemInfo: {
os: {},
cpus: {},
await internalHooks.onServerStarted();
expect(telemetry.identify).toHaveBeenCalledWith({
version_cli: N8N_VERSION,
db_type: 'sqlite',
n8n_version_notifications_enabled: true,
n8n_disable_production_main_process: false,
system_info: {
memory: 1024,
os: {
type: 'TempleOS',
version: '5.03',
},
cpus: {
count: 1,
model: 'MIPS R3000',
speed: 40000000,
},
},
executionVariables: {},
deploymentType: 'testing',
binaryDataMode: 'default',
smtp_set_up: false,
ldap_allowed: true,
saml_enabled: true,
licensePlanName,
licenseTenantId,
execution_variables: {
executions_data_max_age: 336,
executions_data_prune: true,
executions_data_save_manual_executions: true,
executions_data_save_on_error: 'all',
executions_data_save_on_progress: false,
executions_data_save_on_success: 'all',
executions_mode: 'regular',
executions_timeout: -1,
executions_timeout_max: 3600,
},
n8n_deployment_type: 'default',
n8n_binary_data_mode: 'default',
smtp_set_up: true,
ldap_allowed: false,
saml_enabled: false,
license_plan_name: 'Best Plan',
license_tenant_id: 1,
binary_data_s3: false,
multi_main_setup_enabled: false,
};
const parameters = {
version_cli: diagnosticInfo.versionCli,
db_type: diagnosticInfo.databaseType,
n8n_version_notifications_enabled: diagnosticInfo.notificationsEnabled,
n8n_disable_production_main_process: diagnosticInfo.disableProductionWebhooksOnMainProcess,
system_info: diagnosticInfo.systemInfo,
execution_variables: diagnosticInfo.executionVariables,
n8n_deployment_type: diagnosticInfo.deploymentType,
n8n_binary_data_mode: diagnosticInfo.binaryDataMode,
smtp_set_up: diagnosticInfo.smtp_set_up,
ldap_allowed: diagnosticInfo.ldap_allowed,
saml_enabled: diagnosticInfo.saml_enabled,
license_plan_name: diagnosticInfo.licensePlanName,
license_tenant_id: diagnosticInfo.licenseTenantId,
};
await internalHooks.onServerStarted(diagnosticInfo);
expect(telemetry.identify).toHaveBeenCalledWith(parameters);
});
});
});