Skip to content

Commit 1bf30d5

Browse files
authored
Merge pull request #3801 from dlabrecq/test5
Refactor utils tests
2 parents 27ef85b + fd44773 commit 1bf30d5

File tree

5 files changed

+124
-221
lines changed

5 files changed

+124
-221
lines changed

src/api/export/exportUtils.test.ts

+25-45
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,61 @@
11
import { waitFor } from '@testing-library/react';
2-
import { ReportPathsType } from 'api/reports/report';
2+
import { ReportPathsType, ReportType } from 'api/reports/report';
33

4-
import * as awsExport from './awsExport';
5-
import * as awsOcpExport from './awsOcpExport';
6-
import * as azureExport from './azureExport';
7-
import * as azureOcpExport from './azureOcpExport';
8-
import * as gcpExport from './gcpExport';
9-
import * as gcpOcpExport from './gcpOcpExport';
10-
import * as ibmExport from './ibmExport';
11-
import * as ociExport from './ociExport';
12-
import * as ocpCloudExport from './ocpCloudExport';
13-
import * as ocpExport from './ocpExport';
14-
import * as rhelExport from './rhelExport';
4+
import * as exportUtils from './exportUtils';
155

16-
jest.spyOn(awsExport, 'runExport');
17-
jest.spyOn(awsOcpExport, 'runExport');
18-
jest.spyOn(azureExport, 'runExport');
19-
jest.spyOn(azureOcpExport, 'runExport');
20-
jest.spyOn(gcpExport, 'runExport');
21-
jest.spyOn(gcpOcpExport, 'runExport');
22-
jest.spyOn(ibmExport, 'runExport');
23-
jest.spyOn(ociExport, 'runExport');
24-
jest.spyOn(ocpCloudExport, 'runExport');
25-
jest.spyOn(ocpExport, 'runExport');
26-
jest.spyOn(rhelExport, 'runExport');
6+
jest.spyOn(exportUtils, 'runExport');
277

288
test('runExport API request for AWS', async () => {
29-
awsExport.runExport(ReportPathsType.aws, '');
30-
await waitFor(() => expect(awsExport.runExport).toHaveBeenCalled());
9+
exportUtils.runExport(ReportPathsType.aws, ReportType.cost, '');
10+
await waitFor(() => expect(exportUtils.runExport).toHaveBeenCalled());
3111
});
3212

3313
test('runExport API request for OCP on AWS', async () => {
34-
awsOcpExport.runExport(ReportPathsType.awsOcp, '');
35-
await waitFor(() => expect(awsOcpExport.runExport).toHaveBeenCalled());
14+
exportUtils.runExport(ReportPathsType.awsOcp, ReportType.cost, '');
15+
await waitFor(() => expect(exportUtils.runExport).toHaveBeenCalled());
3616
});
3717

3818
test('runExport API request for Azure', async () => {
39-
azureExport.runExport(ReportPathsType.azure, '');
40-
await waitFor(() => expect(azureExport.runExport).toHaveBeenCalled());
19+
exportUtils.runExport(ReportPathsType.azure, ReportType.cost, '');
20+
await waitFor(() => expect(exportUtils.runExport).toHaveBeenCalled());
4121
});
4222

4323
test('runExport API request for OCP on Azure', async () => {
44-
azureOcpExport.runExport(ReportPathsType.azureOcp, '');
45-
await waitFor(() => expect(azureOcpExport.runExport).toHaveBeenCalled());
24+
exportUtils.runExport(ReportPathsType.azureOcp, ReportType.cost, '');
25+
await waitFor(() => expect(exportUtils.runExport).toHaveBeenCalled());
4626
});
4727

4828
test('runExport API request for GCP', async () => {
49-
gcpExport.runExport(ReportPathsType.gcp, '');
50-
await waitFor(() => expect(gcpExport.runExport).toHaveBeenCalled());
29+
exportUtils.runExport(ReportPathsType.gcp, ReportType.cost, '');
30+
await waitFor(() => expect(exportUtils.runExport).toHaveBeenCalled());
5131
});
5232

5333
test('runExport API request for OCP on GCP', async () => {
54-
gcpOcpExport.runExport(ReportPathsType.gcpOcp, '');
55-
await waitFor(() => expect(gcpOcpExport.runExport).toHaveBeenCalled());
34+
exportUtils.runExport(ReportPathsType.gcpOcp, ReportType.cost, '');
35+
await waitFor(() => expect(exportUtils.runExport).toHaveBeenCalled());
5636
});
5737

5838
test('runExport API request for IBM', async () => {
59-
ibmExport.runExport(ReportPathsType.ibm, '');
60-
await waitFor(() => expect(ibmExport.runExport).toHaveBeenCalled());
39+
exportUtils.runExport(ReportPathsType.ibm, ReportType.cost, '');
40+
await waitFor(() => expect(exportUtils.runExport).toHaveBeenCalled());
6141
});
6242

6343
test('runExport API request for OCI', async () => {
64-
ociExport.runExport(ReportPathsType.oci, '');
65-
await waitFor(() => expect(ociExport.runExport).toHaveBeenCalled());
44+
exportUtils.runExport(ReportPathsType.oci, ReportType.cost, '');
45+
await waitFor(() => expect(exportUtils.runExport).toHaveBeenCalled());
6646
});
6747

6848
test('runExport API request for all cloud filtered by OCP', async () => {
69-
ocpCloudExport.runExport(ReportPathsType.ocpCloud, '');
70-
await waitFor(() => expect(ocpCloudExport.runExport).toHaveBeenCalled());
49+
exportUtils.runExport(ReportPathsType.ocpCloud, ReportType.cost, '');
50+
await waitFor(() => expect(exportUtils.runExport).toHaveBeenCalled());
7151
});
7252

7353
test('runExport API request for OCP', async () => {
74-
ocpExport.runExport(ReportPathsType.ocp, '');
75-
await waitFor(() => expect(ocpExport.runExport).toHaveBeenCalled());
54+
exportUtils.runExport(ReportPathsType.ocp, ReportType.cost, '');
55+
await waitFor(() => expect(exportUtils.runExport).toHaveBeenCalled());
7656
});
7757

7858
test('runExport API request for RHEL', async () => {
79-
rhelExport.runExport(ReportPathsType.rhel, '');
80-
await waitFor(() => expect(rhelExport.runExport).toHaveBeenCalled());
59+
exportUtils.runExport(ReportPathsType.rhel, ReportType.cost, '');
60+
await waitFor(() => expect(exportUtils.runExport).toHaveBeenCalled());
8161
});
+25-45
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,61 @@
11
import { waitFor } from '@testing-library/react';
22

3-
import * as awsForecast from './awsForecast';
4-
import * as awsOcpForecast from './awsOcpForecast';
5-
import * as azureForecast from './azureForecast';
6-
import * as azureOcpForecast from './azureOcpForecast';
7-
import { ForecastType } from './forecast';
8-
import * as gcpForecast from './gcpForecast';
9-
import * as gcpOcpForecast from './gcpOcpForecast';
10-
import * as ibmForecast from './ibmForecast';
11-
import * as ociForecast from './ociForecast';
12-
import * as ocpCloudForecast from './ocpCloudForecast';
13-
import * as ocpForecast from './ocpForecast';
14-
import * as rhelForecast from './rhelForecast';
3+
import { ForecastPathsType, ForecastType } from './forecast';
4+
import * as forecastUtils from './forecastUtils';
155

16-
jest.spyOn(awsForecast, 'runForecast');
17-
jest.spyOn(awsOcpForecast, 'runForecast');
18-
jest.spyOn(azureForecast, 'runForecast');
19-
jest.spyOn(azureOcpForecast, 'runForecast');
20-
jest.spyOn(gcpForecast, 'runForecast');
21-
jest.spyOn(gcpOcpForecast, 'runForecast');
22-
jest.spyOn(ibmForecast, 'runForecast');
23-
jest.spyOn(ociForecast, 'runForecast');
24-
jest.spyOn(ocpCloudForecast, 'runForecast');
25-
jest.spyOn(ocpForecast, 'runForecast');
26-
jest.spyOn(rhelForecast, 'runForecast');
6+
jest.spyOn(forecastUtils, 'runForecast');
277

288
test('runForecast API request for AWS', async () => {
29-
awsForecast.runForecast(ForecastType.cost, '');
30-
await waitFor(() => expect(awsForecast.runForecast).toHaveBeenCalled());
9+
forecastUtils.runForecast(ForecastPathsType.aws, ForecastType.cost, '');
10+
await waitFor(() => expect(forecastUtils.runForecast).toHaveBeenCalled());
3111
});
3212

3313
test('runForecast API request for OCP on AWS', async () => {
34-
awsOcpForecast.runForecast(ForecastType.cost, '');
35-
await waitFor(() => expect(awsOcpForecast.runForecast).toHaveBeenCalled());
14+
forecastUtils.runForecast(ForecastPathsType.awsOcp, ForecastType.cost, '');
15+
await waitFor(() => expect(forecastUtils.runForecast).toHaveBeenCalled());
3616
});
3717

3818
test('runForecast API request for Azure', async () => {
39-
azureForecast.runForecast(ForecastType.cost, '');
40-
await waitFor(() => expect(azureForecast.runForecast).toHaveBeenCalled());
19+
forecastUtils.runForecast(ForecastPathsType.azure, ForecastType.cost, '');
20+
await waitFor(() => expect(forecastUtils.runForecast).toHaveBeenCalled());
4121
});
4222

4323
test('runForecast API request for OCP on Azure', async () => {
44-
azureOcpForecast.runForecast(ForecastType.cost, '');
45-
await waitFor(() => expect(azureOcpForecast.runForecast).toHaveBeenCalled());
24+
forecastUtils.runForecast(ForecastPathsType.azureOcp, ForecastType.cost, '');
25+
await waitFor(() => expect(forecastUtils.runForecast).toHaveBeenCalled());
4626
});
4727

4828
test('runForecast API request for GCP', async () => {
49-
gcpForecast.runForecast(ForecastType.cost, '');
50-
await waitFor(() => expect(gcpForecast.runForecast).toHaveBeenCalled());
29+
forecastUtils.runForecast(ForecastPathsType.gcp, ForecastType.cost, '');
30+
await waitFor(() => expect(forecastUtils.runForecast).toHaveBeenCalled());
5131
});
5232

5333
test('runForecast API request for OCP on GCP', async () => {
54-
gcpOcpForecast.runForecast(ForecastType.cost, '');
55-
await waitFor(() => expect(gcpOcpForecast.runForecast).toHaveBeenCalled());
34+
forecastUtils.runForecast(ForecastPathsType.gcpOcp, ForecastType.cost, '');
35+
await waitFor(() => expect(forecastUtils.runForecast).toHaveBeenCalled());
5636
});
5737

5838
test('runForecast API request for IBM', async () => {
59-
ibmForecast.runForecast(ForecastType.cost, '');
60-
await waitFor(() => expect(ibmForecast.runForecast).toHaveBeenCalled());
39+
forecastUtils.runForecast(ForecastPathsType.ibm, ForecastType.cost, '');
40+
await waitFor(() => expect(forecastUtils.runForecast).toHaveBeenCalled());
6141
});
6242

6343
test('runForecast API request for OCI', async () => {
64-
ociForecast.runForecast(ForecastType.cost, '');
65-
await waitFor(() => expect(ociForecast.runForecast).toHaveBeenCalled());
44+
forecastUtils.runForecast(ForecastPathsType.oci, ForecastType.cost, '');
45+
await waitFor(() => expect(forecastUtils.runForecast).toHaveBeenCalled());
6646
});
6747

6848
test('runForecast API request for all cloud filtered by OCP', async () => {
69-
ocpCloudForecast.runForecast(ForecastType.cost, '');
70-
await waitFor(() => expect(ocpCloudForecast.runForecast).toHaveBeenCalled());
49+
forecastUtils.runForecast(ForecastPathsType.ocpCloud, ForecastType.cost, '');
50+
await waitFor(() => expect(forecastUtils.runForecast).toHaveBeenCalled());
7151
});
7252

7353
test('runForecast API request for OCP', async () => {
74-
ocpForecast.runForecast(ForecastType.cost, '');
75-
await waitFor(() => expect(ocpForecast.runForecast).toHaveBeenCalled());
54+
forecastUtils.runForecast(ForecastPathsType.ocp, ForecastType.cost, '');
55+
await waitFor(() => expect(forecastUtils.runForecast).toHaveBeenCalled());
7656
});
7757

7858
test('runForecast API request for RHEL', async () => {
79-
rhelForecast.runForecast(ForecastType.cost, '');
80-
await waitFor(() => expect(rhelForecast.runForecast).toHaveBeenCalled());
59+
forecastUtils.runForecast(ForecastPathsType.rhel, ForecastType.cost, '');
60+
await waitFor(() => expect(forecastUtils.runForecast).toHaveBeenCalled());
8161
});

src/api/reports/reportUtils.test.ts

+25-45
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,61 @@
11
import { waitFor } from '@testing-library/react';
22

3-
import * as awsOcpReports from './awsOcpReports';
4-
import * as awsReports from './awsReports';
5-
import * as azureOcpReports from './azureOcpReports';
6-
import * as azureReports from './azureReports';
7-
import * as gcpOcpReports from './gcpOcpReports';
8-
import * as gcpReports from './gcpReports';
9-
import * as ibmReports from './ibmReports';
10-
import * as ociReports from './ociReports';
11-
import * as ocpCloudReports from './ocpCloudReports';
12-
import * as ocpReports from './ocpReports';
13-
import { ReportType } from './report';
14-
import * as rhelReports from './rhelReports';
3+
import { ReportPathsType, ReportType } from './report';
4+
import * as reportUtils from './reportUtils';
155

16-
jest.spyOn(awsReports, 'runReport');
17-
jest.spyOn(awsOcpReports, 'runReport');
18-
jest.spyOn(azureReports, 'runReport');
19-
jest.spyOn(azureOcpReports, 'runReport');
20-
jest.spyOn(gcpReports, 'runReport');
21-
jest.spyOn(gcpOcpReports, 'runReport');
22-
jest.spyOn(ibmReports, 'runReport');
23-
jest.spyOn(ociReports, 'runReport');
24-
jest.spyOn(ocpCloudReports, 'runReport');
25-
jest.spyOn(ocpReports, 'runReport');
26-
jest.spyOn(rhelReports, 'runReport');
6+
jest.spyOn(reportUtils, 'runReport');
277

288
test('runReport API request for AWS', async () => {
29-
awsReports.runReport(ReportType.cost, '');
30-
await waitFor(() => expect(awsReports.runReport).toHaveBeenCalled());
9+
reportUtils.runReport(ReportPathsType.aws, ReportType.cost, '');
10+
await waitFor(() => expect(reportUtils.runReport).toHaveBeenCalled());
3111
});
3212

3313
test('runReport API request for OCP on AWS', async () => {
34-
awsOcpReports.runReport(ReportType.cost, '');
35-
await waitFor(() => expect(awsOcpReports.runReport).toHaveBeenCalled());
14+
reportUtils.runReport(ReportPathsType.awsOcp, ReportType.cost, '');
15+
await waitFor(() => expect(reportUtils.runReport).toHaveBeenCalled());
3616
});
3717

3818
test('runReport API request for Azure', async () => {
39-
azureReports.runReport(ReportType.cost, '');
40-
await waitFor(() => expect(azureReports.runReport).toHaveBeenCalled());
19+
reportUtils.runReport(ReportPathsType.azure, ReportType.cost, '');
20+
await waitFor(() => expect(reportUtils.runReport).toHaveBeenCalled());
4121
});
4222

4323
test('runReport API request for OCP on Azure', async () => {
44-
azureOcpReports.runReport(ReportType.cost, '');
45-
await waitFor(() => expect(azureOcpReports.runReport).toHaveBeenCalled());
24+
reportUtils.runReport(ReportPathsType.azureOcp, ReportType.cost, '');
25+
await waitFor(() => expect(reportUtils.runReport).toHaveBeenCalled());
4626
});
4727

4828
test('runReport API request for GCP', async () => {
49-
gcpReports.runReport(ReportType.cost, '');
50-
await waitFor(() => expect(gcpReports.runReport).toHaveBeenCalled());
29+
reportUtils.runReport(ReportPathsType.gcp, ReportType.cost, '');
30+
await waitFor(() => expect(reportUtils.runReport).toHaveBeenCalled());
5131
});
5232

5333
test('runReport API request for OCP on GCP', async () => {
54-
gcpOcpReports.runReport(ReportType.cost, '');
55-
await waitFor(() => expect(gcpOcpReports.runReport).toHaveBeenCalled());
34+
reportUtils.runReport(ReportPathsType.gcpOcp, ReportType.cost, '');
35+
await waitFor(() => expect(reportUtils.runReport).toHaveBeenCalled());
5636
});
5737

5838
test('runReport API request for IBM', async () => {
59-
ibmReports.runReport(ReportType.cost, '');
60-
await waitFor(() => expect(ibmReports.runReport).toHaveBeenCalled());
39+
reportUtils.runReport(ReportPathsType.ibm, ReportType.cost, '');
40+
await waitFor(() => expect(reportUtils.runReport).toHaveBeenCalled());
6141
});
6242

6343
test('runReport API request for OCI', async () => {
64-
ociReports.runReport(ReportType.cost, '');
65-
await waitFor(() => expect(ociReports.runReport).toHaveBeenCalled());
44+
reportUtils.runReport(ReportPathsType.oci, ReportType.cost, '');
45+
await waitFor(() => expect(reportUtils.runReport).toHaveBeenCalled());
6646
});
6747

6848
test('runReport API request for all cloud filtered by OCP', async () => {
69-
ocpCloudReports.runReport(ReportType.cost, '');
70-
await waitFor(() => expect(ocpCloudReports.runReport).toHaveBeenCalled());
49+
reportUtils.runReport(ReportPathsType.ocpCloud, ReportType.cost, '');
50+
await waitFor(() => expect(reportUtils.runReport).toHaveBeenCalled());
7151
});
7252

7353
test('runReport API request for OCP', async () => {
74-
ocpReports.runReport(ReportType.cost, '');
75-
await waitFor(() => expect(ocpReports.runReport).toHaveBeenCalled());
54+
reportUtils.runReport(ReportPathsType.ocp, ReportType.cost, '');
55+
await waitFor(() => expect(reportUtils.runReport).toHaveBeenCalled());
7656
});
7757

7858
test('runReport API request for RHEL', async () => {
79-
rhelReports.runReport(ReportType.cost, '');
80-
await waitFor(() => expect(rhelReports.runReport).toHaveBeenCalled());
59+
reportUtils.runReport(ReportPathsType.rhel, ReportType.cost, '');
60+
await waitFor(() => expect(reportUtils.runReport).toHaveBeenCalled());
8161
});

0 commit comments

Comments
 (0)