Skip to content

Conversation

@chris1984
Copy link
Member

@chris1984 chris1984 commented Oct 4, 2025

What are the changes introduced in this pull request?

  • Used useAdvisorEngineConfig hook to check for iop status and add it to the conditional for the api call with uuid
  • Added tests

Considerations taken when implementing this change?

What are the testing steps for this pull request?

  • Check out PR on a iop-box
  • Register a client with sub-man and insights-client
  • Verify you see the API call
Screenshot 2025-10-02 163732 * Check out pr on a non-iop box * Register a client with sub-man and insights-client * Verify you see don't the API call

Summary by Sourcery

Gate CVECountCell API calls on IoP enablement by using the useAdvisorEngineConfig hook and update tests to cover IoP-enabled, IoP-disabled, and API pending scenarios

Enhancements:

  • Add IoP status check in CVECountCell to only fetch CVE counts when IoP is enabled
  • Return UnknownIcon early for non-IoP setups to avoid unnecessary API calls

Tests:

  • Mock useAdvisorEngineConfig in CVECountCell tests and clear mocks between each test
  • Add tests to verify UnknownIcon rendering and omission of API calls when IoP is disabled or undefined

@sourcery-ai
Copy link

sourcery-ai bot commented Oct 4, 2025

Reviewer's Guide

This PR integrates the useAdvisorEngineConfig hook to conditionally enable CVE API calls only for IoP-enabled hosts and adds corresponding tests to verify behavior in IoP, non-IoP, and pending scenarios.

Sequence diagram for conditional CVE API call based on IoP status

sequenceDiagram
    participant "CVECountCell"
    participant "useAdvisorEngineConfig()"
    participant "useAPI()"
    participant "API Server"
    "CVECountCell"->>"useAdvisorEngineConfig()": Check IoP status
    "useAdvisorEngineConfig()"-->>"CVECountCell": Return isIopEnabled
    alt IoP enabled and uuid exists
        "CVECountCell"->>"useAPI()": Request CVE count (GET systems?uuid=...)
        "useAPI()"->>"API Server": Make API call
        "API Server"-->>"useAPI()": Return CVE data
        "useAPI()"-->>"CVECountCell": Provide CVE data
    else Not IoP enabled or uuid missing
        "CVECountCell"-->>"CVECountCell": Render UnknownIcon (no API call)
    end
Loading

File-Level Changes

Change Details Files
Add IoP status guard to CVE API call
  • Import useAdvisorEngineConfig and fetch isIopEnabled
  • Update useAPI call to require both isIopEnabled and uuid
  • Add early return UnknownIcon when IoP is disabled
webpack/InsightsVulnerabilityHostIndexExtensions/CVECountCell.js
Expand CVECountCell tests for IoP conditions
  • Mock useAdvisorEngineConfig true/false/undefined in beforeEach
  • Clear mocks after each test
  • Test UnknownIcon rendering for non-IoP and pending states and verify hook invocation
webpack/InsightsVulnerabilityHostIndexExtensions/__tests__/CVECountCell.test.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `webpack/InsightsVulnerabilityHostIndexExtensions/__tests__/CVECountCell.test.js:36-38` </location>
<code_context>
+    jest.clearAllMocks();
+  });
+
+  it('renders an empty cves count column when no subscription UUID', () => {
     const hostDetailsMock = {
       name: 'test-host.example.com',
</code_context>

<issue_to_address>
**suggestion (testing):** Consider adding a test for when the subscription_facet_attributes object itself is missing.

Testing for missing subscription_facet_attributes will ensure the code handles incomplete hostDetails objects correctly.

```suggestion
  it('renders an empty cves count column when no subscription UUID', () => {
    const hostDetailsMock = {
      name: 'test-host.example.com',
      subscription_facet_attributes: {
    render(<CVECountCell hostDetails={hostDetailsMock} />);
    expect(screen.getByRole('img', { hidden: true })).toBeTruthy();
  });

  it('renders an empty cves count column when subscription_facet_attributes is missing', () => {
    const hostDetailsMock = {
      name: 'test-host.example.com'
      // subscription_facet_attributes is intentionally missing
    };
    render(<CVECountCell hostDetails={hostDetailsMock} />);
    expect(screen.getByRole('img', { hidden: true })).toBeTruthy();
  });
```
</issue_to_address>

### Comment 2
<location> `webpack/InsightsVulnerabilityHostIndexExtensions/__tests__/CVECountCell.test.js:55-52` </location>
<code_context>
+    expect(ConfigHooks.useAdvisorEngineConfig).toHaveBeenCalled();
+  });
+
+  it('renders UnknownIcon when IoP is undefined (API call pending)', () => {
+    ConfigHooks.useAdvisorEngineConfig.mockReturnValue(undefined);
+    
+    const hostDetailsMock = {
+      name: 'test-host.example.com',
+      subscription_facet_attributes: {
+        uuid: 'test-uuid-123',
+      },
+    };
+    
+    render(<CVECountCell hostDetails={hostDetailsMock} />);
+    expect(screen.getByRole('img', { hidden: true })).toBeTruthy();
+    expect(ConfigHooks.useAdvisorEngineConfig).toHaveBeenCalled();
+  });
 });
</code_context>

<issue_to_address>
**suggestion (testing):** Consider adding a test for when IoP is true but the API call returns an error.

Adding a test for IoP being true with a valid uuid, but the API call failing, will verify the component's error handling in this scenario.

Suggested implementation:

```javascript
    expect(ConfigHooks.useAdvisorEngineConfig).toHaveBeenCalled();
  });

  it('renders error handling UI when IoP is true and API call fails', () => {
    // Simulate IoP true with valid uuid
    const hostDetailsMock = {
      name: 'test-host.example.com',
      subscription_facet_attributes: {
        uuid: 'test-uuid-123',
      },
    };

    // Simulate API call failure
    ConfigHooks.useAdvisorEngineConfig.mockImplementation(() => {
      throw new Error('API call failed');
    });

    render(<CVECountCell hostDetails={hostDetailsMock} />);
    // Adjust the selector below to match your error UI (icon, message, etc.)
    expect(screen.getByTestId('cve-count-error-icon')).toBeInTheDocument();
    expect(ConfigHooks.useAdvisorEngineConfig).toHaveBeenCalled();
  });

```

- Ensure that your `CVECountCell` component renders an element with `data-testid="cve-count-error-icon"` (or similar) when an error occurs. If your error UI uses a different selector, update the test accordingly.
- If your error handling is not based on throwing errors but on returning an error object, adjust the mock and assertions to match your implementation.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@chris1984 chris1984 force-pushed the hide-cvecolumn branch 2 times, most recently from f4d2397 to d5c7710 Compare October 4, 2025 02:49
@chris1984 chris1984 force-pushed the hide-cvecolumn branch 2 times, most recently from cc2475c to b95d397 Compare October 6, 2025 21:32
@chris1984 chris1984 requested a review from lfu October 6, 2025 21:33
@chris1984 chris1984 force-pushed the hide-cvecolumn branch 2 times, most recently from d82cd05 to 65f691e Compare October 7, 2025 13:53
@chris1984 chris1984 force-pushed the hide-cvecolumn branch 2 times, most recently from fe1e716 to 9e0027e Compare October 7, 2025 14:11
Copy link
Collaborator

@lfu lfu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and verified for both IoP and non-IoP 👍

@chris1984 chris1984 merged commit a4d194a into theforeman:develop Oct 7, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants