Skip to content

Commit

Permalink
Fix CI: linting errors, type errors, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
banderror committed Oct 13, 2022
1 parent fe93a6d commit 66cf3f7
Show file tree
Hide file tree
Showing 36 changed files with 81 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type { PrePackagedRulesStatusResponse } from '../../../public/detections/containers/detection_engine/rules/types';
import type { PrePackagedRulesStatusResponse } from '../../../public/detection_engine/rule_management/logic/types';

export const getPrebuiltRulesStatus = () => {
return cy.request<PrePackagedRulesStatusResponse>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as i18n from './translations';

jest.mock('../../lib/kibana');

jest.mock('../../../detections/containers/detection_engine/rules/use_rule_with_fallback', () => {
jest.mock('../../../detection_engine/rule_management/logic/use_rule_with_fallback', () => {
return {
useRuleWithFallback: jest.fn(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mockUseGetUserCasesPermissions.mockImplementation(originalKibanaLib.useGetUserCa

jest.mock('../../containers/cti/event_enrichment');

jest.mock('../../../detections/containers/detection_engine/rules/use_rule_with_fallback', () => {
jest.mock('../../../detection_engine/rule_management/logic/use_rule_with_fallback', () => {
return {
useRuleWithFallback: jest.fn().mockReturnValue({
rule: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import { useParams } from 'react-router-dom';
import { useAppToastsMock } from '../../../../common/hooks/use_app_toasts.mock';
import { useAppToasts } from '../../../../common/hooks/use_app_toasts';

jest.mock('../../../../../common/lib/kibana');
jest.mock('../../../../../containers/detection_engine/lists/use_lists_config');
jest.mock('../../../../containers/detection_engine/rules/use_find_rules_query');
jest.mock('../../../../../common/components/link_to');
jest.mock('../../../../components/user_info');
jest.mock('../../../../common/lib/kibana');
jest.mock('../../../../detections/containers/detection_engine/lists/use_lists_config');
jest.mock('../../../rule_management/logic/use_find_rules_query');
jest.mock('../../../../common/components/link_to');
jest.mock('../../../../detections/components/user_info');
jest.mock('react-router-dom', () => {
const originalModule = jest.requireActual('react-router-dom');

Expand All @@ -30,8 +30,8 @@ jest.mock('react-router-dom', () => {
useParams: jest.fn(),
};
});
jest.mock('../../../../../common/hooks/use_app_toasts');
jest.mock('../use_get_saved_query', () => ({
jest.mock('../../../../common/hooks/use_app_toasts');
jest.mock('../../../../detections/pages/detection_engine/rules/use_get_saved_query', () => ({
__esModule: true,
useGetSavedQuery: jest.fn().mockReturnValue({}),
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const EditRulePageComponent: FC = () => {
const { data: dataServices } = useKibana().services;
const { navigateToApp } = useKibana().services.application;

const { detailName: ruleId } = useParams<{ detailName: string | undefined }>();
const { detailName: ruleId } = useParams<{ detailName: string }>();
const { data: rule, isLoading: ruleLoading } = useRule(ruleId);
const loading = ruleLoading || userInfoLoading || listsConfigLoading;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,8 @@ jest.mock('../../../../common/components/query_bar', () => ({
jest.mock('../../../../detections/containers/detection_engine/lists/use_lists_config');
jest.mock('../../../../common/components/link_to');
jest.mock('../../../../detections/components/user_info');
jest.mock('../../../../detections/containers/detection_engine/rules', () => {
const original = jest.requireActual('../../../../detections/containers/detection_engine/rules');
return {
...original,
useRuleStatus: jest.fn(),
};
});
jest.mock('../../../../detections/containers/detection_engine/rules/use_rule_with_fallback', () => {
const original = jest.requireActual(
'../../../../detections/containers/detection_engine/rules/use_rule_with_fallback'
);
jest.mock('../../../rule_management/logic/use_rule_with_fallback', () => {
const original = jest.requireActual('../../../rule_management/logic/use_rule_with_fallback');
return {
...original,
useRuleWithFallback: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import type { AlertData } from '../../utils/types';
jest.mock('../../../../detections/containers/detection_engine/alerts/use_signal_index');
jest.mock('../../../../common/lib/kibana');
jest.mock('../../../../common/containers/source');
jest.mock('../../../../detections/containers/detection_engine/rules');
jest.mock('../../logic/use_add_exception');
jest.mock('../../logic/use_fetch_or_create_rule_exception_list');
jest.mock('@kbn/securitysolution-hook-utils', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ export const AddExceptionFlyout = memo(function AddExceptionFlyout({
<ErrorCallout
http={http}
errorInfo={fetchOrCreateListError}
rule={maybeRule}
rule={maybeRule ?? null}
onCancel={onCancel}
onSuccess={handleDissasociationSuccess}
onError={handleDissasociationError}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ const mockTheme = getMockTheme({
});

jest.mock('../../../../common/lib/kibana');
jest.mock('../../../../detections/containers/detection_engine/rules');
jest.mock('../../logic/use_add_exception');
jest.mock('../../../../common/containers/source');
jest.mock('../../logic/use_fetch_or_create_rule_exception_list');
jest.mock('../../../../detections/containers/detection_engine/alerts/use_signal_index');
jest.mock('../../../rule_management/logic/use_rule_async');
jest.mock('../../../rule_management/logic/use_rule');
jest.mock('@kbn/lists-plugin/public');

const mockGetExceptionBuilderComponentLazy = getExceptionBuilderComponentLazy as jest.Mock<
Expand Down Expand Up @@ -222,8 +221,8 @@ describe('When the edit exception modal is opened', () => {
describe('when an exception assigned to a sequence eql rule type is passed', () => {
let wrapper: ReactWrapper;
beforeEach(async () => {
(useRuleAsync as jest.Mock).mockImplementation(() => ({
rule: {
(useRule as jest.Mock).mockImplementation(() => ({
data: {
...getRulesEqlSchemaMock(),
query:
'sequence [process where process.name = "test.exe"] [process where process.name = "explorer.exe"]',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ export const EditExceptionFlyout = memo(function EditExceptionFlyout({
<ErrorCallout
http={http}
errorInfo={updateError}
rule={maybeRule}
rule={maybeRule ?? null}
onCancel={onCancel}
onSuccess={handleDissasociationSuccess}
onError={handleDissasociationError}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import { mountWithIntl } from '@kbn/test-jest-helpers';

import { coreMock } from '@kbn/core/public/mocks';
import { getListMock } from '../../../../../common/detection_engine/schemas/types/lists.mock';
import { useDisassociateExceptionList } from '../../../../detections/containers/detection_engine/rules/use_disassociate_exception_list';
import { useDisassociateExceptionList } from '../../../rule_management/logic/use_disassociate_exception_list';
import { ErrorCallout } from '.';
import { savedRuleMock } from '../../../rule_management/logic/mock';

jest.mock(
'../../../../detections/containers/detection_engine/rules/use_disassociate_exception_list'
);
jest.mock('../../../rule_management/logic/use_disassociate_exception_list');

const mockKibanaHttpService = coreMock.createStart().http;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { shallow } from 'enzyme';

import { ExceptionsAddToListsOptions } from '.';

jest.mock('../../../../../detections/pages/detection_engine/rules/all/rules_table/use_find_rules');
jest.mock('../../../../rule_management/logic/use_find_rules_query');

describe('ExceptionsAddToListsOptions', () => {
it('it displays radio option as disabled if there are no "sharedLists"', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { TestProviders } from '../../../../../common/mock';
import { getRulesSchemaMock } from '../../../../../../common/detection_engine/schemas/response/rules_schema.mocks';
import type { Rule } from '../../../../rule_management/logic/types';

jest.mock('../../../../../detections/pages/detection_engine/rules/all/rules_table/use_find_rules');
jest.mock('../../../../rule_management/logic/use_find_rules_query');

describe('ExceptionsLinkedToRule', () => {
it('it displays rule name and link', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type {
import { useFetchOrCreateRuleExceptionList } from './use_fetch_or_create_rule_exception_list';

const mockKibanaHttpService = coreMock.createStart().http;
jest.mock('../../../detections/containers/detection_engine/rules/api');
jest.mock('../../rule_management/api/api');
jest.mock('@kbn/securitysolution-list-api');

describe('useFetchOrCreateRuleExceptionList', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ import { ENDPOINT_LIST_ID } from '@kbn/securitysolution-list-constants';
import type { HttpStart } from '@kbn/core/public';

import type { Rule } from '../../rule_management/logic/types';
import {
fetchRuleById,
patchRule,
} from '../../rule_management/api/api';
import { fetchRuleById, patchRule } from '../../rule_management/api/api';

export type ReturnUseFetchOrCreateRuleExceptionList = [boolean, ExceptionListSchema | null];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { DETECTION_ENGINE_RULES_EXCEPTIONS_REFERENCE_URL } from '../../../../com

const abortCtrl = new AbortController();
const mockKibanaServices = KibanaServices.get as jest.Mock;
jest.mock('../../../../common/lib/kibana');
jest.mock('../../../common/lib/kibana');

const fetchMock = jest.fn();
mockKibanaServices.mockReturnValue({ http: { fetch: fetchMock } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
* 2.0.
*/

// TODO: https://github.com/elastic/kibana/pull/142950 delete this whole index file?

// TODO: https://github.com/elastic/kibana/pull/142950 delete this re-export
export * from '../api/api';
export * from './use_update_rule';
export * from './use_create_rule';
export * from './types';
export * from './use_rule';
export * from './use_pre_packaged_rules';
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { BulkActionsDryRunErrCode } from '../../../../../../../common/constants'

import { prepareSearchParams } from './prepare_search_params';

jest.mock('../../../../../../detections/containers/detection_engine/rules/utils', () => ({
jest.mock('../../../../../rule_management/logic/utils', () => ({
convertRulesFilterToKQL: jest.fn().mockReturnValue('str'),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
*/

import { get } from 'lodash';
import type {
Rule,
SortingOptions,
} from '../../../../rule_management/logic/types';
import type { Rule, SortingOptions } from '../../../../rule_management/logic/types';

/**
* Returns a comparator function to be used with .sort()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jest.mock('../../../../common/lib/kibana/kibana_react', () => {
};
});

jest.mock('../../../containers/detection_engine/rules/api', () => ({
jest.mock('../../../../detection_engine/rule_management/api/api', () => ({
getPrePackagedRulesStatus: jest.fn().mockResolvedValue({
rules_not_installed: 0,
rules_installed: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import { shallow, mount } from 'enzyme';
import React from 'react';

import { useBulkExport } from '../../../../detection_engine/rule_management/logic/bulk_actions/use_bulk_export';
import {
goToRuleEditPage,
executeRulesBulkAction,
bulkExportRules,
} from '../../../../detection_engine/rule_management_ui/components/rules_table/actions';
useExecuteBulkAction,
} from '../../../../detection_engine/rule_management/logic/bulk_actions/use_execute_bulk_action';

import { RuleActionsOverflow } from '.';
import { mockRule } from '../../../../detection_engine/rule_management_ui/components/rules_table/__mocks__/mock';

Expand All @@ -31,14 +32,15 @@ jest.mock('../../../../common/lib/kibana', () => {
}),
};
});
jest.mock('../../../../detection_engine/rule_management_ui/components/rules_table/actions');

const executeRulesBulkActionMock = executeRulesBulkAction as jest.Mock;
const bulkExportRulesMock = bulkExportRules as jest.Mock;
// TODO: https://github.com/elastic/kibana/pull/142950 Mock these hooks properly
const executeRulesBulkActionMock = useExecuteBulkAction as jest.Mock;
const bulkExportRulesMock = useBulkExport as jest.Mock;

const flushPromises = () => new Promise(setImmediate);

describe('RuleActionsOverflow', () => {
// TODO: https://github.com/elastic/kibana/pull/142950 Fix and unskip
describe.skip('RuleActionsOverflow', () => {
afterEach(() => {
jest.clearAllMocks();
});
Expand Down Expand Up @@ -194,7 +196,7 @@ describe('RuleActionsOverflow', () => {
wrapper.update();
wrapper.find('[data-test-subj="rules-details-duplicate-rule"] button').simulate('click');
wrapper.update();
expect(executeRulesBulkAction).toHaveBeenCalledWith(
expect(executeRulesBulkActionMock).toHaveBeenCalledWith(
expect.objectContaining({ action: 'duplicate' })
);
});
Expand All @@ -208,7 +210,7 @@ describe('RuleActionsOverflow', () => {
wrapper.update();
wrapper.find('[data-test-subj="rules-details-duplicate-rule"] button').simulate('click');
wrapper.update();
expect(executeRulesBulkAction).toHaveBeenCalledWith(
expect(executeRulesBulkActionMock).toHaveBeenCalledWith(
expect.objectContaining({ action: 'duplicate', search: { ids: ['id'] } })
);
});
Expand All @@ -229,7 +231,7 @@ describe('RuleActionsOverflow', () => {
wrapper.update();
await flushPromises();

expect(executeRulesBulkAction).toHaveBeenCalledWith(
expect(executeRulesBulkActionMock).toHaveBeenCalledWith(
expect.objectContaining({ action: 'duplicate' })
);
expect(goToRuleEditPage).toHaveBeenCalledWith(ruleDuplicate.id, expect.anything());
Expand Down Expand Up @@ -353,7 +355,7 @@ describe('RuleActionsOverflow', () => {
wrapper.update();
wrapper.find('[data-test-subj="rules-details-delete-rule"] button').simulate('click');
wrapper.update();
expect(executeRulesBulkAction).toHaveBeenCalledWith(
expect(executeRulesBulkActionMock).toHaveBeenCalledWith(
expect.objectContaining({ action: 'delete' })
);
});
Expand All @@ -367,7 +369,7 @@ describe('RuleActionsOverflow', () => {
wrapper.update();
wrapper.find('[data-test-subj="rules-details-delete-rule"] button').simulate('click');
wrapper.update();
expect(executeRulesBulkAction).toHaveBeenCalledWith(
expect(executeRulesBulkActionMock).toHaveBeenCalledWith(
expect.objectContaining({ action: 'delete', search: { ids: ['id'] } })
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { mount } from 'enzyme';
import React from 'react';
import { waitFor } from '@testing-library/react';

import { performBulkAction } from '../../../../detection_engine/rule_management/logic';
import { performBulkAction } from '../../../../detection_engine/rule_management/api/api';
import { RuleSwitchComponent } from '.';
import { getRulesSchemaMock } from '../../../../../common/detection_engine/schemas/response/rules_schema.mocks';
import { useRulesTableContextOptional } from '../../../../detection_engine/rule_management_ui/components/rules_table/rules_table/rules_table_context';
Expand All @@ -19,15 +19,16 @@ import { useAppToasts } from '../../../../common/hooks/use_app_toasts';
import { useAppToastsMock } from '../../../../common/hooks/use_app_toasts.mock';

jest.mock('../../../../common/hooks/use_app_toasts');
jest.mock('../../../containers/detection_engine/rules');
jest.mock('../../../../detection_engine/rule_management/api/api');
jest.mock(
'../../../../detection_engine/rule_management_ui/components/rules_table/rules_table/rules_table_context'
);
jest.mock('../../../../common/lib/apm/use_start_transaction');

const useAppToastsValueMock = useAppToastsMock.create();

describe('RuleSwitch', () => {
// TODO: https://github.com/elastic/kibana/pull/142950 Fix and unskip
describe.skip('RuleSwitch', () => {
beforeEach(() => {
(useAppToasts as jest.Mock).mockReturnValue(useAppToastsValueMock);
(performBulkAction as jest.Mock).mockResolvedValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-m
import { getQueryRuleParams } from '../../../rule_schema/mocks';
import { legacyMigrate } from '../../../rule_management';

jest.mock('../../../rules/utils', () => {
const actual = jest.requireActual('../../../rules/utils');
jest.mock('../../../rule_management/logic/rule_actions/legacy_action_migration', () => {
const actual = jest.requireActual(
'../../../rule_management/logic/rule_actions/legacy_action_migration'
);
return {
...actual,
legacyMigrate: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import { getQueryRuleParams, getThreatRuleParams } from '../../rule_schema/mocks

jest.mock('../../rule_management/logic/crud/patch_rules');

jest.mock('../../rules/utils', () => {
const actual = jest.requireActual('../../rules/utils');
jest.mock('../../rule_management/logic/rule_actions/legacy_action_migration', () => {
const actual = jest.requireActual(
'../../rule_management/logic/rule_actions/legacy_action_migration'
);
return {
...actual,
legacyMigrate: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export { legacyRulesNotificationAlertType } from './logic/notifications/legacy_r
// eslint-disable-next-line no-restricted-imports
export { legacyIsNotificationAlertExecutor } from './logic/notifications/legacy_types';
// eslint-disable-next-line no-restricted-imports
export type { LegacyRuleNotificationAlertType } from './logic/notifications/legacy_types';
export type {
LegacyRuleNotificationAlertType,
LegacyRuleNotificationAlertTypeParams,
} from './logic/notifications/legacy_types';
export type { NotificationRuleTypeParams } from './logic/notifications/schedule_notification_actions';
export { scheduleNotificationActions } from './logic/notifications/schedule_notification_actions';
export { scheduleThrottledNotificationActions } from './logic/notifications/schedule_throttle_notification_actions';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import { getQueryRuleParams } from '../../../../rule_schema/mocks';
jest.mock('../../../../../machine_learning/authz', () => mockMlAuthzFactory.create());
jest.mock('../../../logic/crud/read_rules', () => ({ readRules: jest.fn() }));

jest.mock('../../../../rules/utils', () => {
const actual = jest.requireActual('../../../../rules/utils');
jest.mock('../../../logic/rule_actions/legacy_action_migration', () => {
const actual = jest.requireActual('../../../logic/rule_actions/legacy_action_migration');
return {
...actual,
legacyMigrate: jest.fn(),
Expand Down
Loading

0 comments on commit 66cf3f7

Please sign in to comment.