Skip to content

Commit

Permalink
test(General): ✅ Add site pairs mock data and api
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoval committed Dec 4, 2023
1 parent cd0d7ec commit eda2efc
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
30 changes: 30 additions & 0 deletions mocks/data/SITE_PAIRS.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"results": [
{
"recType": "FLOWAGGREGATE",
"identity": "site-1-to-site-2",
"startTime": 1674202485242353,
"endTime": 0,
"pairType": "SITE",
"sourceId": "site-1",
"sourceName": "site 1",
"destinationId": "site-2",
"destinationName": "site-2"
},
{
"recType": "FLOWAGGREGATE",
"identity": "site-2-to-site-3",
"startTime": 1674202485242353,
"endTime": 0,
"pairType": "PROCESS",
"sourceId": "site-2",
"sourceName": "site 2",
"destinationId": "site-3",
"destinationName": "site 3"
}
],
"status": "",
"count": 2,
"timeRangeCount": 2,
"totalCount": 2
}
37 changes: 36 additions & 1 deletion mocks/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
SiteResponse,
FlowPairsResponse,
ResponseWrapper,
ProcessGroupPairsResponse
ProcessGroupPairsResponse,
SitePairsResponse
} from 'API/REST.interfaces';

const DELAY_RESPONSE = Number(process.env.MOCK_DELAY_RESPONSE) || 0; // in ms
Expand All @@ -28,6 +29,7 @@ const sites: ResponseWrapper<SiteResponse[]> = require(`${path}/SITES.json`);
const processGroups: ResponseWrapper<ProcessGroupResponse[]> = require(`${path}/PROCESS_GROUPS.json`);
const processGroupPairs: ResponseWrapper<ProcessGroupPairsResponse[]> = require(`${path}/PROCESS_GROUP_PAIRS.json`);
const processes: ResponseWrapper<ProcessResponse[]> = require(`${path}/PROCESSES.json`);
const sitePairs: ResponseWrapper<SitePairsResponse[]> = require(`${path}/SITE_PAIRS.json`);
const processPairs: ResponseWrapper<ProcessPairsResponse[]> = require(`${path}/PROCESS_PAIRS.json`);
const hosts = require(`${path}/HOSTS.json`);
const services = require(`${path}/SERVICES.json`);
Expand Down Expand Up @@ -122,6 +124,21 @@ for (let i = 0; i < ITEM_COUNT; i++) {
});
}

const mockSitePairsForPerf: SitePairsResponse[] = [];
for (let i = 0; i < ITEM_COUNT; i++) {
const sourceIndex = Math.floor(Math.random() * mockProcessesForPerf.length);
const destinationIndex = Math.floor(Math.random() * mockProcessesForPerf.length);

mockSitePairsForPerf.push({
...sitePairs.results[0],
identity: `${mockSitesForPerf[sourceIndex].identity}-to-${mockSitesForPerf[destinationIndex].identity}`,
sourceId: mockSitesForPerf[sourceIndex].identity,
sourceName: mockSitesForPerf[sourceIndex].name,
destinationId: mockSitesForPerf[destinationIndex].identity,
destinationName: mockSitesForPerf[destinationIndex].name
});
}

const mockProcessPairsForPerf: ProcessPairsResponse[] = [];
for (let i = 0; i < ITEM_COUNT; i++) {
const sourceIndex = Math.floor(Math.random() * mockProcessesForPerf.length);
Expand Down Expand Up @@ -243,6 +260,22 @@ export const MockApi = {
};
},

getSitePairs: (_: unknown, { queryParams }: ApiProps) => {
const sitesForPerfTests = ITEM_COUNT ? mockSitePairsForPerf : [];
const results = [...sitePairs.results, ...sitesForPerfTests];

if (queryParams && !Object.keys(queryParams).length) {
return { ...sitePairs, results };
}

const resultsFiltered = results.filter(
({ sourceId, destinationId }: SitePairsResponse) =>
sourceId === queryParams.sourceId || destinationId === queryParams.destinationId
);

return { ...processPairs, results: resultsFiltered };
},

getProcessPairs: (_: unknown, { queryParams }: ApiProps) => {
const processesForPerfTests = ITEM_COUNT ? mockProcessPairsForPerf : [];
const results = [...processPairs.results, ...processesForPerfTests];
Expand Down Expand Up @@ -328,6 +361,7 @@ export const MockApiPaths = {
Logout: `${prefix}/logout`,
Sites: `${prefix}/sites`,
Site: `${prefix}/sites/:id`,
SitePairs: `${prefix}/sitepairs`,
Components: `${prefix}/processgroups`,
Component: `${prefix}/processgroups/:id`,
Processes: `${prefix}/processes`,
Expand Down Expand Up @@ -362,6 +396,7 @@ export function loadMockServer() {
this.get(MockApiPaths.Components, MockApi.getComponents);
this.get(MockApiPaths.Component, MockApi.getComponent);
this.get(MockApiPaths.Processes, MockApi.getProcesses);
this.get(MockApiPaths.SitePairs, MockApi.getSitePairs);
this.get(MockApiPaths.ProcessPairs, MockApi.getProcessPairs);
this.get(MockApiPaths.PrometheusQuery, MockApi.getPrometheusQuery);
this.get(MockApiPaths.PrometheusRangeQuery, MockApi.getPrometheusRangeQuery);
Expand Down

0 comments on commit eda2efc

Please sign in to comment.