Skip to content

Commit b95d397

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

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

webpack/InsightsVulnerabilityHostIndexExtensions/CVECountCell.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ 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+
15+
if (!isIopEnabled) {
16+
return <UnknownIcon />;
17+
}
18+
1319
// eslint-disable-next-line camelcase
1420
const uuid = hostDetails?.subscription_facet_attributes?.uuid;
1521

webpack/InsightsVulnerabilityHostIndexExtensions/__tests__/CVECountCell.test.js

Lines changed: 59 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,69 @@ 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+
74+
const hostDetailsMock = {
75+
name: 'test-host.example.com',
76+
subscription_facet_attributes: {
77+
uuid: 'test-uuid-123',
78+
},
79+
};
80+
2581
render(<CVECountCell hostDetails={hostDetailsMock} />);
2682
expect(screen.getByRole('img', { hidden: true })).toBeTruthy();
83+
expect(ConfigHooks.useAdvisorEngineConfig).toHaveBeenCalled();
2784
});
2885
});

0 commit comments

Comments
 (0)