Skip to content

Commit

Permalink
Bug/cot 726 final (#443)
Browse files Browse the repository at this point in the history
* Allow assigned users to be passed as a string or an array of strings

* Initialise assignedUser to a blank array

* Revert changes to ng-package.json

* Fix logic if assignedUser is passed as a single string and update unit tests to test new functionality

* Update version number

* Update logic to compare singe assignedUser, add unit test to test additional functionality

* Update version

* merge with master to update the branch and package versions

* updated release version to package.json

* EXUI-1741 - resolving merge conflicts and updating version

* EXUI-1741 - resolving merge conflicts and updating version in second package

* EXUI-1741 - Modified logic in searchInCaseworkers.

* EXUI-1741 - updating dev version number

* EXUI-1741 - updating dev version number

* Update ver num

---------

Co-authored-by: shahedhmcts <[email protected]>
Co-authored-by: Anthony Dummer <[email protected]>
Co-authored-by: Anthony Dummer <[email protected]>
Co-authored-by: Josh <[email protected]>
  • Loading branch information
5 people authored Sep 3, 2024
1 parent c63daf8 commit 8ae32ef
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 24 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.26",
"version": "2.0.28",
"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.26",
"version": "2.0.28",
"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
Expand Up @@ -23,7 +23,7 @@ export class FindPersonComponent implements OnInit, OnDestroy {
@Input() public selectedPerson: string;
@Input() public submitted: boolean = true;
@Input() public userIncluded?: boolean = false;
@Input() public assignedUser?: string;
@Input() public assignedUser?: string | string[];
@Input() public placeholderContent: string = '';
@Input() public isNoResultsShown: boolean = true;
@Input() public showUpdatedColor: boolean = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export interface SearchOptions {
userRole: PersonRole;
services: string[];
userIncluded?: boolean;
assignedUser?: string;
assignedUser?: string | string[];
}
Original file line number Diff line number Diff line change
@@ -1,7 +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';
import { Caseworker } from '../../models';

describe('FindAPersonService', () => {
it('should be Truthy', () => {
Expand Down Expand Up @@ -58,34 +58,84 @@ describe('FindAPersonService', () => {
}
];

it('find search should not filter out current user and assigned user', () => {
it('find search should not filter out single non-matching assigned user if passed as a string', () => {
const mockHttpService = jasmine.createSpyObj('mockHttpService', ['put', 'get', 'post']);
const mockSessionStorageService = jasmine.createSpyObj('mockSessionStorageService', ['setItem', 'getItem']);
mockSessionStorageService.getItem.and.returnValue(JSON.stringify(userDetails));
mockHttpService.post.and.returnValue(of(people));
const service = new FindAPersonService(mockHttpService, mockSessionStorageService);
const searchOptions = { searchTerm: 'term', services: ['IA'], userRole: PersonRole.JUDICIAL, userIncluded: false, assignedUser: '1234' };
const searchOptions = { searchTerm: 'term', services: ['IA'], userRole: PersonRole.JUDICIAL, userIncluded: false, assignedUser: '130' };
service.find(searchOptions).toPromise().then(result => expect(result).toEqual(people));
});

it('find search should not filter out current user and assigned user', () => {
it('find search should not filter out single partially matching assigned user if passed as a string', () => {
const mockHttpService = jasmine.createSpyObj('mockHttpService', ['put', 'get', 'post']);
const mockSessionStorageService = jasmine.createSpyObj('mockSessionStorageService', ['setItem', 'getItem']);
mockSessionStorageService.getItem.and.returnValue(JSON.stringify(userDetails));
mockHttpService.post.and.returnValue(of(people));
const service = new FindAPersonService(mockHttpService, mockSessionStorageService);
const searchOptions = { searchTerm: 'term', services: ['IA'], userRole: PersonRole.JUDICIAL, userIncluded: false, assignedUser: '1234' };
const searchOptions = { searchTerm: 'term', services: ['IA'], userRole: PersonRole.JUDICIAL, userIncluded: false, assignedUser: '12' };
service.find(searchOptions).toPromise().then(result => expect(result).toEqual(people));
});

it('find search should not filter out single partially matching assigned user if passed as an array of strings', () => {
const mockHttpService = jasmine.createSpyObj('mockHttpService', ['put', 'get', 'post']);
const mockSessionStorageService = jasmine.createSpyObj('mockSessionStorageService', ['setItem', 'getItem']);
mockSessionStorageService.getItem.and.returnValue(JSON.stringify(userDetails));
mockHttpService.post.and.returnValue(of(people));
const service = new FindAPersonService(mockHttpService, mockSessionStorageService);
const searchOptions = { searchTerm: 'term', services: ['IA'], userRole: PersonRole.JUDICIAL, userIncluded: false, assignedUser: ['12', '130'] };
service.find(searchOptions).toPromise().then(result => expect(result).toEqual(people));
});

it('find search should filter out matching assigned user', () => {
it('find search should not filter out single partially matching assigned user if passed as an array of strings', () => {
const mockHttpService = jasmine.createSpyObj('mockHttpService', ['put', 'get', 'post']);
const mockSessionStorageService = jasmine.createSpyObj('mockSessionStorageService', ['setItem', 'getItem']);
mockSessionStorageService.getItem.and.returnValue(JSON.stringify(userDetails));
mockHttpService.post.and.returnValue(of(people));
const service = new FindAPersonService(mockHttpService, mockSessionStorageService);
const searchOptions = { searchTerm: 'term', services: ['IA'], userRole: PersonRole.JUDICIAL, userIncluded: false, assignedUser: ['12', '124'] };
service.find(searchOptions).toPromise().then(result => expect(result).toEqual([people[0], people[2], people[3]]));
});

it('find search should not filter out multiple non-matching assigned users if passed as a list of strings', () => {
const mockHttpService = jasmine.createSpyObj('mockHttpService', ['put', 'get', 'post']);
const mockSessionStorageService = jasmine.createSpyObj('mockSessionStorageService', ['setItem', 'getItem']);
mockSessionStorageService.getItem.and.returnValue(JSON.stringify(userDetails));
mockHttpService.post.and.returnValue(of(people));
const service = new FindAPersonService(mockHttpService, mockSessionStorageService);
const searchOptions = { searchTerm: 'term', services: ['IA'], userRole: PersonRole.JUDICIAL, userIncluded: false, assignedUser: '130, 131' };
service.find(searchOptions).toPromise().then(result => expect(result).toEqual(people));
});

it('find search should filter out single matching assigned user if passed as a string', () => {
const mockHttpService = jasmine.createSpyObj('mockHttpService', ['put', 'get', 'post']);
const mockSessionStorageService = jasmine.createSpyObj('mockSessionStorageService', ['setItem', 'getItem']);
mockSessionStorageService.getItem.and.returnValue(JSON.stringify(userDetails));
mockHttpService.post.and.returnValue(of(people));
const service = new FindAPersonService(mockHttpService, mockSessionStorageService);
const searchOptions = { searchTerm: 'term', services: ['IA'], userRole: PersonRole.JUDICIAL, userIncluded: false, assignedUser: '124' };
service.find(searchOptions).toPromise().then(result => expect(result).toEqual([people[0], people[2], people[3]]));
});

it('find search should filter out single matching assigned user if passed as an array of strings', () => {
const mockHttpService = jasmine.createSpyObj('mockHttpService', ['put', 'get', 'post']);
const mockSessionStorageService = jasmine.createSpyObj('mockSessionStorageService', ['setItem', 'getItem']);
mockSessionStorageService.getItem.and.returnValue(JSON.stringify(userDetails));
mockHttpService.post.and.returnValue(of(people));
const service = new FindAPersonService(mockHttpService, mockSessionStorageService);
const searchOptions = { searchTerm: 'term', services: ['IA'], userRole: PersonRole.JUDICIAL, userIncluded: false, assignedUser: ['124', '130'] };
service.find(searchOptions).toPromise().then(result => expect(result).toEqual([people[0], people[2], people[3]]));
});

it('find search should filter out multiple matching assigned users if passed as an array of strings', () => {
const mockHttpService = jasmine.createSpyObj('mockHttpService', ['put', 'get', 'post']);
const mockSessionStorageService = jasmine.createSpyObj('mockSessionStorageService', ['setItem', 'getItem']);
mockSessionStorageService.getItem.and.returnValue(JSON.stringify(userDetails));
mockHttpService.post.and.returnValue(of(people));
const service = new FindAPersonService(mockHttpService, mockSessionStorageService);
const searchOptions = { searchTerm: 'term', services: ['IA'], userRole: PersonRole.JUDICIAL, userIncluded: false, assignedUser: '123' };
service.find(searchOptions).toPromise().then(result => expect(result).toEqual(people.slice(1, 4)));
const searchOptions = { searchTerm: 'term', services: ['IA'], userRole: PersonRole.JUDICIAL, userIncluded: false, assignedUser: ['124', '125'] };
service.find(searchOptions).toPromise().then(result => expect(result).toEqual([people[0], people[3]]));
});

it('find specific caseworkers', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ import { SessionStorageService } from '../storage/session-storage/session-storag
providedIn: 'root'
})
export class FindAPersonService {

public static caseworkersKey: string = 'caseworkers';
public userId: string;
public assignedUser: string;
public assignedUser: string | string[] = [];

constructor(private readonly http: HttpClient, private readonly sessionStorageService: SessionStorageService) {
}
Expand All @@ -30,9 +29,13 @@ export class FindAPersonService {
const userInfo = JSON.parse(userInfoStr);
this.userId = userInfo.id ? userInfo.id : userInfo.uid;
}
this.assignedUser = searchOptions.assignedUser ? searchOptions.assignedUser : null;
this.assignedUser = searchOptions.assignedUser ? searchOptions.assignedUser : [];
let assignedUserToCompare = this.assignedUser;
if (typeof(this.assignedUser) === 'string') {
assignedUserToCompare = [this.assignedUser];
}
return this.http.post<Person[]>('/workallocation/findPerson', { searchOptions })
.pipe(map(judiciary => judiciary.filter(judge => !([this.assignedUser].includes(judge.id)))));
.pipe(map((judiciary) => judiciary.filter((judge) => !(assignedUserToCompare.includes(judge.id)))));
// Removed the current user id to fix EUI-8465.
}

Expand All @@ -42,10 +45,10 @@ export class FindAPersonService {
const userInfo = JSON.parse(userInfoStr);
this.userId = userInfo.id ? userInfo.id : userInfo.uid;
}
this.assignedUser = searchOptions.assignedUser ? searchOptions.assignedUser : null;
this.assignedUser = searchOptions.assignedUser ? searchOptions.assignedUser : [];
const fullServices = searchOptions.services;
return this.http.post<Caseworker[]>('/workallocation/caseworker/getUsersByServiceName', {services: fullServices, term: searchOptions.searchTerm}).pipe(
map(caseworkers => {
return this.http.post<Caseworker[]>('/workallocation/caseworker/getUsersByServiceName', { services: fullServices, term: searchOptions.searchTerm }).pipe(
map((caseworkers) => {
return this.searchInCaseworkers(caseworkers, searchOptions);
})
);
Expand All @@ -58,7 +61,7 @@ export class FindAPersonService {
email: caseworker.email,
name: `${caseworker.firstName} ${caseworker.lastName}`,
id: caseworker.idamId,
domain: caseworker.roleCategory === RoleCategory.CASEWORKER ? PersonRole.CASEWORKER : PersonRole.ADMIN,
domain: caseworker.roleCategory === RoleCategory.CASEWORKER ? PersonRole.CASEWORKER : PersonRole.ADMIN
// knownAs can be added if required
};
if (caseworker.roleCategory === roleCategory || roleCategory === RoleCategory.ALL || caseworker.idamId === this.userId) {
Expand All @@ -81,14 +84,16 @@ export class FindAPersonService {
}
const searchTerm = searchOptions && searchOptions.searchTerm ? searchOptions.searchTerm.toLowerCase() : '';
const people = caseworkers ? this.mapCaseworkers(caseworkers, roleCategory) : [];
const finalPeopleList = people.filter(person => person && person.name && person.name.toLowerCase().includes(searchTerm));
return searchOptions.userIncluded ? finalPeopleList.filter(person => person && person.id !== this.assignedUser)
: finalPeopleList.filter(person => person || person.id.includes(this.userId) && person.id !== this.assignedUser);
const finalPeopleList = people.filter((person) => person && person.name && person.name.toLowerCase().includes(searchTerm));

if (typeof(this.assignedUser) === 'string') {
return finalPeopleList.filter((person) => person && person.id !== this.assignedUser);
}
return finalPeopleList.filter((person) => person && !this.assignedUser.includes(person.id));
}

public searchJudicial(value: string, serviceId: string): Observable<JudicialUserModel[]> {
return this.http.post<JudicialUserModel[]>('api/prd/judicial/getJudicialUsersSearch',
{ searchString: value, serviceCode: serviceId });
}
}

0 comments on commit 8ae32ef

Please sign in to comment.