mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
refactor(editor): Remove i18n and toast usage from setting store (no-changelog) (#16721)
This commit is contained in:
@@ -18,9 +18,10 @@ import { EnterpriseEditionFeature } from '@/constants';
|
||||
import { useUIStore } from '@/stores/ui.store';
|
||||
|
||||
const showMessage = vi.fn();
|
||||
const showToast = vi.fn();
|
||||
|
||||
vi.mock('@/composables/useToast', () => ({
|
||||
useToast: () => ({ showMessage }),
|
||||
useToast: () => ({ showMessage, showToast }),
|
||||
}));
|
||||
|
||||
vi.mock('@/stores/users.store', () => ({
|
||||
@@ -90,6 +91,23 @@ describe('Init', () => {
|
||||
expect(settingsStoreSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should throw an error if settings initialization fails', async () => {
|
||||
const error = new Error('Settings initialization failed');
|
||||
|
||||
vi.spyOn(settingsStore, 'initialize').mockImplementation(() => {
|
||||
throw error;
|
||||
});
|
||||
|
||||
await initializeCore();
|
||||
|
||||
expect(showToast).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
title: 'Error connecting to n8n',
|
||||
type: 'error',
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('should initialize authentication hooks', async () => {
|
||||
const registerLoginHookSpy = vi.spyOn(usersStore, 'registerLoginHook');
|
||||
const registerLogoutHookSpy = vi.spyOn(usersStore, 'registerLogoutHook');
|
||||
|
||||
@@ -43,13 +43,25 @@ export async function initializeCore() {
|
||||
const ssoStore = useSSOStore();
|
||||
const uiStore = useUIStore();
|
||||
|
||||
const toast = useToast();
|
||||
const i18n = useI18n();
|
||||
|
||||
registerAuthenticationHooks();
|
||||
|
||||
/**
|
||||
* Initialize stores
|
||||
*/
|
||||
|
||||
await settingsStore.initialize();
|
||||
try {
|
||||
await settingsStore.initialize();
|
||||
} catch (error) {
|
||||
toast.showToast({
|
||||
title: i18n.baseText('startupError'),
|
||||
message: i18n.baseText('startupError.message'),
|
||||
type: 'error',
|
||||
duration: 0,
|
||||
});
|
||||
}
|
||||
|
||||
ssoStore.initialize({
|
||||
authenticationMethod: settingsStore.userManagement
|
||||
|
||||
@@ -21,12 +21,9 @@ import type { IDataObject, WorkflowSettings } from 'n8n-workflow';
|
||||
import { defineStore } from 'pinia';
|
||||
import { useRootStore } from '@n8n/stores/useRootStore';
|
||||
import { makeRestApiRequest } from '@n8n/rest-api-client';
|
||||
import { useToast } from '@/composables/useToast';
|
||||
import { useI18n } from '@n8n/i18n';
|
||||
import { useLocalStorage } from '@vueuse/core';
|
||||
|
||||
export const useSettingsStore = defineStore(STORES.SETTINGS, () => {
|
||||
const i18n = useI18n();
|
||||
const initialized = ref(false);
|
||||
const settings = ref<FrontendSettings>({} as FrontendSettings);
|
||||
const moduleSettings = ref<FrontendModuleSettings>({});
|
||||
@@ -265,23 +262,11 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, () => {
|
||||
return;
|
||||
}
|
||||
|
||||
const { showToast } = useToast();
|
||||
try {
|
||||
await getSettings();
|
||||
await getSettings();
|
||||
|
||||
initialized.value = true;
|
||||
initialized.value = true;
|
||||
|
||||
await getModuleSettings();
|
||||
} catch (e) {
|
||||
showToast({
|
||||
title: i18n.baseText('startupError'),
|
||||
message: i18n.baseText('startupError.message'),
|
||||
type: 'error',
|
||||
duration: 0,
|
||||
});
|
||||
|
||||
throw e;
|
||||
}
|
||||
await getModuleSettings();
|
||||
};
|
||||
|
||||
const stopShowingSetupPage = () => {
|
||||
|
||||
Reference in New Issue
Block a user