Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Fixed an error with missing uids in the cases detail page (#207228) #207873

Merged
merged 1 commit into from
Jan 22, 2025
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
@@ -0,0 +1,61 @@
/*
* 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 { createUserActionServiceMock } from '../../services/mocks';
import { createMockClient } from '../metrics/test_utils/client';
import { createCasesClientMockArgs } from '../mocks';
import { getUsers } from './users';
import { mockCases } from '../../mocks';
import type { CaseResolveResponse } from '../../../common/types/api';
import { getUserProfiles } from '../cases/utils';

jest.mock('../cases/utils');

const getUserProfilesMock = getUserProfiles as jest.Mock;

describe('getUsers', () => {
const casesClient = createMockClient();

casesClient.cases.resolve.mockResolvedValue({
case: mockCases[0].attributes,
} as CaseResolveResponse);

const clientArgs = createCasesClientMockArgs();
const userActionService = createUserActionServiceMock();

userActionService.getUsers.mockResolvedValue({
participants: [
{
id: 'foo',
owner: 'bar',
user: { email: '', full_name: '', username: '', profile_uid: '' },
},
{
id: 'foo',
owner: 'bar',
user: { email: '', full_name: '', username: '', profile_uid: 'some_profile_id' },
},
],
assignedAndUnassignedUsers: new Set([]),
});
getUserProfilesMock.mockResolvedValue(new Map());
clientArgs.services.userActionService = userActionService;

beforeEach(() => {
jest.clearAllMocks();
});

it('removes empty uids from getUserProfiles call', async () => {
await getUsers({ caseId: 'test-case' }, casesClient, clientArgs);

expect(getUserProfilesMock).toHaveBeenCalledWith(
expect.any(Object),
new Set(['some_profile_id']),
expect.any(String)
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { isString } from 'lodash';
import { isEmpty, isString } from 'lodash';
import type { UserProfileAvatarData, UserProfileWithAvatar } from '@kbn/user-profile-components';
import type { GetCaseUsersResponse } from '../../../common/types/api';
import { GetCaseUsersResponseRt } from '../../../common/types/api';
Expand Down Expand Up @@ -57,12 +57,14 @@ export const getUsers = async (
const reporter = theCase.case.created_by;
const reporterProfileIdAsArray = reporter.profile_uid != null ? [reporter.profile_uid] : [];

const userProfileUids = new Set([
...assignedAndUnassignedUsers,
...participantsUids,
...assigneesUids,
...reporterProfileIdAsArray,
]);
const userProfileUids = new Set(
[
...assignedAndUnassignedUsers,
...participantsUids,
...assigneesUids,
...reporterProfileIdAsArray,
].filter((uid) => !isEmpty(uid))
);

const userProfiles = await getUserProfiles(securityStartPlugin, userProfileUids, 'avatar');

Expand Down
Loading