Skip to content

Commit fe1e716

Browse files
committed
SAT-37395 - Don't make API call for cveColumn if non-iop
1 parent 8e8cee6 commit fe1e716

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

webpack/InsightsVulnerabilityHostIndexExtensions/CVECountCell.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,31 @@ import PropTypes from 'prop-types';
33
import { UnknownIcon } from '@patternfly/react-icons';
44
import { Link } from 'react-router-dom';
55
import { useAPI } from 'foremanReact/common/hooks/API/APIHooks';
6-
76
import { insightsCloudUrl } from '../InsightsCloudSync/InsightsCloudSyncHelpers';
7+
import { useAdvisorEngineConfig } from '../common/Hooks/ConfigHooks';
88

99
const vulnerabilityApiPath = path =>
1010
insightsCloudUrl(`api/vulnerability/v1/${path}`);
1111

1212
export const CVECountCell = ({ hostDetails }) => {
13+
const isIopEnabled = useAdvisorEngineConfig();
14+
1315
// eslint-disable-next-line camelcase
1416
const uuid = hostDetails?.subscription_facet_attributes?.uuid;
1517

1618
const key = `HOST_CVE_COUNT_${uuid}`;
1719
const response = useAPI(
18-
uuid ? 'get' : null,
20+
isIopEnabled && uuid ? 'get' : null,
1921
vulnerabilityApiPath(`systems?uuid=${uuid}`),
2022
{
2123
key,
2224
}
2325
);
2426

27+
if (!isIopEnabled) {
28+
return <UnknownIcon />;
29+
}
30+
2531
if (uuid === undefined) {
2632
return <UnknownIcon />;
2733
}

webpack/InsightsVulnerabilityHostIndexExtensions/__tests__/CVECountCell.test.js

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import React from 'react';
22
import { render, screen } from '@testing-library/react';
33
import { API } from 'foremanReact/redux/API';
44
import { CVECountCell } from '../CVECountCell';
5+
import * as ConfigHooks from '../../common/Hooks/ConfigHooks';
56

67
jest.mock('foremanReact/redux/API');
8+
jest.mock('../../common/Hooks/ConfigHooks');
9+
710
API.get.mockImplementation(async () => ({
811
data: [
912
{
@@ -14,15 +17,62 @@ API.get.mockImplementation(async () => ({
1417
],
1518
}));
1619

20+
const hostDetailsMock = {
21+
name: 'test-host.example.com',
22+
subscription_facet_attributes: {
23+
uuid: 'test-uuid-123',
24+
},
25+
};
26+
1727
describe('CVECountCell', () => {
18-
it('renders an empty cves count column', () => {
19-
const hostDetailsMock = {
28+
beforeEach(() => {
29+
ConfigHooks.useAdvisorEngineConfig.mockReturnValue(true);
30+
});
31+
32+
afterEach(() => {
33+
jest.clearAllMocks();
34+
});
35+
36+
it('renders an empty cves count column when no subscription UUID', () => {
37+
const hostDetailsMockIoP = {
2038
name: 'test-host.example.com',
2139
subscription_facet_attributes: {
2240
uuid: null, // no subscription
2341
},
2442
};
43+
render(<CVECountCell hostDetails={hostDetailsMockIoP} />);
44+
expect(screen.getByRole('img', { hidden: true })).toBeTruthy();
45+
});
46+
47+
it('renders UnknownIcon when IoP is not enabled', () => {
48+
ConfigHooks.useAdvisorEngineConfig.mockReturnValue(false);
49+
50+
render(<CVECountCell hostDetails={hostDetailsMock} />);
51+
expect(screen.getByRole('img', { hidden: true })).toBeTruthy();
52+
expect(ConfigHooks.useAdvisorEngineConfig).toHaveBeenCalled();
53+
});
54+
55+
it('renders UnknownIcon when IoP is enabled but CVE API call fails', () => {
56+
// Mock successful IoP config
57+
ConfigHooks.useAdvisorEngineConfig.mockReturnValue(true);
58+
59+
// Mock CVE API failure - override the global mock for this test
60+
API.get.mockImplementationOnce(async () => {
61+
throw new Error('CVE API call failed');
62+
});
63+
64+
render(<CVECountCell hostDetails={hostDetailsMock} />);
65+
66+
// Should render UnknownIcon when CVE API fails
67+
expect(screen.getByRole('img', { hidden: true })).toBeTruthy();
68+
expect(ConfigHooks.useAdvisorEngineConfig).toHaveBeenCalled();
69+
});
70+
71+
it('renders UnknownIcon when IoP is undefined (API call pending)', () => {
72+
ConfigHooks.useAdvisorEngineConfig.mockReturnValue(undefined);
73+
2574
render(<CVECountCell hostDetails={hostDetailsMock} />);
2675
expect(screen.getByRole('img', { hidden: true })).toBeTruthy();
76+
expect(ConfigHooks.useAdvisorEngineConfig).toHaveBeenCalled();
2777
});
2878
});

0 commit comments

Comments
 (0)