refactor(core): Abstract away InstanceSettings and encryptionKey into injectable services (no-changelog) (#7471)

This change ensures that things like `encryptionKey` and `instanceId`
are always available directly where they are needed, instead of passing
them around throughout the code.
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-10-23 13:39:35 +02:00
committed by GitHub
parent 519680c2cf
commit b6de910cbe
94 changed files with 501 additions and 1070 deletions

View File

@@ -4,6 +4,8 @@ import config from '@/config';
import { flushPromises } from './Helpers';
import { PostHogClient } from '@/posthog';
import { mock } from 'jest-mock-extended';
import { mockInstance } from '../integration/shared/utils';
import { InstanceSettings } from 'n8n-core';
jest.unmock('@/telemetry');
jest.mock('@/license/License.service', () => {
@@ -28,6 +30,7 @@ describe('Telemetry', () => {
let telemetry: Telemetry;
const instanceId = 'Telemetry unit test';
const testDateTime = new Date('2022-01-01 00:00:00');
const instanceSettings = mockInstance(InstanceSettings, { instanceId });
beforeAll(() => {
startPulseSpy = jest
@@ -49,11 +52,10 @@ describe('Telemetry', () => {
beforeEach(async () => {
spyTrack.mockClear();
const postHog = new PostHogClient();
await postHog.init(instanceId);
const postHog = new PostHogClient(instanceSettings);
await postHog.init();
telemetry = new Telemetry(postHog, mock());
telemetry.setInstanceId(instanceId);
telemetry = new Telemetry(postHog, mock(), instanceSettings);
(telemetry as any).rudderStack = mockRudderStack;
});