Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const mockUserProfiles = [
data: {},
},
];
jest.mock('../../../detections/containers/detection_engine/alerts/use_suggest_users', () => {
jest.mock('../../../detections/containers/detection_engine/user_profiles/use_suggest_users', () => {
return {
useSuggestUsers: () => ({
loading: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { UserProfileWithAvatar } from '@kbn/user-profile-components';
import { UserProfilesPopover } from '@kbn/user-profile-components';

import { EuiFilterButton } from '@elastic/eui';
import { useSuggestUsers } from '../../../detections/containers/detection_engine/alerts/use_suggest_users';
import { useSuggestUsers } from '../../../detections/containers/detection_engine/user_profiles/use_suggest_users';
import { TEST_IDS } from './constants';

export interface FilterByAssigneesPopoverProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import type { TimelineItem } from '@kbn/timelines-plugin/common';
import { act, fireEvent, render } from '@testing-library/react';
import React from 'react';
import { TestProviders } from '../../../mock';
import { useGetUserProfiles } from '../../../../detections/containers/detection_engine/alerts/use_get_user_profiles';
import { useSuggestUsers } from '../../../../detections/containers/detection_engine/alerts/use_suggest_users';
import { useGetUserProfiles } from '../../../../detections/containers/detection_engine/user_profiles/use_get_user_profiles';
import { useSuggestUsers } from '../../../../detections/containers/detection_engine/user_profiles/use_suggest_users';

import { BulkAlertAssigneesPanel } from './alert_bulk_assignees';
import { ALERT_WORKFLOW_ASSIGNEE_IDS } from '@kbn/rule-data-utils';

jest.mock('../../../../detections/containers/detection_engine/alerts/use_get_user_profiles');
jest.mock('../../../../detections/containers/detection_engine/alerts/use_suggest_users');
jest.mock('../../../../detections/containers/detection_engine/user_profiles/use_get_user_profiles');
jest.mock('../../../../detections/containers/detection_engine/user_profiles/use_suggest_users');

const mockUserProfiles = [
{ uid: 'user-id-1', enabled: true, user: { username: 'user1' }, data: {} },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import React, { memo, useCallback, useEffect, useMemo, useState } from 'react';
import { ALERT_WORKFLOW_ASSIGNEE_IDS } from '@kbn/rule-data-utils';
import type { UserProfileWithAvatar } from '@kbn/user-profile-components';
import { UserProfilesSelectable } from '@kbn/user-profile-components';
import { useGetUserProfiles } from '../../../../detections/containers/detection_engine/alerts/use_get_user_profiles';
import { useSuggestUsers } from '../../../../detections/containers/detection_engine/alerts/use_suggest_users';
import { useGetUserProfiles } from '../../../../detections/containers/detection_engine/user_profiles/use_get_user_profiles';
import { useSuggestUsers } from '../../../../detections/containers/detection_engine/user_profiles/use_suggest_users';
import * as i18n from './translations';
import type { SetAlertAssigneesFunc } from './use_set_alert_assignees';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import type {
} from './use_bulk_alert_assignees_items';
import { useBulkAlertAssigneesItems } from './use_bulk_alert_assignees_items';
import { useSetAlertAssignees } from './use_set_alert_assignees';
import { useGetUserProfiles } from '../../../../detections/containers/detection_engine/alerts/use_get_user_profiles';
import { useSuggestUsers } from '../../../../detections/containers/detection_engine/alerts/use_suggest_users';
import { useGetUserProfiles } from '../../../../detections/containers/detection_engine/user_profiles/use_get_user_profiles';
import { useSuggestUsers } from '../../../../detections/containers/detection_engine/user_profiles/use_suggest_users';

jest.mock('./use_set_alert_assignees');
jest.mock('../../../../detections/containers/detection_engine/alerts/use_get_user_profiles');
jest.mock('../../../../detections/containers/detection_engine/alerts/use_suggest_users');
jest.mock('../../../../detections/containers/detection_engine/user_profiles/use_get_user_profiles');
jest.mock('../../../../detections/containers/detection_engine/user_profiles/use_suggest_users');

const mockUserProfiles = [
{ uid: 'user-id-1', enabled: true, user: { username: 'fakeUser1' }, data: {} },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import React from 'react';
import type { EuiContextMenuPanelDescriptor } from '@elastic/eui';
import { EuiPopover, EuiContextMenu } from '@elastic/eui';
import { useSetAlertAssignees } from '../../../../common/components/toolbar/bulk_actions/use_set_alert_assignees';
import { useGetUserProfiles } from '../../../containers/detection_engine/alerts/use_get_user_profiles';
import { useSuggestUsers } from '../../../containers/detection_engine/alerts/use_suggest_users';
import { useGetUserProfiles } from '../../../containers/detection_engine/user_profiles/use_get_user_profiles';
import { useSuggestUsers } from '../../../containers/detection_engine/user_profiles/use_suggest_users';

jest.mock('../../../containers/detection_engine/alerts/use_alerts_privileges');
jest.mock('../../../../common/components/toolbar/bulk_actions/use_set_alert_assignees');
jest.mock('../../../containers/detection_engine/alerts/use_get_user_profiles');
jest.mock('../../../containers/detection_engine/alerts/use_suggest_users');
jest.mock('../../../containers/detection_engine/user_profiles/use_get_user_profiles');
jest.mock('../../../containers/detection_engine/user_profiles/use_suggest_users');

const mockUserProfiles = [
{ uid: 'user-id-1', enabled: true, user: { username: 'fakeUser1' }, data: {} },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const mockUserProfiles = [
data: {},
},
];
jest.mock('../../containers/detection_engine/alerts/use_suggest_users', () => {
jest.mock('../../containers/detection_engine/user_profiles/use_suggest_users', () => {
return {
useSuggestUsers: () => ({
loading: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { SUPPRESSED_ALERT_TOOLTIP } from './translations';
import { VIEW_SELECTION } from '../../../../common/constants';
import { getAllFieldsByName } from '../../../common/containers/source';
import { eventRenderedViewColumns, getColumns } from './columns';
import { useGetUserProfiles } from '../../containers/detection_engine/alerts/use_get_user_profiles';
import { useGetUserProfiles } from '../../containers/detection_engine/user_profiles/use_get_user_profiles';

/**
* This implementation of `EuiDataGrid`'s `renderCellValue`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import type { UserProfileWithAvatar } from '@kbn/user-profile-components';
import type {
QueryAlerts,
AlertSearchResponse,
Expand All @@ -14,13 +13,7 @@ import type {
Privilege,
CasesFromAlertsResponse,
} from '../types';
import {
alertsMock,
mockSignalIndex,
mockUserPrivilege,
mockCaseIdsFromAlertId,
mockUserProfiles,
} from '../mock';
import { alertsMock, mockSignalIndex, mockUserPrivilege, mockCaseIdsFromAlertId } from '../mock';

export const fetchQueryAlerts = async <Hit, Aggregations>({
query,
Expand All @@ -43,9 +36,3 @@ export const getCaseIdsFromAlertId = async ({
}: {
alertId: string;
}): Promise<CasesFromAlertsResponse> => Promise.resolve(mockCaseIdsFromAlertId);

export const suggestUsers = async ({
searchTerm,
}: {
searchTerm: string;
}): Promise<UserProfileWithAvatar[]> => Promise.resolve(mockUserProfiles);
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
mockSignalIndex,
mockUserPrivilege,
mockHostIsolation,
mockUserProfiles,
} from './mock';
import {
fetchQueryAlerts,
Expand All @@ -23,7 +22,6 @@ import {
createHostIsolation,
updateAlertStatusByQuery,
updateAlertStatusByIds,
suggestUsers,
} from './api';
import { coreMock } from '@kbn/core/public/mocks';

Expand Down Expand Up @@ -266,28 +264,4 @@ describe('Detections Alerts API', () => {
expect(hostIsolationResponse).toEqual(mockHostIsolation);
});
});

describe('suggestUsers', () => {
beforeEach(() => {
fetchMock.mockClear();
fetchMock.mockResolvedValue(mockUserProfiles);
});

test('check parameter url', async () => {
await suggestUsers({ searchTerm: 'name1' });
expect(fetchMock).toHaveBeenCalledWith(
'/api/detection_engine/signals/suggest_users',
expect.objectContaining({
method: 'GET',
version: '2023-10-31',
query: { searchTerm: 'name1' },
})
);
});

test('happy path', async () => {
const alertsResp = await suggestUsers({ searchTerm: '' });
expect(alertsResp).toEqual(mockUserProfiles);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import type { UserProfileWithAvatar } from '@kbn/user-profile-components';
import type { HostIsolationResponse } from '../../../../../common/endpoint/types/actions';
import type { AlertSearchResponse, AlertsIndex, Privilege, CasesFromAlertsResponse } from './types';

Expand Down Expand Up @@ -1335,8 +1334,3 @@ export const mockCaseIdsFromAlertId: CasesFromAlertsResponse = [
{ id: '818601a0-b26b-11eb-8759-6b318e8cf4bc', title: 'Case 1' },
{ id: '8a774850-b26b-11eb-8759-6b318e8cf4bc', title: 'Case 2' },
];

export const mockUserProfiles: UserProfileWithAvatar[] = [
{ uid: 'user-id-1', enabled: true, user: { username: 'user1' }, data: {} },
{ uid: 'user-id-2', enabled: true, user: { username: 'user2' }, data: {} },
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { UserProfileWithAvatar } from '@kbn/user-profile-components';
import { mockUserProfiles } from '../mock';

export const suggestUsers = async ({
searchTerm,
}: {
searchTerm: string;
}): Promise<UserProfileWithAvatar[]> => Promise.resolve(mockUserProfiles);
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { coreMock } from '@kbn/core/public/mocks';

import { mockUserProfiles } from './mock';
import { suggestUsers } from './api';
import { KibanaServices } from '../../../../common/lib/kibana';

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

const coreStartMock = coreMock.createStart({ basePath: '/mock' });
mockKibanaServices.mockReturnValue(coreStartMock);
const fetchMock = coreStartMock.http.fetch;

describe('Detections Alerts API', () => {
describe('suggestUsers', () => {
beforeEach(() => {
fetchMock.mockClear();
fetchMock.mockResolvedValue(mockUserProfiles);
});

test('check parameter url', async () => {
await suggestUsers({ searchTerm: 'name1' });
expect(fetchMock).toHaveBeenCalledWith(
'/api/detection_engine/signals/suggest_users',
expect.objectContaining({
method: 'GET',
version: '2023-10-31',
query: { searchTerm: 'name1' },
})
);
});

test('happy path', async () => {
const alertsResp = await suggestUsers({ searchTerm: '' });
expect(alertsResp).toEqual(mockUserProfiles);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { UserProfileWithAvatar } from '@kbn/user-profile-components';

import type { SuggestUsersProps } from './types';
import { DETECTION_ENGINE_ALERT_SUGGEST_USERS_URL } from '../../../../../common/constants';
import { KibanaServices } from '../../../../common/lib/kibana';

/**
* Fetches suggested user profiles
*/
export const suggestUsers = async ({
searchTerm,
}: SuggestUsersProps): Promise<UserProfileWithAvatar[]> => {
return KibanaServices.get().http.fetch<UserProfileWithAvatar[]>(
DETECTION_ENGINE_ALERT_SUGGEST_USERS_URL,
{
method: 'GET',
version: '2023-10-31',
query: { searchTerm },
}
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export const mockUserProfiles = [
{ uid: 'user-id-1', enabled: true, user: { username: 'user1' }, data: {} },
{ uid: 'user-id-2', enabled: true, user: { username: 'user2' }, data: {} },
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { i18n } from '@kbn/i18n';

export const USER_PROFILES_FAILURE = i18n.translate(
'xpack.securitySolution.containers.detectionEngine.userProfiles.title',
{ defaultMessage: 'Failed to find users' }
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export interface SuggestUsersProps {
searchTerm: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
*/

import { renderHook } from '@testing-library/react-hooks';
import { securityMock } from '@kbn/security-plugin/public/mocks';

import { mockUserProfiles } from './mock';
import { useGetUserProfiles } from './use_get_user_profiles';
import { useKibana } from '../../../../common/lib/kibana';
import { useAppToasts } from '../../../../common/hooks/use_app_toasts';
import { useAppToastsMock } from '../../../../common/hooks/use_app_toasts.mock';
import { mockUserProfiles } from './mock';
import { createStartServicesMock } from '../../../../common/lib/kibana/kibana_react.mock';
import { securityMock } from '@kbn/security-plugin/public/mocks';

jest.mock('../../../../common/lib/kibana');
jest.mock('../../../../common/hooks/use_app_toasts');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

import type { UserProfileWithAvatar } from '@kbn/user-profile-components';
import { useEffect, useState } from 'react';

import { USER_PROFILES_FAILURE } from './translations';
import { useKibana } from '../../../../common/lib/kibana';
import { useAppToasts } from '../../../../common/hooks/use_app_toasts';
import { USER_PROFILES_FAILURE } from './translations';

interface GetUserProfilesReturn {
loading: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

import { renderHook } from '@testing-library/react-hooks';
import { useSuggestUsers } from './use_suggest_users';

import * as api from './api';
import { mockUserProfiles } from './mock';
import { useAppToasts } from '../../../../common/hooks/use_app_toasts';
import { useAppToastsMock } from '../../../../common/hooks/use_app_toasts.mock';
import { mockUserProfiles } from './mock';

jest.mock('./api');
jest.mock('../../../../common/hooks/use_app_toasts');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

import type { UserProfileWithAvatar } from '@kbn/user-profile-components';
import { useEffect, useState } from 'react';
import { useAppToasts } from '../../../../common/hooks/use_app_toasts';

import { suggestUsers } from './api';
import { USER_PROFILES_FAILURE } from './translations';
import { useAppToasts } from '../../../../common/hooks/use_app_toasts';

interface SuggestUsersReturn {
loading: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import {
} from './test_ids';
import { Assignees } from './assignees';

import { useGetUserProfiles } from '../../../../detections/containers/detection_engine/alerts/use_get_user_profiles';
import { useSuggestUsers } from '../../../../detections/containers/detection_engine/alerts/use_suggest_users';
import { useGetUserProfiles } from '../../../../detections/containers/detection_engine/user_profiles/use_get_user_profiles';
import { useSuggestUsers } from '../../../../detections/containers/detection_engine/user_profiles/use_suggest_users';
import type { SetAlertAssigneesFunc } from '../../../../common/components/toolbar/bulk_actions/use_set_alert_assignees';
import { useSetAlertAssignees } from '../../../../common/components/toolbar/bulk_actions/use_set_alert_assignees';
import { TestProviders } from '../../../../common/mock';

jest.mock('../../../../detections/containers/detection_engine/alerts/use_get_user_profiles');
jest.mock('../../../../detections/containers/detection_engine/alerts/use_suggest_users');
jest.mock('../../../../detections/containers/detection_engine/user_profiles/use_get_user_profiles');
jest.mock('../../../../detections/containers/detection_engine/user_profiles/use_suggest_users');
jest.mock('../../../../common/components/toolbar/bulk_actions/use_set_alert_assignees');

const mockUserProfiles: UserProfileWithAvatar[] = [
Expand Down
Loading