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

Bug/cot 726 final #443

Merged
merged 20 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e8e07de
Allow assigned users to be passed as a string or an array of strings
richardhenryash Jan 25, 2024
ff789eb
Merge branch 'bug/cot-726' into bug/cot-726-v3
richardhenryash Jan 25, 2024
bd5da91
Initialise assignedUser to a blank array
richardhenryash Jan 29, 2024
79c216e
Revert changes to ng-package.json
richardhenryash Jan 30, 2024
f5e1244
Fix logic if assignedUser is passed as a single string and update uni…
richardhenryash Jan 30, 2024
69a64b3
Update version number
richardhenryash Jan 30, 2024
24d8076
Update logic to compare singe assignedUser, add unit test to test add…
richardhenryash Jan 30, 2024
c07db70
Update version
richardhenryash Jan 30, 2024
59f2cf5
merge with master to update the branch and package versions
shahedhmcts Mar 20, 2024
42f7b2b
merge with master to update the branch and package versions
shahedhmcts Mar 20, 2024
276aa92
updated release version to package.json
shahedhmcts Mar 20, 2024
e2e26f5
Merge branch 'master' into bug/cot-726-final
anthonydummer Jul 31, 2024
97a1fa1
EXUI-1741 - resolving merge conflicts and updating version
anthonydummer Aug 1, 2024
d6d4ca1
EXUI-1741 - resolving merge conflicts and updating version in second …
anthonydummer Aug 1, 2024
2f8c5bb
EXUI-1741 - Modified logic in searchInCaseworkers.
anthonydummer Aug 5, 2024
9653bfc
EXUI-1741 - updating dev version number
anthonydummer Aug 5, 2024
3daac4c
EXUI-1741 - updating dev version number
anthonydummer Aug 5, 2024
ff6465d
Merge branch 'master' into bug/cot-726-final
anthonydummer Aug 20, 2024
ab5c6d7
Merge branch 'master' into bug/cot-726-final
anthonydummer Aug 20, 2024
38dfa87
Update ver num
Josh-HMCTS Sep 3, 2024
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
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.25",
"version": "2.0.25-cot-726-rc2",
"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.25",
"version": "2.0.25-cot-726-rc2",
"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 });
}
}

Loading