diff --git a/packages/frontend/editor-ui/src/init.test.ts b/packages/frontend/editor-ui/src/init.test.ts index 09b7687373..0f30bc3391 100644 --- a/packages/frontend/editor-ui/src/init.test.ts +++ b/packages/frontend/editor-ui/src/init.test.ts @@ -176,7 +176,7 @@ describe('Init', () => { typeof useUsersStore >); - await initializeAuthenticatedFeatures(); + await initializeAuthenticatedFeatures(false); expect(cloudStoreSpy).not.toHaveBeenCalled(); expect(sourceControlSpy).not.toHaveBeenCalled(); expect(nodeTranslationSpy).not.toHaveBeenCalled(); @@ -184,7 +184,7 @@ describe('Init', () => { }); it('should init authenticated features only once if user is logged in', async () => { - const cloudStoreSpy = vi.spyOn(cloudPlanStore, 'initialize'); + const cloudStoreSpy = vi.spyOn(cloudPlanStore, 'initialize').mockResolvedValue(); const sourceControlSpy = vi.spyOn(sourceControlStore, 'getPreferences'); const nodeTranslationSpy = vi.spyOn(nodeTypesStore, 'getNodeTranslationHeaders'); const versionsSpy = vi.spyOn(versionsStore, 'checkForNewVersions'); @@ -192,7 +192,7 @@ describe('Init', () => { typeof useUsersStore >); - await initializeAuthenticatedFeatures(); + await initializeAuthenticatedFeatures(false); expect(cloudStoreSpy).toHaveBeenCalled(); expect(sourceControlSpy).toHaveBeenCalled(); @@ -204,7 +204,46 @@ describe('Init', () => { expect(cloudStoreSpy).toHaveBeenCalledTimes(1); }); + it('should handle cloud plan initialization error', async () => { + const cloudStoreSpy = vi + .spyOn(cloudPlanStore, 'initialize') + .mockRejectedValue(new AxiosError('Something went wrong', '404')); + 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 + >); + + await initializeAuthenticatedFeatures(false); + + expect(cloudStoreSpy).toHaveBeenCalled(); + expect(sourceControlSpy).toHaveBeenCalled(); + expect(nodeTranslationSpy).toHaveBeenCalled(); + expect(versionsSpy).toHaveBeenCalled(); + }); + + it('should initialize even if cloud requests get stuck', async () => { + const cloudStoreSpy = vi.spyOn(cloudPlanStore, 'initialize').mockImplementation(async () => { + await new Promise((resolve) => setTimeout(resolve, 10000)); + }); + 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 + >); + + await initializeAuthenticatedFeatures(false); + + expect(cloudStoreSpy).toHaveBeenCalled(); + expect(sourceControlSpy).toHaveBeenCalled(); + expect(nodeTranslationSpy).toHaveBeenCalled(); + expect(versionsSpy).toHaveBeenCalled(); + }, 5000); + it('should handle source control initialization error', async () => { + vi.spyOn(cloudPlanStore, 'initialize').mockResolvedValue(); vi.mocked(useUsersStore).mockReturnValue({ currentUser: { id: '123' } } as ReturnType< typeof useUsersStore >); diff --git a/packages/frontend/editor-ui/src/init.ts b/packages/frontend/editor-ui/src/init.ts index 812559d50b..1a1353b420 100644 --- a/packages/frontend/editor-ui/src/init.ts +++ b/packages/frontend/editor-ui/src/init.ts @@ -148,21 +148,22 @@ export async function initializeAuthenticatedFeatures( } if (settingsStore.isCloudDeployment) { - try { - await cloudPlanStore.initialize(); - - if (cloudPlanStore.userIsTrialing) { - if (cloudPlanStore.trialExpired) { - uiStore.pushBannerToStack('TRIAL_OVER'); - } else { - uiStore.pushBannerToStack('TRIAL'); + void cloudPlanStore + .initialize() + .then(() => { + if (cloudPlanStore.userIsTrialing) { + if (cloudPlanStore.trialExpired) { + uiStore.pushBannerToStack('TRIAL_OVER'); + } else { + uiStore.pushBannerToStack('TRIAL'); + } + } else if (cloudPlanStore.currentUserCloudInfo?.confirmed === false) { + uiStore.pushBannerToStack('EMAIL_CONFIRMATION'); } - } else if (cloudPlanStore.currentUserCloudInfo?.confirmed === false) { - uiStore.pushBannerToStack('EMAIL_CONFIRMATION'); - } - } catch (e) { - console.error('Failed to initialize cloud plan store:', e); - } + }) + .catch((error) => { + console.error('Failed to initialize cloud plan store:', error); + }); } if (insightsStore.isSummaryEnabled) { diff --git a/packages/frontend/editor-ui/src/stores/versions.store.ts b/packages/frontend/editor-ui/src/stores/versions.store.ts index fc538202b6..affffcfde4 100644 --- a/packages/frontend/editor-ui/src/stores/versions.store.ts +++ b/packages/frontend/editor-ui/src/stores/versions.store.ts @@ -130,7 +130,9 @@ export const useVersionsStore = defineStore(STORES.VERSIONS, () => { const versions = await versionsApi.getNextVersions(endpoint, current, instanceId); setVersions({ versions, currentVersion: current }); } - } catch (e) {} + } catch (e) { + console.error('Failed to fetch versions:', e); + } }; const setVersions = (params: SetVersionParams) => { @@ -208,7 +210,9 @@ export const useVersionsStore = defineStore(STORES.VERSIONS, () => { } } } - } catch (e) {} + } catch (e) { + console.error('Failed to fetch Whats New section:', e); + } }; const initialize = (settings: IVersionNotificationSettings) => {