Skip to content

Commit

Permalink
Merge pull request #461 from hmcts/bug/exui-1889
Browse files Browse the repository at this point in the history
EXUI-1889 - Add current user to find person
  • Loading branch information
RiteshHMCTS authored Jul 25, 2024
2 parents bc2245c + 96979b1 commit e69b943
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/rpx-xui-common-lib",
"version": "2.0.24",
"version": "2.0.25",
"engines": {
"node": ">=18.19.0"
},
Expand Down
2 changes: 1 addition & 1 deletion projects/exui-common-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hmcts/rpx-xui-common-lib",
"version": "2.0.24",
"version": "2.0.25",
"peerDependencies": {
"launchdarkly-js-client-sdk": "^3.3.0",
"ngx-pagination": "^3.2.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { of } from 'rxjs';
import { Person, PersonRole, RoleCategory } from '../../models/person.model';
import { FindAPersonService } from './find-person.service';
import { Caseworker } from 'exui-common-lib';

describe('FindAPersonService', () => {
it('should be Truthy', () => {
Expand Down Expand Up @@ -167,4 +168,73 @@ describe('FindAPersonService', () => {
expect(service.mapCaseworkers(caseworkers, RoleCategory.CASEWORKER)).toEqual(people.slice(0, 3));
expect(service.mapCaseworkers(caseworkers, RoleCategory.ADMIN)).toEqual(people.slice(3, 4));
});

it('should not filter out current user ', () => {
const caseworkers: Caseworker[] = [
{
idamId: '123',
firstName: 'Test',
lastName: 'One',
email: 'TestOne@test.com',
roleCategory: 'LEGAL_OPERATIONS'
},
{
idamId: '124',
firstName: 'Test',
lastName: 'Two',
email: 'TestTwo@test.com',
roleCategory: 'LEGAL_OPERATIONS'
},
{
idamId: '125',
firstName: 'Test',
lastName: 'Three',
email: 'TestThree@test.com',
roleCategory: 'CTSC'
},
{
idamId: '126',
firstName: 'Test',
lastName: 'Four',
email: 'TestFour@test.com',
roleCategory: 'ADMIN'
}
];
const mockHttpService = jasmine.createSpyObj('mockHttpService', ['put', 'get', 'post']);
mockHttpService.post.and.returnValue(of());
const mockSessionStorageService = jasmine.createSpyObj('mockSessionStorageService', ['setItem', 'getItem']);
mockSessionStorageService.getItem.and.returnValues(JSON.stringify(userDetails), undefined, caseworkers);
const service = new FindAPersonService(mockHttpService, mockSessionStorageService);
service.userId = '126';

let searchOptions = { searchTerm: 'four', services: ['IA'], userRole: PersonRole.CASEWORKER };
const filteredUsersSpecificName = service.searchInCaseworkers(caseworkers, searchOptions);
expect(filteredUsersSpecificName).toEqual([
{ id: '126', name: 'Test Four', email: 'TestFour@test.com', domain: 'Admin' }
]);

searchOptions = { searchTerm: 'test', services: ['IA'], userRole: PersonRole.CASEWORKER };
const filteredUsersCaseWorker = service.searchInCaseworkers(caseworkers, searchOptions);
expect(filteredUsersCaseWorker).toHaveSize(3);
expect(filteredUsersCaseWorker).toEqual([
{ email: 'TestOne@test.com', name: 'Test One', id: '123', domain: 'Legal Ops' },
{ email: 'TestTwo@test.com', name: 'Test Two', id: '124', domain: 'Legal Ops' },
{ email: 'TestFour@test.com', name: 'Test Four', id: '126', domain: 'Admin' }
]);

searchOptions = { searchTerm: 'test', services: ['IA'], userRole: PersonRole.CTSC };
const filteredUsersCTSC = service.searchInCaseworkers(caseworkers, searchOptions);
expect(filteredUsersCTSC).toHaveSize(2);
expect(filteredUsersCTSC).toEqual([
{ email: 'TestThree@test.com', name: 'Test Three', id: '125', domain: 'Admin' },
{ email: 'TestFour@test.com', name: 'Test Four', id: '126', domain: 'Admin' }
]);

searchOptions = { searchTerm: 'test', services: ['IA'], userRole: PersonRole.ADMIN };
const filteredUsersAdmin = service.searchInCaseworkers(caseworkers, searchOptions);
expect(filteredUsersAdmin).toHaveSize(1);
expect(filteredUsersAdmin).toEqual([
{ email: 'TestFour@test.com', name: 'Test Four', id: '126', domain: 'Admin' }
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class FindAPersonService {
domain: caseworker.roleCategory === RoleCategory.CASEWORKER ? PersonRole.CASEWORKER : PersonRole.ADMIN,
// knownAs can be added if required
};
if (caseworker.roleCategory === roleCategory || roleCategory === RoleCategory.ALL) {
if (caseworker.roleCategory === roleCategory || roleCategory === RoleCategory.ALL || caseworker.idamId === this.userId) {
people.push(thisPerson);
}
});
Expand Down

0 comments on commit e69b943

Please sign in to comment.