mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 11:01:15 +00:00
fix(editor): Include n8n version in user identify call (no-changelog) (#19306)
Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
@@ -1,23 +1,25 @@
|
||||
import { useUsersStore } from '@/stores/users.store';
|
||||
import { mockedStore, SETTINGS_STORE_DEFAULT_STATE } from '@/__tests__/utils';
|
||||
import { EnterpriseEditionFeature } from '@/constants';
|
||||
import { initializeAuthenticatedFeatures, initializeCore, state } from '@/init';
|
||||
import { UserManagementAuthenticationMethod } from '@/Interface';
|
||||
import { useCloudPlanStore } from '@/stores/cloudPlan.store';
|
||||
import { useSourceControlStore } from '@/stores/sourceControl.store';
|
||||
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
|
||||
import { useRootStore } from '@n8n/stores/useRootStore';
|
||||
import { state, initializeAuthenticatedFeatures, initializeCore } from '@/init';
|
||||
import { createTestingPinia } from '@pinia/testing';
|
||||
import { setActivePinia } from 'pinia';
|
||||
import { useSettingsStore } from '@/stores/settings.store';
|
||||
import { useSourceControlStore } from '@/stores/sourceControl.store';
|
||||
import { useSSOStore } from '@/stores/sso.store';
|
||||
import { useUIStore } from '@/stores/ui.store';
|
||||
import { useUsersStore } from '@/stores/users.store';
|
||||
import { useVersionsStore } from '@/stores/versions.store';
|
||||
import type { Cloud, CurrentUserResponse } from '@n8n/rest-api-client';
|
||||
import type { IUser } from '@n8n/rest-api-client/api/users';
|
||||
import { STORES } from '@n8n/stores';
|
||||
import { useRootStore } from '@n8n/stores/useRootStore';
|
||||
import { createTestingPinia } from '@pinia/testing';
|
||||
import { AxiosError } from 'axios';
|
||||
import merge from 'lodash/merge';
|
||||
import { mockedStore, SETTINGS_STORE_DEFAULT_STATE } from '@/__tests__/utils';
|
||||
import { STORES } from '@n8n/stores';
|
||||
import { useSSOStore } from '@/stores/sso.store';
|
||||
import { UserManagementAuthenticationMethod } from '@/Interface';
|
||||
import type { IUser } from '@n8n/rest-api-client/api/users';
|
||||
import { EnterpriseEditionFeature } from '@/constants';
|
||||
import { useUIStore } from '@/stores/ui.store';
|
||||
import type { Cloud } from '@n8n/rest-api-client';
|
||||
import { setActivePinia } from 'pinia';
|
||||
import { mock } from 'vitest-mock-extended';
|
||||
import { telemetry } from './plugins/telemetry';
|
||||
|
||||
const showMessage = vi.fn();
|
||||
const showToast = vi.fn();
|
||||
@@ -34,19 +36,16 @@ vi.mock('@/stores/users.store', () => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock('@n8n/stores/useRootStore', () => ({
|
||||
useRootStore: vi.fn(),
|
||||
}));
|
||||
|
||||
describe('Init', () => {
|
||||
let settingsStore: ReturnType<typeof useSettingsStore>;
|
||||
let settingsStore: ReturnType<typeof mockedStore<typeof useSettingsStore>>;
|
||||
let cloudPlanStore: ReturnType<typeof mockedStore<typeof useCloudPlanStore>>;
|
||||
let sourceControlStore: ReturnType<typeof useSourceControlStore>;
|
||||
let usersStore: ReturnType<typeof useUsersStore>;
|
||||
let nodeTypesStore: ReturnType<typeof useNodeTypesStore>;
|
||||
let versionsStore: ReturnType<typeof useVersionsStore>;
|
||||
let ssoStore: ReturnType<typeof useSSOStore>;
|
||||
let uiStore: ReturnType<typeof useUIStore>;
|
||||
let sourceControlStore: ReturnType<typeof mockedStore<typeof useSourceControlStore>>;
|
||||
let usersStore: ReturnType<typeof mockedStore<typeof useUsersStore>>;
|
||||
let nodeTypesStore: ReturnType<typeof mockedStore<typeof useNodeTypesStore>>;
|
||||
let versionsStore: ReturnType<typeof mockedStore<typeof useVersionsStore>>;
|
||||
let ssoStore: ReturnType<typeof mockedStore<typeof useSSOStore>>;
|
||||
let uiStore: ReturnType<typeof mockedStore<typeof useUIStore>>;
|
||||
let rootStore: ReturnType<typeof mockedStore<typeof useRootStore>>;
|
||||
|
||||
beforeEach(() => {
|
||||
setActivePinia(
|
||||
@@ -57,15 +56,16 @@ describe('Init', () => {
|
||||
}),
|
||||
);
|
||||
|
||||
settingsStore = useSettingsStore();
|
||||
settingsStore = mockedStore(useSettingsStore);
|
||||
cloudPlanStore = mockedStore(useCloudPlanStore);
|
||||
sourceControlStore = useSourceControlStore();
|
||||
nodeTypesStore = useNodeTypesStore();
|
||||
usersStore = useUsersStore();
|
||||
versionsStore = useVersionsStore();
|
||||
versionsStore = useVersionsStore();
|
||||
ssoStore = useSSOStore();
|
||||
uiStore = useUIStore();
|
||||
sourceControlStore = mockedStore(useSourceControlStore);
|
||||
nodeTypesStore = mockedStore(useNodeTypesStore);
|
||||
usersStore = mockedStore(useUsersStore);
|
||||
versionsStore = mockedStore(useVersionsStore);
|
||||
versionsStore = mockedStore(useVersionsStore);
|
||||
ssoStore = mockedStore(useSSOStore);
|
||||
uiStore = mockedStore(useUIStore);
|
||||
rootStore = mockedStore(useRootStore);
|
||||
});
|
||||
|
||||
describe('initializeCore()', () => {
|
||||
@@ -118,6 +118,19 @@ describe('Init', () => {
|
||||
expect(registerLogoutHookSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should correctly identify the user for telemetry', async () => {
|
||||
const telemetryIdentifySpy = vi.spyOn(telemetry, 'identify');
|
||||
usersStore.registerLoginHook.mockImplementation((hook) =>
|
||||
hook(mock<CurrentUserResponse>({ id: 'userId' })),
|
||||
);
|
||||
rootStore.instanceId = 'testInstanceId';
|
||||
rootStore.versionCli = '1.102.0';
|
||||
|
||||
await initializeCore();
|
||||
|
||||
expect(telemetryIdentifySpy).toHaveBeenCalledWith('testInstanceId', 'userId', '1.102.0');
|
||||
});
|
||||
|
||||
it('should initialize ssoStore with settings SSO configuration', async () => {
|
||||
const saml = { loginEnabled: true, loginLabel: '' };
|
||||
const ldap = { loginEnabled: false, loginLabel: '' };
|
||||
@@ -155,12 +168,10 @@ describe('Init', () => {
|
||||
|
||||
describe('initializeAuthenticatedFeatures()', () => {
|
||||
beforeEach(() => {
|
||||
vi.spyOn(settingsStore, 'isCloudDeployment', 'get').mockReturnValue(true);
|
||||
vi.spyOn(settingsStore, 'isTemplatesEnabled', 'get').mockReturnValue(true);
|
||||
vi.spyOn(sourceControlStore, 'isEnterpriseSourceControlEnabled', 'get').mockReturnValue(true);
|
||||
vi.mocked(useRootStore).mockReturnValue({ defaultLocale: 'es' } as ReturnType<
|
||||
typeof useRootStore
|
||||
>);
|
||||
settingsStore.isCloudDeployment = true;
|
||||
settingsStore.isTemplatesEnabled = true;
|
||||
sourceControlStore.isEnterpriseSourceControlEnabled = true;
|
||||
rootStore.defaultLocale = 'es';
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -172,9 +183,7 @@ describe('Init', () => {
|
||||
const sourceControlSpy = vi.spyOn(sourceControlStore, 'getPreferences');
|
||||
const nodeTranslationSpy = vi.spyOn(nodeTypesStore, 'getNodeTranslationHeaders');
|
||||
const versionsSpy = vi.spyOn(versionsStore, 'checkForNewVersions');
|
||||
vi.mocked(useUsersStore).mockReturnValue({ currentUser: null } as ReturnType<
|
||||
typeof useUsersStore
|
||||
>);
|
||||
usersStore.currentUser = null;
|
||||
|
||||
await initializeAuthenticatedFeatures(false);
|
||||
expect(cloudStoreSpy).not.toHaveBeenCalled();
|
||||
@@ -188,9 +197,7 @@ describe('Init', () => {
|
||||
const sourceControlSpy = vi.spyOn(sourceControlStore, 'getPreferences');
|
||||
const nodeTranslationSpy = vi.spyOn(nodeTypesStore, 'getNodeTranslationHeaders');
|
||||
const versionsSpy = vi.spyOn(versionsStore, 'checkForNewVersions');
|
||||
vi.mocked(useUsersStore).mockReturnValue({ currentUser: { id: '123' } } as ReturnType<
|
||||
typeof useUsersStore
|
||||
>);
|
||||
usersStore.currentUser = mock<IUser>({ id: '123', globalScopes: ['*'] });
|
||||
|
||||
await initializeAuthenticatedFeatures(false);
|
||||
|
||||
@@ -211,9 +218,7 @@ describe('Init', () => {
|
||||
const sourceControlSpy = vi.spyOn(sourceControlStore, 'getPreferences');
|
||||
const nodeTranslationSpy = vi.spyOn(nodeTypesStore, 'getNodeTranslationHeaders');
|
||||
const versionsSpy = vi.spyOn(versionsStore, 'checkForNewVersions');
|
||||
vi.mocked(useUsersStore).mockReturnValue({ currentUser: { id: '123' } } as ReturnType<
|
||||
typeof useUsersStore
|
||||
>);
|
||||
usersStore.currentUser = mock<IUser>({ id: '123', globalScopes: ['*'] });
|
||||
|
||||
await initializeAuthenticatedFeatures(false);
|
||||
|
||||
@@ -230,9 +235,7 @@ describe('Init', () => {
|
||||
const sourceControlSpy = vi.spyOn(sourceControlStore, 'getPreferences');
|
||||
const nodeTranslationSpy = vi.spyOn(nodeTypesStore, 'getNodeTranslationHeaders');
|
||||
const versionsSpy = vi.spyOn(versionsStore, 'checkForNewVersions');
|
||||
vi.mocked(useUsersStore).mockReturnValue({ currentUser: { id: '123' } } as ReturnType<
|
||||
typeof useUsersStore
|
||||
>);
|
||||
usersStore.currentUser = mock<IUser>({ id: '123', globalScopes: ['*'] });
|
||||
|
||||
await initializeAuthenticatedFeatures(false);
|
||||
|
||||
@@ -244,9 +247,7 @@ describe('Init', () => {
|
||||
|
||||
it('should handle source control initialization error', async () => {
|
||||
vi.spyOn(cloudPlanStore, 'initialize').mockResolvedValue();
|
||||
vi.mocked(useUsersStore).mockReturnValue({ currentUser: { id: '123' } } as ReturnType<
|
||||
typeof useUsersStore
|
||||
>);
|
||||
usersStore.currentUser = mock<IUser>({ id: '123', globalScopes: ['*'] });
|
||||
vi.spyOn(sourceControlStore, 'getPreferences').mockRejectedValueOnce(
|
||||
new AxiosError('Something went wrong', '404'),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user