Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.7] [Security Solution] Allow rewriting rule create props in Cypress tests (#153474) #154332

Merged
merged 1 commit into from
Apr 4, 2023

Conversation

maximpn
Copy link
Contributor

@maximpn maximpn commented Apr 4, 2023

Backport

This will backport the following commits from main to 8.7:

Questions ?

Please refer to the Backport tool documentation

elastic#153474)

**Relates to:** elastic#150553

## Summary

This PR is based on the review comments in elastic#150553. It allows to rewrite rule create properties.

## Details

Rule create properties are returned by helper functions like `getNewRule()`, `getNewThresholdRule()` and so on. So instead of `createRule({ ...getNewRule(), index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' })` it allows to use a concise and a much more readable structure `createRule(getNewRule({ index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' ))`.

## Possible improvements

The PR doesn't implement deep / nested fields merge. High level fields completely rewrite default values. Deep merge would allow to extend defaults with the provided rewrites. For example, overriding nested properties become tiresome quickly, as shown in the following code snippet:

```ts
const rule = {
  ...getNewTermsRule(),
  rule_id: 'new_rule_id',
  runsEvery: {
    interval: '1',
    ...getNewTermsRule().runsEvery,
  },
};
```

If we implement deep merge, the readability could be greatly improved:

```ts
const rule = getNewTermsRule({
  rule_id: 'new_rule_id',
  runsEvery: {
    interval: '1',
  },
});
```

While it looks as a good idea we should take into consideration the fact that complete rewriting of default values can be a desired behavior. Engineers could tend to switch to `createRule({ ...getNewRule(), index: undefined, data_view_id: DATA_VIEW_ID, rule_id: '1' })` to overcome deep merge. So it should be analysed carefully before implementing it.

(cherry picked from commit ca696ac)

# Conflicts:
#	x-pack/plugins/security_solution/cypress/e2e/detection_alerts/alerts_charts.cy.ts
#	x-pack/plugins/security_solution/cypress/e2e/detection_alerts/detection_page_filters.cy.ts
#	x-pack/plugins/security_solution/cypress/e2e/exceptions/add_edit_flyout/flyout_validation.cy.ts
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@maximpn maximpn merged commit 5b7d183 into elastic:8.7 Apr 4, 2023
1 check passed
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.

None yet

2 participants