[8.10] [Security Solution] Fix Related integrations Cypress test (#165481) (#165501)

# Backport

This will backport the following commits from `main` to `8.10`:
- [[Security Solution] Fix Related integrations Cypress test
(#165481)](https://github.com/elastic/kibana/pull/165481)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Juan Pablo
Djeredjian","email":"jpdjeredjian@gmail.com"},"sourceCommit":{"committedDate":"2023-09-01T16:32:13Z","message":"[Security
Solution] Fix Related integrations Cypress test
(#165481)","sha":"d2381149fdaae6070fa007953f3969924916a6e9","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["test","release_note:skip","Team:Detections
and Resp","Team: SecuritySolution","Team:Detection Rule
Management","Feature:Related
Integrations","v8.10.0","v8.11.0"],"number":165481,"url":"https://github.com/elastic/kibana/pull/165481","mergeCommit":{"message":"[Security
Solution] Fix Related integrations Cypress test
(#165481)","sha":"d2381149fdaae6070fa007953f3969924916a6e9"}},"sourceBranch":"main","suggestedTargetBranches":["8.10"],"targetPullRequestStates":[{"branch":"8.10","label":"v8.10.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/165481","number":165481,"mergeCommit":{"message":"[Security
Solution] Fix Related integrations Cypress test
(#165481)","sha":"d2381149fdaae6070fa007953f3969924916a6e9"}}]}]
BACKPORT-->

Co-authored-by: Juan Pablo Djeredjian <jpdjeredjian@gmail.com>
This commit is contained in:
Kibana Machine 2023-09-01 13:41:06 -04:00 committed by GitHub
parent 181820026a
commit de6c207632
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -222,14 +222,29 @@ describe('Related integrations', { tags: [tag.ESS, tag.BROKEN_IN_SERVERLESS] },
openTable();
filterBy(RELATED_INTEGRATION_FIELD);
RULE_RELATED_INTEGRATIONS.forEach((integration) => {
cy.contains(
FIELD(RELATED_INTEGRATION_FIELD),
`{"package":"${integration.package}"${
integration.integration ? `,"integration":"${integration.integration}"` : ''
},"version":"${integration.version}"}`
);
});
cy.get(FIELD(RELATED_INTEGRATION_FIELD))
.invoke('text')
.then((stringValue) => {
// Integrations are displayed in the flyout as a string with a format like so:
// '{"package":"aws","version":"1.17.0","integration":"unknown"}{"package":"mock","version":"1.1.0"}{"package":"system","version":"1.17.0"}'
// We need to parse it to an array of valid objects before we can compare it to the expected value
// Otherwise, the test might fail because of the order of the properties in the objects in the string
const jsonStringArray = stringValue.split('}{');
const validJsonStringArray = createValidJsonStringArray(jsonStringArray);
const parsedIntegrations = validJsonStringArray.map((jsonString) =>
JSON.parse(jsonString)
);
RULE_RELATED_INTEGRATIONS.forEach((integration) => {
expect(parsedIntegrations).to.deep.include({
package: integration.package,
version: integration.version,
...(integration.integration ? { integration: integration.integration } : {}),
});
});
});
});
});
});
@ -408,3 +423,14 @@ const AWS_PACKAGE_POLICY: PackagePolicyWithoutAgentPolicyId = {
},
},
};
const createValidJsonStringArray = (jsonStringArray: string[]) =>
jsonStringArray.map((jsonString, index) => {
if (index === 0) {
return `${jsonString}}`;
} else if (index === jsonStringArray.length - 1) {
return `{${jsonString}`;
} else {
return `{${jsonString}}`;
}
});