Skip to content

Commit

Permalink
NCL-7856 Integrate PNC API Mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
patrikk0123 committed Aug 3, 2023
1 parent c18beb8 commit 37c525b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/services/buildApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AxiosRequestConfig } from 'axios';

import { ArtifactPage, Build, BuildPage, BuildsGraph, RunningBuildCount } from 'pnc-api-types-ts';

import { mockClient } from 'services/mockClient';
import { pncApiMocksClient } from 'services/pncApiMocksClient';

import { kafkaClient } from './kafkaClient';
import { pncClient } from './pncClient';
Expand Down Expand Up @@ -90,7 +90,7 @@ export const getDependencyGraph = ({ id }: IBuildApiData, requestConfig: AxiosRe
* @param requestConfig - Axios based request config
*/
export const getArtifactDependencyGrah = ({ id }: IBuildApiData, requestConfig: AxiosRequestConfig = {}) => {
return mockClient.getHttpClient().get<any>(`/builds/${id}/artifact-dependency-graph`, requestConfig);
return pncApiMocksClient.getHttpClient().get<any>(`/builds/${id}/artifact-dependency-graph`, requestConfig);
};

/**
Expand All @@ -99,5 +99,5 @@ export const getArtifactDependencyGrah = ({ id }: IBuildApiData, requestConfig:
* @param requestConfig - Axios based request config
*/
export const getArtifactDependencies = (requestConfig: AxiosRequestConfig = {}) => {
return mockClient.getHttpClient().get<any>(`/build-artifact-dependencies`, requestConfig);
return pncApiMocksClient.getHttpClient().get<any>(`/build-artifact-dependencies`, requestConfig);
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import axios, { AxiosInstance } from 'axios';

import * as webConfigService from './webConfigService';

/**
* Mocked backend client. Use for WIP features.
*/
class MockClient {
class PncApiMocksClient {
private httpClient: AxiosInstance;

constructor() {
Expand All @@ -17,7 +19,7 @@ class MockClient {
*/
private createHttpClient = (): AxiosInstance =>
axios.create({
baseURL: `http://localhost:8020`,
baseURL: process.env.REACT_APP_PNC_API_MOCKS_URL || webConfigService.getPncApiMocksUrl(),
});

// PUBLIC
Expand All @@ -28,4 +30,4 @@ class MockClient {
public getHttpClient = (): AxiosInstance => this.httpClient;
}

export const mockClient = new MockClient();
export const pncApiMocksClient = new PncApiMocksClient();
10 changes: 5 additions & 5 deletions src/services/productMilestoneApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ProductMilestoneCloseResultPage,
} from 'pnc-api-types-ts';

import { mockClient } from 'services/mockClient';
import { pncApiMocksClient } from 'services/pncApiMocksClient';

import { pncClient } from './pncClient';

Expand Down Expand Up @@ -75,7 +75,7 @@ export const getBuilds = ({ id }: IProductMilestoneApiData, requestConfig: Axios
* @param requestConfig - Axios based request config
*/
export const getStatistics = ({ id }: IProductMilestoneApiData, requestConfig: AxiosRequestConfig = {}) => {
return mockClient.getHttpClient().get<any>(`/product-milestones/${id}/statistics`, requestConfig);
return pncApiMocksClient.getHttpClient().get<any>(`/product-milestones/${id}/statistics`, requestConfig);
};

/**
Expand All @@ -84,7 +84,7 @@ export const getStatistics = ({ id }: IProductMilestoneApiData, requestConfig: A
* @param requestConfig - Axios based request config
*/
export const getInterconnectionGraph = ({ id }: IProductMilestoneApiData, requestConfig: AxiosRequestConfig = {}) => {
return mockClient.getHttpClient().get<any>(`/product-milestones/${id}/interconnection-graph`, requestConfig);
return pncApiMocksClient.getHttpClient().get<any>(`/product-milestones/${id}/interconnection-graph`, requestConfig);
};

/**
Expand All @@ -93,7 +93,7 @@ export const getInterconnectionGraph = ({ id }: IProductMilestoneApiData, reques
* @param requestConfig - Axios based request config
*/
export const getSharedDeliveredArtifacts = (requestConfig: AxiosRequestConfig = {}) => {
return mockClient.getHttpClient().get<any>(`/product-milestone-shared-delivered-artifacts`, requestConfig);
return pncApiMocksClient.getHttpClient().get<any>(`/product-milestone-shared-delivered-artifacts`, requestConfig);
};

/**
Expand All @@ -107,5 +107,5 @@ export const getProductMilestoneComparison = (
{ data }: { data: { productMilestones: string[] } },
requestConfig: AxiosRequestConfig = {}
) => {
return mockClient.getHttpClient().post<any>(`/product-milestone-comparison`, data, requestConfig);
return pncApiMocksClient.getHttpClient().post<any>(`/product-milestone-comparison`, data, requestConfig);
};
8 changes: 4 additions & 4 deletions src/services/productVersionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AxiosRequestConfig } from 'axios';

import { GroupConfigPage, ProductMilestonePage, ProductReleasePage, ProductVersion } from 'pnc-api-types-ts';

import { mockClient } from 'services/mockClient';
import { pncApiMocksClient } from 'services/pncApiMocksClient';

import { pncClient } from './pncClient';

Expand All @@ -29,7 +29,7 @@ export const getProductVersion = ({ id }: IProductVersionApiData, requestConfig:
* @param requestConfig - Axios based request config
*/
export const getStatistics = ({ id }: IProductVersionApiData, requestConfig: AxiosRequestConfig = {}) => {
return mockClient.getHttpClient().get<any>(`/product-versions/${id}/statistics`, requestConfig);
return pncApiMocksClient.getHttpClient().get<any>(`/product-versions/${id}/statistics`, requestConfig);
};

/**
Expand All @@ -40,7 +40,7 @@ export const getStatistics = ({ id }: IProductVersionApiData, requestConfig: Axi
* @param requestConfig - Axios based request config
*/
export const getArtifactQualityStatistics = ({ id }: IProductVersionApiData, requestConfig: AxiosRequestConfig = {}) => {
return mockClient.getHttpClient().get<any>(`/product-versions/${id}/artifact-quality-statistics`, requestConfig);
return pncApiMocksClient.getHttpClient().get<any>(`/product-versions/${id}/artifact-quality-statistics`, requestConfig);
};

/**
Expand All @@ -51,7 +51,7 @@ export const getArtifactQualityStatistics = ({ id }: IProductVersionApiData, req
* @param requestConfig - Axios based request config
*/
export const getRepositoryTypeStatistics = ({ id }: IProductVersionApiData, requestConfig: AxiosRequestConfig = {}) => {
return mockClient.getHttpClient().get<any>(`/product-versions/${id}/repository-type-statistics`, requestConfig);
return pncApiMocksClient.getHttpClient().get<any>(`/product-versions/${id}/repository-type-statistics`, requestConfig);
};

/**
Expand Down
11 changes: 11 additions & 0 deletions src/services/webConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ export const getKafkaUrl = (): string => {
return kafkaUrl;
};

export const getPncApiMocksUrl = (): string => {
// TODO: extract URL from config once available
const pncApiMocksUrl = process.env.REACT_APP_PNC_API_MOCKS_URL;

if (!pncApiMocksUrl) {
throw new Error(`PNC API MOCKS URL does not contain any data: #${pncApiMocksUrl}#`);
}

return pncApiMocksUrl;
};

export const getUILoggerUrl = (): string => {
const uiLoggerUrl = getWebConfig().externalUiLoggerUrl;

Expand Down

0 comments on commit 37c525b

Please sign in to comment.