Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaweiWu committed Jul 17, 2023
1 parent 50d8e5a commit abfd8fa
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { schema } from '@kbn/config-schema';
import { omit } from 'lodash';
import { v4 as uuidv4 } from 'uuid';
import { AlertConsumers } from '@kbn/rule-data-utils';
import { RulesClient, ConstructorOptions } from '../../../../rules_client/rules_client';
Expand Down Expand Up @@ -110,10 +111,21 @@ describe('bulkEdit()', () => {
attributes: {
enabled: false,
tags: ['foo'],
createdBy: 'user',
createdAt: '2019-02-12T21:01:22.479Z',
updatedAt: '2019-02-12T21:01:22.479Z',
legacyId: null,
muteAll: false,
mutedInstanceIds: [],
snoozeSchedule: [],
alertTypeId: 'myType',
schedule: { interval: '1m' },
consumer: 'myApp',
scheduledTaskId: 'task-123',
executionStatus: {
lastExecutionDate: '2019-02-12T21:01:22.479Z',
status: 'pending',
},
params: {},
throttle: null,
notifyWhen: null,
Expand Down Expand Up @@ -249,6 +261,10 @@ describe('bulkEdit()', () => {
schedule: { interval: '1m' },
consumer: 'myApp',
scheduledTaskId: 'task-123',
executionStatus: {
lastExecutionDate: '2019-02-12T21:01:22.479Z',
status: 'pending',
},
params: {},
throttle: null,
notifyWhen: null,
Expand Down Expand Up @@ -306,6 +322,10 @@ describe('bulkEdit()', () => {
schedule: { interval: '1m' },
consumer: 'myApp',
scheduledTaskId: 'task-123',
executionStatus: {
lastExecutionDate: '2019-02-12T21:01:22.479Z',
status: 'pending',
},
params: {},
throttle: null,
notifyWhen: null,
Expand Down Expand Up @@ -359,6 +379,10 @@ describe('bulkEdit()', () => {
schedule: { interval: '1m' },
consumer: 'myApp',
scheduledTaskId: 'task-123',
executionStatus: {
lastExecutionDate: '2019-02-12T21:01:22.479Z',
status: 'pending',
},
params: {},
throttle: null,
notifyWhen: null,
Expand Down Expand Up @@ -626,8 +650,15 @@ describe('bulkEdit()', () => {
],
{ overwrite: true }
);

expect(result.rules[0]).toEqual({
...existingRule.attributes,
...omit(existingRule.attributes, 'legacyId'),
createdAt: new Date(existingRule.attributes.createdAt),
updatedAt: new Date(existingRule.attributes.updatedAt),
executionStatus: {
...existingRule.attributes.executionStatus,
lastExecutionDate: new Date(existingRule.attributes.executionStatus.lastExecutionDate),
},
actions: [existingAction, { ...newAction, uuid: '222' }],
id: existingRule.id,
snoozeSchedule: [],
Expand Down Expand Up @@ -832,7 +863,13 @@ describe('bulkEdit()', () => {
{ overwrite: true }
);
expect(result.rules[0]).toEqual({
...existingRule.attributes,
...omit(existingRule.attributes, 'legacyId'),
createdAt: new Date(existingRule.attributes.createdAt),
updatedAt: new Date(existingRule.attributes.updatedAt),
executionStatus: {
...existingRule.attributes.executionStatus,
lastExecutionDate: new Date(existingRule.attributes.executionStatus.lastExecutionDate),
},
actions: [
existingAction,
{
Expand Down Expand Up @@ -880,6 +917,10 @@ describe('bulkEdit()', () => {
schedule: { interval: '1m' },
consumer: 'myApp',
scheduledTaskId: 'task-123',
executionStatus: {
lastExecutionDate: '2019-02-12T21:01:22.479Z',
status: 'pending',
},
params: {
index: ['test-1', 'test-2', 'test-4', 'test-5'],
},
Expand Down Expand Up @@ -945,6 +986,10 @@ describe('bulkEdit()', () => {
schedule: { interval: '1m' },
consumer: 'myApp',
scheduledTaskId: 'task-123',
executionStatus: {
lastExecutionDate: '2019-02-12T21:01:22.479Z',
status: 'pending',
},
params: {
index: ['test-1'],
},
Expand Down Expand Up @@ -1045,6 +1090,10 @@ describe('bulkEdit()', () => {
schedule: { interval: '1m' },
consumer: 'myApp',
scheduledTaskId: 'task-123',
executionStatus: {
lastExecutionDate: '2019-02-12T21:01:22.479Z',
status: 'pending',
},
params: {},
throttle: null,
notifyWhen: null,
Expand Down Expand Up @@ -1419,7 +1468,7 @@ describe('bulkEdit()', () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(unsecuredSavedObjectsClient.bulkCreate.mock.calls[0][0][0].attributes as any)
.snoozeSchedule
).toBeUndefined();
).toEqual([]);
});
});

Expand Down Expand Up @@ -1496,6 +1545,10 @@ describe('bulkEdit()', () => {
schedule: { interval: '1m' },
consumer: 'myApp',
scheduledTaskId: 'task-123',
executionStatus: {
lastExecutionDate: '2019-02-12T21:01:22.479Z',
status: 'pending',
},
params: {
index: ['index-1', 'index-2', 'index-3'],
},
Expand Down Expand Up @@ -1564,6 +1617,10 @@ describe('bulkEdit()', () => {
schedule: { interval: '1m' },
consumer: 'myApp',
scheduledTaskId: 'task-123',
executionStatus: {
lastExecutionDate: '2019-02-12T21:01:22.479Z',
status: 'pending',
},
params: {
index: ['index-1', 'index-2'],
},
Expand Down Expand Up @@ -1633,6 +1690,10 @@ describe('bulkEdit()', () => {
schedule: { interval: '1m' },
consumer: 'myApp',
scheduledTaskId: 'task-123',
executionStatus: {
lastExecutionDate: '2019-02-12T21:01:22.479Z',
status: 'pending',
},
params: {
index: ['index-1', 'index-2', 'index-3'],
},
Expand Down Expand Up @@ -2046,6 +2107,10 @@ describe('bulkEdit()', () => {
schedule: { interval: '1m' },
consumer: 'myApp',
scheduledTaskId: 'task-123',
executionStatus: {
lastExecutionDate: '2019-02-12T21:01:22.479Z',
status: 'pending',
},
params: { index: ['test-index-*'] },
throttle: null,
notifyWhen: null,
Expand Down Expand Up @@ -2442,6 +2507,10 @@ describe('bulkEdit()', () => {
schedule: { interval: '1m' },
consumer: 'myApp',
scheduledTaskId: 'task-123',
executionStatus: {
lastExecutionDate: '2019-02-12T21:01:22.479Z',
status: 'pending',
},
params: { index: ['test-index-*'] },
throttle: null,
notifyWhen: null,
Expand Down Expand Up @@ -2519,6 +2588,10 @@ describe('bulkEdit()', () => {
schedule: { interval: '1m' },
consumer: 'myApp',
scheduledTaskId: 'task-123',
executionStatus: {
lastExecutionDate: '2019-02-12T21:01:22.479Z',
status: 'pending',
},
params: { index: ['test-index-*'] },
throttle: null,
notifyWhen: null,
Expand Down Expand Up @@ -2556,6 +2629,10 @@ describe('bulkEdit()', () => {
tags: ['foo'],
alertTypeId: 'myType',
schedule: { interval: '1m' },
executionStatus: {
lastExecutionDate: '2019-02-12T21:01:22.479Z',
status: 'pending',
},
consumer: 'myApp',
params: { index: ['test-index-*'] },
throttle: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export async function bulkEditRules<Params extends RuleParams>(

// TODO (http-versioning): This should be of type Rule, change this when all rule types are fixed
const publicRules = updatedRules.map((rule: RuleDomain<Params>) => {
return transformRuleDomainToRule<Params>(rule, { isPublic: true });
return transformRuleDomainToRule<Params>(rule);
}) as Array<SanitizedRule<Params>>;

await bulkUpdateSchedules(context, options.operations, updatedRules);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { rulesClientMock } from '../../../../rules_client.mock';
import { SanitizedRule } from '../../../../types';

const rulesClient = rulesClientMock.create();
jest.mock('../../../../lib/license_state.mock', () => ({
jest.mock('../../../../lib/license_api_access', () => ({
verifyApiAccess: jest.fn(),
}));
beforeEach(() => {
Expand Down

0 comments on commit abfd8fa

Please sign in to comment.