Skip to content

Replace endpoint address constants with helper functions in vulnmanagement integration tests#3131

Merged
pedrottimark merged 5 commits intomasterfrom
cypress-vulnmanagement-apiEndpoints
Sep 20, 2022
Merged

Replace endpoint address constants with helper functions in vulnmanagement integration tests#3131
pedrottimark merged 5 commits intomasterfrom
cypress-vulnmanagement-apiEndpoints

Conversation

@pedrottimark
Copy link
Contributor

@pedrottimark pedrottimark commented Sep 19, 2022

Description

Encapsulate endpoints to reduce the sources of supporting information needed to read or write tests.

Through the experience of fixing 2 minor mistakes that I made in the first draft, I do see a benefit to my understanding from explicitly declaring entity keys for each interaction within a test.

  1. Factor out multiple or parallel references in tests as helper functions which have semantic names:

    • visitVulnerabilityManagementEntityInSidePanel
    • interactAndWaitForVulnerabilityManagementEntity
    • interactAndWaitForVulnerabilityManagementEntities
    • interactAndWaitForVulnerabilityManagementSecondaryEntities
  2. If only one test requires some container-specific information, consider pro and con to write it as inline string in the test, and then factor it out later if there is need to reuse it in other tests.

    • For example, api.vulnMgmt.graphqlOps.getFixableCvesForEntity has only 1 reference.
  3. Delete a few redundant tests which had been skipped for a long time.

Changed files

  1. Edit cypress/constants/apiEndpoints.js

    • Delete vulnMgmt object.
    • Move opnameForEntity, opnameForEntities, opnamePrefixForPrimaryAndSecondaryEntities objects to entities.js file.
  2. Edit cypress/constants/VulnManagementPage.js

    • Delete sidepanel property of url object.
    • Delete applicationAndInfrastructureDropdown property of dashboardSelectors object.
  3. Edit cypress/helpers/vulnmanagement/entities.js

    • Move opnameForEntity, opnameForEntities, opnamePrefixForPrimaryAndSecondaryEntities objects from apiEndpoints.js file.
    • Rename keyForEntity as typeOfEntity because it is the type in workflow state.
    • Add helper functions.
  4. Edit cypress/integration/vulnmanagement/dashboard.test.js

    • Factor out local helper functions for menu items.
    • Call interactAndWaitForVulnerabilityManagementEntities function to wait on relevant request for entities list.
    • Move pathname assertions into helper functions.
    • Replace method chains with pseudo-selectors to reduce risk that cy.get gets DOM elements too soon, and therefore delete timeout options.
    • Replace parseInt function calls with :contains(value) pseudo-selector to reduce risk that cy.get gets DOM elements too soon.
    • Replace skip classic test for CVEs button with 3 tests for CVEs drop-down.
    • Delete 'should properly navigate to the policies list' test which is redundant with the first test.
    • Add test for Top Risky Nodes.
  5. Edit cypress/integration/vulnmanagement/entitypages.test.js

    • Call helper functions to encapsulate intercept-visit-wait sandwich and optional static response for request.
    • Replace parseInt function calls with :contains(value) pseudo-selector to reduce risk that cy.get gets DOM elements too soon.
    • Delete skipped 'should filter deployment count in failing policies section in namespace findings by namespace' test because it is redundant with a test in namespacesListPages.test.js file.
    • Delete skipped 'should filter component count in images list and image overview by cve when coming from cve list' test because it is redundant with tests in imageCvesListPages.test.js file.
    • Replace api.vulnMgmt.graphqlOps.getFixableCvesForEntity with inline string.
  6. Edit cypress/integration/vulnmanagement/imageSection/imageOverview.test.js

    • Get entity id from fixture file.
    • Call visitVulnerabilityManagementEntityInSidePanel function with static response argument for body from fixture file.
  7. Edit cypress/integration/vulnmanagement/nodeSection/nodeOverview.test.js

    • Get entity id from fixture file.
    • Call visitVulnerabilityManagementEntityInSidePanel function with static response argument for body from fixture file.

Checklist

  • Investigated and inspected CI test results
  • Edited integration tests

Testing Performed

Ran changed tests one at a time in local deployment and used inspector with stagingdb for tests which fail because no vulnerabilities:

  • vulnmanagement/dashboard.test.js
  • vulnmanagement/entitypages.test.js
  • vulnmanagement/imageSection/imageOverview.test.js
  • vulnmanagement/nodeSection/nodeOverview.test.js

@ghost
Copy link

ghost commented Sep 19, 2022

Images are ready for the commit at c33f312.

To use with deploy scripts, first export MAIN_IMAGE_TAG=3.72.x-88-gc33f31280f.

@pedrottimark
Copy link
Contributor Author

The following unrelated test failure looks like my bad editing cypress/helpers/compliance.js in #2799

Timed out retrying after 4050ms: expected '<button.flex.items-center.justify-center.border-2.btn.btn-base.h-10.uppercase.lg:min-w-32.xl:min-w-43.text-base-100.hover:bg-primary-800>' not to have attribute 'disabled'
compliance-triggerScan

There was a second click of the Scan button, which makes no sense. Apparently a copy-paste error.

Copy link
Contributor

@vjwilson vjwilson left a comment

Choose a reason for hiding this comment

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

Just one question about some still-skipped tests.

Comment on lines +91 to +93
it.skip('should show same number of Image CVEs in menu item and entities list', () => {
verifyVulnerabilityManagementDashboardCVEs('image-cves', /^\d+ Image CVEs?$/);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

You abstracted the setup into a function verifyVulnerabilityManagementDashboardCVEs(), but did you mean to leave all three of these tests that now use it skip'ed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good eyes. I tested them locally and decided on temporary skip instead of feature flag logic.

When we turn on the feature flag for nightly and release builds, we can remove the skip.

@pedrottimark pedrottimark merged commit 7312f61 into master Sep 20, 2022
@pedrottimark pedrottimark deleted the cypress-vulnmanagement-apiEndpoints branch September 20, 2022 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants