From eda2efcf75975418110218221228554dc09bd059 Mon Sep 17 00:00:00 2001 From: bartoval Date: Mon, 4 Dec 2023 09:55:49 +0100 Subject: [PATCH] test(General): :white_check_mark: Add site pairs mock data and api --- mocks/data/SITE_PAIRS.json | 30 ++++++++++++++++++++++++++++++ mocks/server.ts | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 mocks/data/SITE_PAIRS.json diff --git a/mocks/data/SITE_PAIRS.json b/mocks/data/SITE_PAIRS.json new file mode 100644 index 00000000..b8eb10d4 --- /dev/null +++ b/mocks/data/SITE_PAIRS.json @@ -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 +} diff --git a/mocks/server.ts b/mocks/server.ts index 5d6edb99..8181c85a 100644 --- a/mocks/server.ts +++ b/mocks/server.ts @@ -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 @@ -28,6 +29,7 @@ const sites: ResponseWrapper = require(`${path}/SITES.json`); const processGroups: ResponseWrapper = require(`${path}/PROCESS_GROUPS.json`); const processGroupPairs: ResponseWrapper = require(`${path}/PROCESS_GROUP_PAIRS.json`); const processes: ResponseWrapper = require(`${path}/PROCESSES.json`); +const sitePairs: ResponseWrapper = require(`${path}/SITE_PAIRS.json`); const processPairs: ResponseWrapper = require(`${path}/PROCESS_PAIRS.json`); const hosts = require(`${path}/HOSTS.json`); const services = require(`${path}/SERVICES.json`); @@ -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); @@ -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]; @@ -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`, @@ -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);