diff --git a/package.json b/package.json index eacdc147..fcae23de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hmcts/rpx-xui-common-lib", - "version": "2.0.24", + "version": "2.0.25", "engines": { "node": ">=18.19.0" }, diff --git a/projects/exui-common-lib/package.json b/projects/exui-common-lib/package.json index db5f3557..7cbabe6d 100644 --- a/projects/exui-common-lib/package.json +++ b/projects/exui-common-lib/package.json @@ -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", diff --git a/projects/exui-common-lib/src/lib/services/find-person/find-person.service.spec.ts b/projects/exui-common-lib/src/lib/services/find-person/find-person.service.spec.ts index 00251dfe..af6a3580 100644 --- a/projects/exui-common-lib/src/lib/services/find-person/find-person.service.spec.ts +++ b/projects/exui-common-lib/src/lib/services/find-person/find-person.service.spec.ts @@ -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', () => { @@ -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' } + ]); + }); }); diff --git a/projects/exui-common-lib/src/lib/services/find-person/find-person.service.ts b/projects/exui-common-lib/src/lib/services/find-person/find-person.service.ts index 7e74c447..07889056 100644 --- a/projects/exui-common-lib/src/lib/services/find-person/find-person.service.ts +++ b/projects/exui-common-lib/src/lib/services/find-person/find-person.service.ts @@ -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); } });