Skip to content

Commit

Permalink
👌 Moving cloud hooks to initializeCore
Browse files Browse the repository at this point in the history
  • Loading branch information
MiloradFilipovic committed Nov 29, 2023
1 parent 50cb2f3 commit 89667e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
5 changes: 0 additions & 5 deletions packages/editor-ui/src/__tests__/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useSourceControlStore } from '@/stores/sourceControl.store';
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
import { useRootStore } from '@/stores/n8nRoot.store';
import { initializeAuthenticatedFeatures } from '@/init';
import * as registerModule from '@/hooks/register';
import type { SpyInstance } from 'vitest';
import { createTestingPinia } from '@pinia/testing';
import { setActivePinia } from 'pinia';
Expand All @@ -24,7 +23,6 @@ describe('Init', () => {
let cloudPlanStore: ReturnType<typeof useCloudPlanStore>;
let sourceControlStore: ReturnType<typeof useSourceControlStore>;
let nodeTypesStore: ReturnType<typeof useNodeTypesStore>;
let hooksSpy: SpyInstance<[], Promise<void>>;
let cloudStoreSpy: SpyInstance<[], Promise<void>>;
let templatesTestSpy: SpyInstance<[], Promise<void>>;
let sourceControlSpy: SpyInstance<[], Promise<void>>;
Expand All @@ -45,7 +43,6 @@ describe('Init', () => {
vi.mock('@/hooks/register', () => ({
initializeCloudHooks: vi.fn(),
}));
hooksSpy = vi.spyOn(registerModule, 'initializeCloudHooks');
cloudStoreSpy = vi.spyOn(cloudPlanStore, 'initialize');
templatesTestSpy = vi.spyOn(settingsStore, 'testTemplatesEndpoint');
sourceControlSpy = vi.spyOn(sourceControlStore, 'getPreferences');
Expand All @@ -61,7 +58,6 @@ describe('Init', () => {
typeof useUsersStore
>);
await initializeAuthenticatedFeatures();
expect(hooksSpy).not.toHaveBeenCalled();
expect(cloudStoreSpy).not.toHaveBeenCalled();
expect(templatesTestSpy).not.toHaveBeenCalled();
expect(sourceControlSpy).not.toHaveBeenCalled();
Expand All @@ -72,7 +68,6 @@ describe('Init', () => {
typeof useUsersStore
>);
await initializeAuthenticatedFeatures();
expect(hooksSpy).toHaveBeenCalled();
expect(cloudStoreSpy).toHaveBeenCalled();
expect(templatesTestSpy).toHaveBeenCalled();
expect(sourceControlSpy).toHaveBeenCalled();
Expand Down
22 changes: 13 additions & 9 deletions packages/editor-ui/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ export async function initializeCore() {
await settingsStore.initialize();
await usersStore.initialize();

if (settingsStore.isCloudDeployment) {
try {
await initializeCloudHooks();
} catch (e) {
console.error('Failed to initialize cloud hooks:', e);
}
}

coreInitialized = true;
}

Expand Down Expand Up @@ -61,15 +69,11 @@ export async function initializeAuthenticatedFeatures() {
}

if (settingsStore.isCloudDeployment) {
const results = await Promise.allSettled([cloudPlanStore.initialize(), initializeCloudHooks()]);
results.forEach((result, index) => {
if (result.status === 'rejected') {
console.error(
`Failed to initialize ${index === 0 ? 'cloud plan store' : 'cloud hooks'}:`,
result.reason,
);
}
});
try {
await cloudPlanStore.initialize();
} catch (e) {
console.error('Failed to initialize cloud plan store:', e);
}
}

authenticatedFeaturesInitialized = true;
Expand Down

0 comments on commit 89667e8

Please sign in to comment.