Skip to content

Commit

Permalink
Fallback reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Feb 9, 2023
1 parent 377cd88 commit 83331e4
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { SeveritySidebarSelector } from '../../severity/sidebar_selector';
import { useFindCaseUserActions } from '../../../containers/use_find_case_user_actions';
import { AssignUsers } from './assign_users';
import type { Assignee } from '../../user_profiles/types';
import { convertToCaseUserWithProfileInfo } from '../../user_profiles/user_converter';

const buildUserProfilesMap = (users?: CaseUsers): Map<string, UserProfileWithAvatar> => {
const userProfiles = new Map();
Expand Down Expand Up @@ -173,6 +174,11 @@ export const CaseViewActivity = ({
const showConnectorSidebar =
pushToServiceAuthorized && userActionsData && caseConnectors && supportedActionConnectors;

const reporterAsArray =
caseUsers?.reporter != null
? [caseUsers.reporter]
: [convertToCaseUserWithProfileInfo(caseData.createdBy)];

return (
<>
<EuiFlexItem grow={6}>
Expand Down Expand Up @@ -229,15 +235,13 @@ export const CaseViewActivity = ({
selectedSeverity={caseData.severity}
onSeverityChange={onUpdateSeverity}
/>
{caseUsers?.reporter ? (
<UserList
dataTestSubj="case-view-user-list-reporter"
theCase={caseData}
headline={i18n.REPORTER}
users={[caseUsers.reporter]}
userProfiles={userProfiles}
/>
) : null}
<UserList
dataTestSubj="case-view-user-list-reporter"
theCase={caseData}
headline={i18n.REPORTER}
users={reporterAsArray}
userProfiles={userProfiles}
/>
{caseUsers?.participants ? (
<UserList
dataTestSubj="case-view-user-list-participants"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,80 +6,104 @@
*/

import { userProfiles, userProfilesMap } from '../../containers/user_profiles/api.mock';
import { convertToUserInfo } from './user_converter';
import { convertToCaseUserWithProfileInfo, convertToUserInfo } from './user_converter';

describe('convertToUserInfo', () => {
it('returns undefined when the username is an empty string and the profile uid is not defined', () => {
expect(convertToUserInfo({ username: '', email: null, fullName: null })).toBeUndefined();
});
describe('user_converter', () => {
describe('convertToUserInfo', () => {
it('returns undefined when the username is an empty string and the profile uid is not defined', () => {
expect(convertToUserInfo({ username: '', email: null, fullName: null })).toBeUndefined();
});

it('returns a key of 123 and empty user info when the username is an empty string and the profile uid is not found', () => {
expect(
convertToUserInfo({ username: '', profileUid: '123', email: null, fullName: null })
).toEqual({
key: '123',
userInfo: {},
it('returns a key of 123 and empty user info when the username is an empty string and the profile uid is not found', () => {
expect(
convertToUserInfo({ username: '', profileUid: '123', email: null, fullName: null })
).toEqual({
key: '123',
userInfo: {},
});
});
});

it('returns the profile uid as the key and full profile when the profile uid is found', () => {
expect(
convertToUserInfo(
{ profileUid: userProfiles[0].uid, email: null, fullName: null, username: null },
userProfilesMap
)
).toMatchInlineSnapshot(`
Object {
"key": "u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0",
"userInfo": Object {
"data": Object {},
"enabled": true,
"uid": "u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0",
"user": Object {
"email": "[email protected]",
"full_name": "Damaged Raccoon",
"username": "damaged_raccoon",
},
},
}
`);
});
it('returns the profile uid as the key and full profile when the profile uid is found', () => {
expect(
convertToUserInfo(
{ profileUid: userProfiles[0].uid, email: null, fullName: null, username: null },
userProfilesMap
)
).toMatchInlineSnapshot(`
Object {
"key": "u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0",
"userInfo": Object {
"data": Object {},
"enabled": true,
"uid": "u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0",
"user": Object {
"email": "[email protected]",
"full_name": "Damaged Raccoon",
"username": "damaged_raccoon",
},
},
}
`);
});

it('returns the username as the key and the user info using the existing elastic user information', () => {
expect(convertToUserInfo({ username: 'sam', fullName: 'Sam Smith', email: '[email protected]' }))
.toMatchInlineSnapshot(`
Object {
"key": "sam",
"userInfo": Object {
"user": Object {
"email": "[email protected]",
"full_name": "Sam Smith",
"username": "sam",
},
},
}
`);
it('returns the username as the key and the user info using the existing elastic user information', () => {
expect(convertToUserInfo({ username: 'sam', fullName: 'Sam Smith', email: '[email protected]' }))
.toMatchInlineSnapshot(`
Object {
"key": "sam",
"userInfo": Object {
"user": Object {
"email": "[email protected]",
"full_name": "Sam Smith",
"username": "sam",
},
},
}
`);
});

it('returns the username as the key and the user info using the existing elastic user information when the profile uid is not found', () => {
expect(
convertToUserInfo({
username: 'sam',
fullName: 'Sam Smith',
email: '[email protected]',
profileUid: '123',
})
).toMatchInlineSnapshot(`
Object {
"key": "sam",
"userInfo": Object {
"user": Object {
"email": "[email protected]",
"full_name": "Sam Smith",
"username": "sam",
},
},
}
`);
});
});

it('returns the username as the key and the user info using the existing elastic user information when the profile uid is not found', () => {
expect(
convertToUserInfo({
username: 'sam',
fullName: 'Sam Smith',
email: '[email protected]',
profileUid: '123',
})
).toMatchInlineSnapshot(`
Object {
"key": "sam",
"userInfo": Object {
describe('convertToCaseUserWithProfileInfo', () => {
it('converts a CaseUse to a CaseUserWithProfileInfo correctly', () => {
expect(
convertToCaseUserWithProfileInfo({
username: 'test',
email: '[email protected]',
fullName: 'Test',
profileUid: 'test-id',
})
).toMatchInlineSnapshot(`
Object {
"uid": "test-id",
"user": Object {
"email": "[email protected]",
"full_name": "Sam Smith",
"username": "sam",
"email": "[email protected]",
"full_name": "Test",
"username": "test",
},
},
}
`);
}
`);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import type { UserProfileWithAvatar } from '@kbn/user-profile-components';
import { isEmpty } from 'lodash';
import type { CaseUser } from '../../containers/types';
import type { UserInfoWithAvatar } from './types';
import type { CaseUserWithProfileInfo, UserInfoWithAvatar } from './types';

export const convertToUserInfo = (
user: CaseUser,
Expand Down Expand Up @@ -43,3 +43,8 @@ const createWithUsername = (username: string, user: CaseUser) => {
},
};
};

export const convertToCaseUserWithProfileInfo = (user: CaseUser): CaseUserWithProfileInfo => ({
uid: user.profileUid,
user: { email: user.email, full_name: user.fullName, username: user.username },
});

0 comments on commit 83331e4

Please sign in to comment.