Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Oct 6, 2023
1 parent 2e50e0d commit 432d35c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ describe('bulkEdit()', () => {
});

test('should add system and default actions', async () => {
const newAction = {
const defaultAction = {
frequency: {
notifyWhen: 'onActiveAlert' as const,
summary: false,
Expand All @@ -953,7 +953,7 @@ describe('bulkEdit()', () => {
type: RuleActionTypes.DEFAULT,
};

const newAction2 = {
const systemAction = {
id: 'system_action-id',
params: {},
type: RuleActionTypes.SYSTEM,
Expand All @@ -967,13 +967,21 @@ describe('bulkEdit()', () => {
...existingRule.attributes,
actions: [
{
...newAction,
frequency: {
notifyWhen: 'onActiveAlert' as const,
summary: false,
throttle: null,
},
group: 'default',
id: '1',
params: {},
actionRef: 'action_0',
actionTypeId: 'test-1',
uuid: '222',
},
{
...newAction2,
id: 'system_action-id',
params: {},
actionRef: 'system_action:system_action-id',
actionTypeId: 'test-2',
uuid: '222',
Expand Down Expand Up @@ -1020,7 +1028,7 @@ describe('bulkEdit()', () => {
{
field: 'actions',
operation: 'add',
value: [newAction, newAction2],
value: [defaultAction, systemAction],
},
],
});
Expand Down Expand Up @@ -1073,16 +1081,16 @@ describe('bulkEdit()', () => {
lastExecutionDate: new Date(existingRule.attributes.executionStatus.lastExecutionDate),
},
actions: [
{ ...newAction, actionTypeId: 'test-1', uuid: '222' },
{ ...newAction2, actionTypeId: 'test-2', uuid: '222' },
{ ...defaultAction, actionTypeId: 'test-1', uuid: '222' },
{ ...systemAction, actionTypeId: 'test-2', uuid: '222' },
],
id: existingRule.id,
snoozeSchedule: [],
});
});

test('should construct the refs correctly and not persist the type of the action', async () => {
const newAction = {
const defaultAction = {
frequency: {
notifyWhen: 'onActiveAlert' as const,
summary: false,
Expand All @@ -1094,7 +1102,7 @@ describe('bulkEdit()', () => {
type: RuleActionTypes.DEFAULT,
};

const newAction2 = {
const systemAction = {
id: 'system_action-id',
params: {},
type: RuleActionTypes.SYSTEM,
Expand All @@ -1108,13 +1116,21 @@ describe('bulkEdit()', () => {
...existingRule.attributes,
actions: [
{
...newAction,
frequency: {
notifyWhen: 'onActiveAlert' as const,
summary: false,
throttle: null,
},
group: 'default',
id: '1',
params: {},
actionRef: 'action_0',
actionTypeId: 'test-1',
uuid: '222',
},
{
...newAction2,
id: 'system_action-id',
params: {},
actionRef: 'system_action:system_action-id',
actionTypeId: 'test-2',
uuid: '222',
Expand Down Expand Up @@ -1161,7 +1177,7 @@ describe('bulkEdit()', () => {
{
field: 'actions',
operation: 'add',
value: [newAction, newAction2],
value: [defaultAction, systemAction],
},
],
});
Expand Down Expand Up @@ -1189,7 +1205,7 @@ describe('bulkEdit()', () => {
});

test('should add the actions type to the response correctly', async () => {
const newAction = {
const defaultAction = {
frequency: {
notifyWhen: 'onActiveAlert' as const,
summary: false,
Expand All @@ -1201,7 +1217,7 @@ describe('bulkEdit()', () => {
type: RuleActionTypes.DEFAULT,
};

const newAction2 = {
const systemAction = {
id: 'system_action-id',
params: {},
type: RuleActionTypes.SYSTEM,
Expand All @@ -1215,13 +1231,21 @@ describe('bulkEdit()', () => {
...existingRule.attributes,
actions: [
{
...newAction,
frequency: {
notifyWhen: 'onActiveAlert' as const,
summary: false,
throttle: null,
},
group: 'default',
id: '1',
params: {},
actionRef: 'action_0',
actionTypeId: 'test-1',
uuid: '222',
},
{
...newAction2,
id: 'system_action-id',
params: {},
actionRef: 'system_action:system_action-id',
actionTypeId: 'test-2',
uuid: '222',
Expand Down Expand Up @@ -1268,14 +1292,14 @@ describe('bulkEdit()', () => {
{
field: 'actions',
operation: 'add',
value: [newAction, newAction2],
value: [defaultAction, systemAction],
},
],
});

expect(result.rules[0].actions).toEqual([
{ ...newAction, actionTypeId: 'test-1', uuid: '222' },
{ ...newAction2, actionTypeId: 'test-2', uuid: '222' },
{ ...defaultAction, actionTypeId: 'test-1', uuid: '222' },
{ ...systemAction, actionTypeId: 'test-2', uuid: '222' },
]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,21 +533,21 @@ async function updateRuleAttributesAndParamsInMemory<Params extends RuleParams>(
ruleType.validate.params
);

const {
actions: rawAlertActions,
references,
params: updatedParams,
} = await extractReferences(
const { references, params: updatedParams } = await extractReferences(
context,
ruleType,
updatedRuleActions as NormalizedAlertActionWithGeneratedValues[],
validatedMutatedAlertTypeParams
);

const ruleAttributes = transformRuleDomainToRuleAttributes(updatedRule, {
legacyId: rule.attributes.legacyId,
actionsWithRefs: rawAlertActions,
paramsWithRefs: updatedParams as RuleAttributes['params'],
const ruleAttributes = await transformRuleDomainToRuleAttributes({
actions: updatedRuleActions as NormalizedAlertActionWithGeneratedValues[],
context,
rule: updatedRule,
params: {
legacyId: rule.attributes.legacyId,
paramsWithRefs: updatedParams as RuleAttributes['params'],
},
});

const { apiKeyAttributes } = await prepareApiKeys(
Expand All @@ -565,7 +565,7 @@ async function updateRuleAttributesAndParamsInMemory<Params extends RuleParams>(
ruleAttributes,
apiKeyAttributes,
updatedParams,
rawAlertActions,
ruleAttributes.actions,
username
);

Expand Down

0 comments on commit 432d35c

Please sign in to comment.