From 7ea3c7c13b812fbf1cbac916a95a5a0217cc516c Mon Sep 17 00:00:00 2001 From: ivinokur Date: Tue, 28 Jan 2025 16:10:00 +0200 Subject: [PATCH] Do not dispatch a warning, if the git provider is not supported --- .../CreatingSteps/Fetch/Devfile/index.tsx | 4 +-- .../__tests__/startWorkspace.spec.ts | 28 +++++++++++++++++++ .../actions/actionCreators/const.ts | 14 ++++++++++ .../actions/actionCreators/startWorkspace.ts | 5 ++-- 4 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/actions/actionCreators/const.ts diff --git a/packages/dashboard-frontend/src/components/WorkspaceProgress/CreatingSteps/Fetch/Devfile/index.tsx b/packages/dashboard-frontend/src/components/WorkspaceProgress/CreatingSteps/Fetch/Devfile/index.tsx index 098f84631..a0d4ad227 100644 --- a/packages/dashboard-frontend/src/components/WorkspaceProgress/CreatingSteps/Fetch/Devfile/index.tsx +++ b/packages/dashboard-frontend/src/components/WorkspaceProgress/CreatingSteps/Fetch/Devfile/index.tsx @@ -37,6 +37,7 @@ import SessionStorageService, { SessionStorageKey } from '@/services/session-sto import { RootState } from '@/store'; import { selectBranding } from '@/store/Branding'; import { factoryResolverActionCreators, selectFactoryResolver } from '@/store/FactoryResolver'; +import { FACTORY_RESOLVER_NOT_FOUND_ERROR_MESSAGE } from '@/store/Workspaces/devWorkspaces/actions/actionCreators/const'; import { selectAllWorkspaces } from '@/store/Workspaces/selectors'; export class ApplyingDevfileError extends Error { @@ -212,8 +213,7 @@ class CreatingStepFetchDevfile extends ProgressStep { } if ( errorMessage === 'Failed to fetch devfile' || - errorMessage === - 'Cannot build factory with any of the provided parameters. Please check parameters correctness, and resend query.' || + errorMessage === FACTORY_RESOLVER_NOT_FOUND_ERROR_MESSAGE || errorMessage.startsWith('Could not reach devfile') ) { this.setState({ useDefaultDevfile: true }); diff --git a/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/actions/actionCreators/__tests__/startWorkspace.spec.ts b/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/actions/actionCreators/__tests__/startWorkspace.spec.ts index b96d88f4c..628d0c5ca 100644 --- a/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/actions/actionCreators/__tests__/startWorkspace.spec.ts +++ b/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/actions/actionCreators/__tests__/startWorkspace.spec.ts @@ -201,6 +201,34 @@ describe('devWorkspaces, actions', () => { expect(actions[2]).toEqual(devWorkspacesErrorAction(expect.any(String))); }); + it('should not dispatch a warning for unsupported provider', async () => { + const mockError = { + response: { + data: { + message: 'Invalid token', + }, + }, + }; + + (OAuthService.refreshTokenIfProjectExists as jest.Mock).mockRejectedValueOnce(mockError); + (getWarningFromResponse as jest.Mock).mockReturnValueOnce( + 'Cannot build factory with any of the provided parameters. Please check parameters correctness, and resend query.', + ); + + // let's stop the workspace start at this point + // as we want to test the warning dispatch only + (checkRunningDevWorkspacesClusterLimitExceeded as jest.Mock).mockImplementationOnce(() => { + throw new Error('Cluster limit exceeded'); + }); + + await expect(store.dispatch(startWorkspace(mockWorkspace))).rejects.toThrow(); + + const actions = store.getActions(); + expect(actions).toHaveLength(2); + expect(actions[0]).toEqual(devWorkspacesRequestAction()); + expect(actions[1]).toEqual(devWorkspacesErrorAction(expect.any(String))); + }); + it('should dispatch update action on successful start', async () => { await store.dispatch(startWorkspace(mockWorkspace)); diff --git a/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/actions/actionCreators/const.ts b/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/actions/actionCreators/const.ts new file mode 100644 index 000000000..118c581e1 --- /dev/null +++ b/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/actions/actionCreators/const.ts @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2018-2024 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ + +export const FACTORY_RESOLVER_NOT_FOUND_ERROR_MESSAGE = + 'Cannot build factory with any of the provided parameters. Please check parameters correctness, and resend query.'; diff --git a/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/actions/actionCreators/startWorkspace.ts b/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/actions/actionCreators/startWorkspace.ts index 49a25c121..2f12757ab 100644 --- a/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/actions/actionCreators/startWorkspace.ts +++ b/packages/dashboard-frontend/src/store/Workspaces/devWorkspaces/actions/actionCreators/startWorkspace.ts @@ -21,6 +21,7 @@ import { devWorkspacesClusterActionCreators, } from '@/store/DevWorkspacesCluster'; import { verifyAuthorized } from '@/store/SanityCheck'; +import { FACTORY_RESOLVER_NOT_FOUND_ERROR_MESSAGE } from '@/store/Workspaces/devWorkspaces/actions/actionCreators/const'; import { checkDevWorkspaceNextStartAnnotation, checkRunningWorkspacesLimit, @@ -61,9 +62,9 @@ export const startWorkspace = await OAuthService.refreshTokenIfProjectExists(workspace); } catch (e: unknown) { // Do not interrupt the workspace start, but show a warning notification. - const warnMessage = getWarningFromResponse(e); - if (warnMessage) { + // Do not dispatch a warning, if the git provider is not supported. + if (warnMessage && warnMessage !== FACTORY_RESOLVER_NOT_FOUND_ERROR_MESSAGE) { dispatch(devWorkspaceWarningUpdateAction({ workspace, warning: warnMessage })); } }