Skip to content

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

Merged
maximpn merged 1 commit intoelastic:8.7from
maximpn:backport/8.7/pr-153474
Apr 4, 2023
Merged

[8.7] [Security Solution] Allow rewriting rule create props in Cypress tests (#153474)#154332
maximpn merged 1 commit intoelastic:8.7from
maximpn:backport/8.7/pr-153474

Conversation

@maximpn
Copy link
Copy Markdown
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
@maximpn maximpn added the backport This PR is a backport of another PR label Apr 4, 2023
@maximpn maximpn enabled auto-merge (squash) April 4, 2023 11:22
@kibana-ci
Copy link
Copy Markdown

💚 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
@maximpn maximpn deleted the backport/8.7/pr-153474 branch March 9, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants