Fixes migration bug where I was deleting attributes (#115098)

## Summary

During the work here: https://github.com/elastic/kibana/pull/113577

I accidentally have introduced a bug where on migration I was deleting the attributes of `ruleThrottle` and `alertThrottle` because I was not using splat correctly.

Added unit and e2e tests to fix this.

### Checklist
- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
This commit is contained in:
Frank Hassanabad 2021-10-15 18:37:36 -06:00 committed by GitHub
parent 55235c61e5
commit 95e412b4a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

View file

@ -20,6 +20,8 @@ describe('legacy_migrations', () => {
test('it migrates both a "ruleAlertId" and a actions array with 1 element into the references array', () => {
const doc = {
attributes: {
ruleThrottle: '1d',
alertThrottle: '1d',
ruleAlertId: '123',
actions: [
{
@ -37,6 +39,8 @@ describe('legacy_migrations', () => {
)
).toEqual({
attributes: {
ruleThrottle: '1d',
alertThrottle: '1d',
actions: [
{
actionRef: 'action_0',

View file

@ -245,7 +245,7 @@ export const legacyMigrateRuleAlertId = (
return {
...doc,
attributes: {
...attributesWithoutRuleAlertId.attributes,
...attributesWithoutRuleAlertId,
actions: actionsWithRef,
},
references: [...existingReferences, ...alertReferences, ...actionsReferences],

View file

@ -65,6 +65,27 @@ export default ({ getService }: FtrProviderContext): void => {
undefined
);
});
it('migrates legacy siem-detection-engine-rule-actions and retains "ruleThrottle" and "alertThrottle" as the same attributes as before', async () => {
const response = await es.get<{
'siem-detection-engine-rule-actions': {
ruleThrottle: string;
alertThrottle: string;
};
}>({
index: '.kibana',
id: 'siem-detection-engine-rule-actions:fce024a0-0452-11ec-9b15-d13d79d162f3',
});
expect(response.statusCode).to.eql(200);
// "alertThrottle" and "ruleThrottle" should still exist
expect(response.body._source?.['siem-detection-engine-rule-actions'].alertThrottle).to.eql(
'7d'
);
expect(response.body._source?.['siem-detection-engine-rule-actions'].ruleThrottle).to.eql(
'7d'
);
});
});
});
};