Skip to content

Commit

Permalink
Fix incorrect tags after rule duplication (#104948)
Browse files Browse the repository at this point in the history
  • Loading branch information
xcrzx authored Jul 9, 2021
1 parent b1f2f13 commit 0100528
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,17 @@ describe('add_tags', () => {
const tags2 = addTags(tags1, 'rule-1', false);
expect(tags2).toEqual([
'tag-1',
`${INTERNAL_RULE_ID_KEY}:rule-1`,
`${INTERNAL_IMMUTABLE_KEY}:false`,
]);
});

test('it should overwrite existing immutable tag if it exists', () => {
const tags1 = addTags(['tag-1', `${INTERNAL_IMMUTABLE_KEY}:true`], 'rule-1', false);
expect(tags1).toEqual([
'tag-1',
`${INTERNAL_RULE_ID_KEY}:rule-1`,
`${INTERNAL_IMMUTABLE_KEY}:false`,
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { INTERNAL_RULE_ID_KEY, INTERNAL_IMMUTABLE_KEY } from '../../../../common
export const addTags = (tags: string[], ruleId: string, immutable: boolean): string[] => {
return Array.from(
new Set([
...tags.filter((tag) => !tag.startsWith(INTERNAL_RULE_ID_KEY)),
...tags.filter(
(tag) => !(tag.startsWith(INTERNAL_RULE_ID_KEY) || tag.startsWith(INTERNAL_IMMUTABLE_KEY))
),
`${INTERNAL_RULE_ID_KEY}:${ruleId}`,
`${INTERNAL_IMMUTABLE_KEY}:${immutable}`,
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ describe('duplicateRule', () => {
},
"tags": Array [
"test",
"__internal_immutable:false",
"__internal_rule_id:newId",
"__internal_immutable:false",
],
"throttle": null,
}
Expand Down

0 comments on commit 0100528

Please sign in to comment.