Skip to content

Commit

Permalink
feat: remove che-workspace-client lib
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <oorel@redhat.com>
  • Loading branch information
olexii4 committed Sep 22, 2023
1 parent 8d29c17 commit 9959875
Show file tree
Hide file tree
Showing 78 changed files with 525 additions and 337 deletions.
1 change: 1 addition & 0 deletions .deps/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@
| [`at-least-node@1.0.0`](git+https://github.com/RyanZim/at-least-node.git) | ISC | clearlydefined |
| [`available-typed-arrays@1.0.5`](git+https://github.com/inspect-js/available-typed-arrays.git) | MIT | clearlydefined |
| [`axios-mock-adapter@1.21.5`](git+https://github.com/ctimmerm/axios-mock-adapter.git) | MIT | clearlydefined |
| [`axios@1.4.0`](https://github.com/axios/axios.git) | MIT | clearlydefined |
| [`babel-jest@29.6.2`](https://github.com/facebook/jest.git) | MIT | clearlydefined |
| [`babel-plugin-istanbul@6.1.1`](git+https://github.com/istanbuljs/babel-plugin-istanbul.git) | BSD-3-Clause | clearlydefined |
| [`babel-plugin-jest-hoist@29.5.0`](https://github.com/facebook/jest.git) | MIT | clearlydefined |
Expand Down
4 changes: 1 addition & 3 deletions .deps/prod.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
| [`@babel/runtime@7.22.10`](https://github.com/babel/babel.git) | MIT | #8730 |
| [`@devfile/api@2.2.1-alpha-1667236163`](https://github.com/devfile/api.git) | Apache-2.0 | clearlydefined |
| `@eclipse-che/api@7.72.0` | EPL-2.0 | ecd.che |
| [`@eclipse-che/che-devworkspace-generator@7.75.0-next-50585f6`](git+https://github.com/eclipse-che/che-devfile-registry.git) | EPL-2.0 | ecd.che |
| [`@eclipse-che/che-devworkspace-generator@7.75.0-next-bbd66d3`](git+https://github.com/eclipse-che/che-devfile-registry.git) | EPL-2.0 | ecd.che |
| [`@eclipse-che/common@7.75.0-next`](https://github.com/eclipse-che/che-dashboard) | EPL-2.0 | ecd.che |
| [`@eclipse-che/dashboard-backend@7.75.0-next`](https://github.com/eclipse-che/che-dashboard) | EPL-2.0 | ecd.che |
| [`@eclipse-che/dashboard-frontend@7.75.0-next`](git://github.com/eclipse/che-dashboard.git) | EPL-2.0 | ecd.che |
| [`@eclipse-che/devfile-converter@0.0.1-ff55f9a`](git+https://github.com/che-incubator/devfile-converter.git) | EPL-2.0 | ecd.che |
| [`@eclipse-che/workspace-client@0.0.1-1672830275`](https://github.com/eclipse/che-workspace-client) | EPL-2.0 | ecd.che |
| [`@fastify/accept-negotiator@1.1.0`](git+https://github.com/fastify/accept-negotiator.git) | MIT | clearlydefined |
| [`@fastify/ajv-compiler@3.5.0`](git+https://github.com/fastify/ajv-compiler.git) | MIT | clearlydefined |
| [`@fastify/cookie@8.3.0`](git+ssh://git@github.com/fastify/fastify-cookie.git) | MIT | clearlydefined |
Expand Down Expand Up @@ -379,7 +378,6 @@
| [`trim-right@1.0.1`](https://github.com/sindresorhus/trim-right.git) | MIT | clearlydefined |
| [`tslib@2.6.1`](https://github.com/Microsoft/tslib.git) | 0BSD | #9189 |
| [`tunnel-agent@0.6.0`](https://github.com/mikeal/tunnel-agent) | Apache-2.0 | clearlydefined |
| [`tunnel@0.0.6`](https://github.com/koichik/node-tunnel.git) | MIT | clearlydefined |
| [`tweetnacl@0.14.5`](https://github.com/dchest/tweetnacl-js.git) | Unlicense | #1035 |
| [`type-fest@1.4.0`](https://github.com/sindresorhus/type-fest.git) | (MIT OR CC0-1.0) | clearlydefined |
| [`underscore@1.13.6`](git://github.com/jashkenas/underscore.git) | MIT | clearlydefined |
Expand Down
1 change: 0 additions & 1 deletion packages/dashboard-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
},
"dependencies": {
"@eclipse-che/devfile-converter": "0.0.1-ff55f9a",
"@eclipse-che/workspace-client": "0.0.1-1672830275",
"@patternfly/react-core": "^4.276.11",
"@patternfly/react-icons": "^4.93.7",
"@patternfly/react-table": "^4.113.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { BrandingData } from '../../../../services/bootstrap/branding.constant';
import {
ConnectionEvent,
WebsocketClient,
} from '../../../../services/dashboard-backend-client/websocketClient';
} from '../../../../services/backend-client/websocketClient';
import { FakeStoreBuilder } from '../../../../store/__mocks__/storeBuilder';

const failingMessage = 'WebSocket connections are failing';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
ConnectionEvent,
ConnectionListener,
WebsocketClient,
} from '../../../services/dashboard-backend-client/websocketClient';
} from '../../../services/backend-client/websocketClient';

type Props = MappedProps;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@
display: inline-block;
padding-top: 8px;
}

4 changes: 1 addition & 3 deletions packages/dashboard-frontend/src/inversify.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@
import 'reflect-metadata';
import { Container } from 'inversify';
import getDecorators from 'inversify-inject-decorators';
import { CheWorkspaceClient } from './services/workspace-client/cheworkspace/cheWorkspaceClient';
import { AppAlerts } from './services/alerts/appAlerts';
import { IssuesReporterService } from './services/bootstrap/issuesReporter';
import { DevWorkspaceClient } from './services/workspace-client/devworkspace/devWorkspaceClient';
import { DevWorkspaceDefaultPluginsHandler } from './services/workspace-client/devworkspace/DevWorkspaceDefaultPluginsHandler';
import { WorkspaceStoppedDetector } from './services/bootstrap/workspaceStoppedDetector';
import { WebsocketClient } from './services/dashboard-backend-client/websocketClient';
import { WebsocketClient } from './services/backend-client/websocketClient';

const container = new Container();
const { lazyInject } = getDecorators(container);

container.bind(IssuesReporterService).toSelf().inSingletonScope();
container.bind(WebsocketClient).toSelf().inSingletonScope();
container.bind(CheWorkspaceClient).toSelf().inSingletonScope();
container.bind(DevWorkspaceClient).toSelf().inSingletonScope();
container.bind(AppAlerts).toSelf().inSingletonScope();
container.bind(DevWorkspaceDefaultPluginsHandler).toSelf().inSingletonScope();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright (c) 2018-2023 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
*/

import mockAxios from 'axios';
import { getFactoryResolver, refreshFactoryOauthToken } from '../factoryApi';
import { FactoryResolver } from '../../helpers/types';
import devfileApi from '../../devfileApi';

describe('Factory API', () => {
const mockPost = mockAxios.post as jest.Mock;

const location = 'https://github.com/eclipse-che/che-dashboard.git';
const factoryResolver: FactoryResolver = {
v: '4.0',
source: 'devfile.yaml',
scm_info: {
clone_url: location,
scm_provider: 'github',
},
devfile: {
schemaVersion: '2.2.1',
metadata: {
name: 'che-dashboard',
namespace: 'namespace',
},
projects: [
{
git: {
remotes: {
origin: 'https://github.com/eclipse-che/che-dashboard.git',
},
},
name: 'che-dashboard',
},
],
} as devfileApi.Devfile,
links: [],
};

afterEach(() => {
jest.resetAllMocks();
});

describe('resolve factory', () => {
it('should call "/factory/resolver"', async () => {
mockPost.mockResolvedValueOnce({
data: expect.anything(),
});
await getFactoryResolver(location, {});

expect(mockPost).toBeCalledWith('/api/factory/resolver', {
url: 'https://github.com/eclipse-che/che-dashboard.git',
});
});

it('should return a factory resolver', async () => {
mockPost.mockResolvedValueOnce({
data: factoryResolver,
});

const res = await getFactoryResolver(location, {});

expect(res).toEqual(factoryResolver);
});
});

describe('refresh factory OAuth token', () => {
it('should call "/api/factory/token/refresh?url=${url}"', async () => {
mockPost.mockResolvedValueOnce({
data: expect.anything(),
});

await refreshFactoryOauthToken(location);

expect(mockPost).toBeCalledWith(
'/api/factory/token/refresh?url=https://github.com/eclipse-che/che-dashboard.git',
);
});

it('should return the OAuth token', async () => {
mockPost.mockResolvedValueOnce(undefined);

const res = await refreshFactoryOauthToken(location);

expect(res).toBeUndefined();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2018-2023 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
*/

import mockAxios from 'axios';
import { getKubernetesNamespace, provisionKubernetesNamespace } from '../kubernetesNamespaceApi';

describe('Kubernetes namespace API', () => {
const mockGet = mockAxios.get as jest.Mock;
const mockPost = mockAxios.post as jest.Mock;

const namespace: che.KubernetesNamespace = { name: 'test-name', attributes: { phase: 'Active' } };

afterEach(() => {
jest.resetAllMocks();
});

describe('fetch namespace', () => {
it('should call "/api/kubernetes/namespace"', async () => {
mockGet.mockResolvedValueOnce({
data: expect.anything(),
});
await getKubernetesNamespace();

expect(mockGet).toBeCalledWith('/api/kubernetes/namespace');
expect(mockPost).not.toBeCalled();
});

it('should return a list of namespaces', async () => {
mockGet.mockResolvedValueOnce({
data: [namespace],
});

const res = await getKubernetesNamespace();

expect(res).toEqual([namespace]);
});
});

describe('provision namespace', () => {
it('should call "/api/kubernetes/namespace/provision"', async () => {
mockPost.mockResolvedValueOnce({
data: expect.anything(),
});
await provisionKubernetesNamespace();

expect(mockGet).not.toBeCalled();
expect(mockPost).toBeCalledWith('/api/kubernetes/namespace/provision');
});

it('should return a list of namespaces', async () => {
mockPost.mockResolvedValueOnce({
data: [namespace],
});

const res = await provisionKubernetesNamespace();

expect(res).toEqual([namespace]);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright (c) 2018-2023 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
*/

import mockAxios from 'axios';
import { IGitOauth } from '../../../store/GitOauthConfig/types';
import { deleteOAuthToken, getOAuthProviders, getOAuthToken } from '../oAuthApi';

describe('Open Authorization API', () => {
const mockGet = mockAxios.get as jest.Mock;
const mockDelete = mockAxios.delete as jest.Mock;

const oAuthProvider = { name: 'github', endpointUrl: 'https://github.com' } as IGitOauth;
const oAuthProviderToken = { token: 'dummy_token' };

afterEach(() => {
jest.resetAllMocks();
});

describe('fetch OAuthProviders', () => {
it('should call "/api/oauth"', async () => {
mockGet.mockResolvedValueOnce({
data: expect.anything(),
});
await getOAuthProviders();

expect(mockDelete).not.toBeCalled();
expect(mockGet).toBeCalledWith('/api/oauth');
});

it('should return a list of providers', async () => {
mockGet.mockResolvedValueOnce({
data: [oAuthProvider],
});

const res = await getOAuthProviders();

expect(res).toEqual([oAuthProvider]);
});
});

describe('fetch OAuthToken', () => {
it('should call "/api/oauth/token?oauth_provider=github"', async () => {
mockGet.mockResolvedValueOnce({
data: expect.anything(),
});

await getOAuthToken(oAuthProvider.name);

expect(mockDelete).not.toBeCalled();
expect(mockGet).toBeCalledWith('/api/oauth/token?oauth_provider=github');
});

it('should return the OAuth token', async () => {
mockGet.mockResolvedValueOnce({
data: oAuthProviderToken,
});

const res = await getOAuthToken(oAuthProvider.name);

expect(mockDelete).not.toBeCalled();
expect(res).toEqual(oAuthProviderToken);
});
});

describe('delete OAuthToken', () => {
it('should call "/api/oauth/token?oauth_provider=github"', async () => {
mockDelete.mockResolvedValueOnce(undefined);

await deleteOAuthToken(oAuthProvider.name);

expect(mockGet).not.toBeCalled();
expect(mockDelete).toBeCalledWith('/api/oauth/token?oauth_provider=github');
});

it('should return undefined', async () => {
mockDelete.mockResolvedValueOnce(undefined);

const res = await deleteOAuthToken(oAuthProvider.name);

expect(mockGet).not.toBeCalled();
expect(res).toBeUndefined();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ import axios from 'axios';
import { cheServerPrefix } from './const';
import { FactoryResolver } from '../helpers/types';

const factoryResolverEndpoint = '/factory/resolver';

export async function getFactoryResolver(
url: string,
overrideParams: { [params: string]: string } = {},
): Promise<FactoryResolver> {
const response = await axios.post(
`${cheServerPrefix}${factoryResolverEndpoint}`,
`${cheServerPrefix}/factory/resolver`,
Object.assign({}, overrideParams, { url }),
);

return response.data;
}

export async function refreshFactoryOauthToken(url: string): Promise<void> {
await axios.post(`${cheServerPrefix}/factory/token/refresh?url=${url}`);

return Promise.resolve();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2018-2023 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
*/

import axios from 'axios';
import { cheServerPrefix } from './const';

export async function getKubernetesNamespace(): Promise<che.KubernetesNamespace[]> {
const response = await axios.get(`${cheServerPrefix}/kubernetes/namespace`);

return response.data;
}

export async function provisionKubernetesNamespace(): Promise<che.KubernetesNamespace> {
const response = await axios.post(`${cheServerPrefix}/kubernetes/namespace/provision`);

return response.data;
}
Loading

0 comments on commit 9959875

Please sign in to comment.