Skip to content

Commit

Permalink
Bug/cot 540 v2 (#3338)
Browse files Browse the repository at this point in the history
* Add getHearingJudgeIds selector and use in JudicialUserSearchResponseResolver

* Add judicialResponseUsers to hearing-cancelled-summary/:id route

* Align JudicialUserModel with api response

* Fix linting errors

* Refactor getHearingJudgeIds selector, test for null caseHearings and null hearingDaySchedule

* Fix unit test

* Fix unit test

* Update known security issues

* Add unit tests for hearing judges selectors

* Fix linting

* Fix linting

* Fix linting

* Add further test scenarios to hearing judges selectors unit tests

* Fix linting errors

* Remove unused imports

* Return empty array if state is undefined, add additional test case

* Add additional test case, fix linting errors

* Fix linting errors

* Fix linting errors

* Update yarn audit known security issues

* Set jrdELinksV2Enabled to true

* Update values.preview.template.yaml

* Set "jrdELinksV2Enabled" flag back to false

* Update yarn known issues log

* remove FEATURE_JRD_E_LINKS_V2_ENABLED flag from preview environment

* Update yarn audit known issues log

* Update yarn audit known issues log

* Update yarn audit known issues log

* Add test to check if first member of judicialMemberIds array is null or an empty string

* remove focus from test

* Increase coverage of unit tests for judicial user search response resolver

* Update yarn audit known issues log

* Remove focus from unit test

* exui-1035-my work returns an error (#3365)

* checking userList before makiing call -avoid error

* lint error

* cve

* cve

---------

Co-authored-by: RiteshHMCTS <74713687+RiteshHMCTS@users.noreply.github.com>
Co-authored-by: Andy Wilkins <49269487+andywilkinshmcts@users.noreply.github.com>
Co-authored-by: Ritesh Dsouza <ritesh.dsouza@HMCTS.net>
  • Loading branch information
4 people authored Nov 13, 2023
1 parent 2e5713c commit 8cb5579
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 35 deletions.
18 changes: 11 additions & 7 deletions api/workAllocation/caseWorkerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,17 @@ export async function handleCaseWorkersForServicesPost(path: string, payloads: C
export async function handlePostCaseWorkersRefData(path: string, userIdsByJurisdiction: any, req: EnhancedRequest): Promise<any> {
const data = new Array<any>();
for (const userIdList of userIdsByJurisdiction) {
const payload = {
userIds: userIdList.userIds
};
const headers = setHeaders(req);
const response: AxiosResponse = await http.post(path, payload, { headers });
const userListByService = { jurisdiction: userIdList.jurisdiction, data: response.data };
data.push(userListByService);
if (userIdList.userIds && userIdList.userIds.length > 0) {
const payload = {
userIds: userIdList.userIds
};
const headers = setHeaders(req);
const response: AxiosResponse = await http.post(path, payload, { headers });
const userListByService = { jurisdiction: userIdList.jurisdiction, data: response.data };
data.push(userListByService);
} else {
console.warn('Jurisdiction ' + userIdList.jurisdiction + ' user list is empty');
}
}
return data;
}
Expand Down
1 change: 1 addition & 0 deletions src/hearings/hearings.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ export const ROUTES: Routes = [
partyChannels: PartyChannelsResolverService,
partySubChannels: PartySubChannelsResolverService,
judgeTypes: JudgeTypesResolverService,
judicialResponseUsers: JudicialUserSearchResponseResolver,
otherPanelRoles: PanelRolesResolverService,
courtLocation: CourtLocationsDataResolver
},
Expand Down
6 changes: 3 additions & 3 deletions src/hearings/models/judicialUser.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface JudicialUserModel {
initials: string;
postNominals: string;
personalCode: string;
isJudge: string;
isMagistrate: string;
isPanelMember: string;
isJudge?: string;
isMagistrate?: string;
isPanelMember?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,36 @@ import { JudicialUserSearchResponseResolver } from './judicial-user-search-respo

describe('Ref Data Resolver', () => {
let judicialRefDataService: JudicialRefDataService;
const dataRef: JudicialUserModel[] = [];
const testJudge1 = {
title: 'Mr',
knownAs: 'Test Judge1',
surname: 'Judge1',
fullName: 'Test Judge1',
emailId: '',
idamId: '123456789',
initials: 'TJ1',
postNominals: '',
personalCode: 'p100001',
isJudge: 'YES',
isMagistrate: 'Yes',
isPanelMember: 'Yes'
} as JudicialUserModel;
const testJudge2 = {
title: 'Mr',
knownAs: 'Test Judge2',
surname: 'Judge2',
fullName: 'Test Judge2',
emailId: '',
idamId: '123456789',
initials: 'TJ2',
postNominals: '',
personalCode: 'p100002',
isJudge: 'YES',
isMagistrate: 'Yes',
isPanelMember: 'Yes'
} as JudicialUserModel;
const judicialUsers: JudicialUserModel[] = [testJudge1, testJudge2];
const judgePersonalCodes = ['p100001', 'p100002'];

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -31,20 +60,66 @@ describe('Ref Data Resolver', () => {
});

it('should be created', () => {
const service: JudicialUserSearchResponseResolver = TestBed.inject(JudicialUserSearchResponseResolver);
expect(service).toBeTruthy();
const resolver: JudicialUserSearchResponseResolver = TestBed.inject(JudicialUserSearchResponseResolver);
expect(resolver).toBeTruthy();
});

it('resolves reference data', inject([JudicialUserSearchResponseResolver], (service: JudicialUserSearchResponseResolver) => {
spyOn(judicialRefDataService, 'searchJudicialUserByPersonalCodes').and.returnValue(of(dataRef));
spyOn(service, 'getUsersByPanelRequirements$').and.callThrough();
spyOn(service, 'getUsersData$').and.callThrough();
it('should resolve judicial user data when panel requirements are set', inject([JudicialUserSearchResponseResolver], (service: JudicialUserSearchResponseResolver) => {
spyOn(judicialRefDataService, 'searchJudicialUserByPersonalCodes').withArgs(judgePersonalCodes).and.returnValue(of(judicialUsers));
spyOn(service, 'getUsersByPanelRequirements$').and.returnValue(of(judgePersonalCodes));
spyOn(service, 'getUsersData$').withArgs(judgePersonalCodes).and.returnValue(of(judicialUsers));
service.resolve().subscribe((refData: JudicialUserModel[]) => {
expect(service.getUsersByPanelRequirements$).toHaveBeenCalled();
expect(service.getUsersData$).toHaveBeenCalled();
expect(judicialRefDataService.searchJudicialUserByPersonalCodes).not.toHaveBeenCalled();
expect(refData).toEqual([testJudge1, testJudge2]);
});
}));

it('should resolve judicial user data when panel requirements are not set', inject([JudicialUserSearchResponseResolver], (service: JudicialUserSearchResponseResolver) => {
spyOn(judicialRefDataService, 'searchJudicialUserByPersonalCodes').and.returnValue(of([]));
spyOn(service, 'getUsersByPanelRequirements$').and.returnValue(of([]));
spyOn(service, 'getUsersData$').and.returnValue(of([]));
service.resolve().subscribe((refData: JudicialUserModel[]) => {
expect(service.getUsersByPanelRequirements$).toHaveBeenCalled();
expect(service.getUsersData$).not.toHaveBeenCalled();
expect(judicialRefDataService.searchJudicialUserByPersonalCodes).not.toHaveBeenCalled();
expect(refData).toEqual([]);
});
}));

it('should return empty array if judicialMemberIds is null', inject([JudicialUserSearchResponseResolver], (service: JudicialUserSearchResponseResolver) => {
spyOn(service, 'getUsersByPanelRequirements$').and.returnValue(of(null));
service.resolve().subscribe((refData: JudicialUserModel[]) => {
expect(refData).toEqual([]);
});
}));

it('should return empty array if judicialMemberIds is undefined', inject([JudicialUserSearchResponseResolver], (service: JudicialUserSearchResponseResolver) => {
spyOn(service, 'getUsersByPanelRequirements$').and.returnValue(of(undefined));
service.resolve().subscribe((refData: JudicialUserModel[]) => {
expect(refData).toEqual([]);
});
}));

it('should return empty array if judicialMemberIds length is 0', inject([JudicialUserSearchResponseResolver], (service: JudicialUserSearchResponseResolver) => {
spyOn(service, 'getUsersByPanelRequirements$').and.returnValue(of([]));
service.resolve().subscribe((refData: JudicialUserModel[]) => {
expect(refData).toEqual([]);
});
}));

it('should return empty array if judicialMemberIds is a list containing null', inject([JudicialUserSearchResponseResolver], (service: JudicialUserSearchResponseResolver) => {
spyOn(service, 'getUsersByPanelRequirements$').and.returnValue(of([null]));
service.resolve().subscribe((refData: JudicialUserModel[]) => {
expect(refData).toEqual([]);
});
}));

it('should return empty array if judicialMemberIds is a list containing an empty string', inject([JudicialUserSearchResponseResolver], (service: JudicialUserSearchResponseResolver) => {
spyOn(service, 'getUsersByPanelRequirements$').and.returnValue(of(['']));
service.resolve().subscribe((refData: JudicialUserModel[]) => {
expect(refData).toEqual([]);
service.getUsersData$([]);
expect(judicialRefDataService.searchJudicialUserByPersonalCodes).toHaveBeenCalled();
});
}));
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Injectable } from '@angular/core';
import { Resolve } from '@angular/router';
import { select, Store } from '@ngrx/store';
import { Store } from '@ngrx/store';
import { Observable, of } from 'rxjs';
import { catchError, map, switchMap, take } from 'rxjs/operators';
import { catchError, switchMap, take } from 'rxjs/operators';
import { JudicialUserModel } from '../models/judicialUser.model';
import { JudicialRefDataService } from '../services/judicial-ref-data.service';
import * as fromHearingStore from '../store';
import { getHearingJudgeIds } from '../store/selectors/hearing-judges.selectors';

@Injectable({
providedIn: 'root'
Expand All @@ -23,24 +24,13 @@ export class JudicialUserSearchResponseResolver implements Resolve<JudicialUserM
return of(judicialMemberIds);
}), take(1),
switchMap((judicialMemberIds) => {
return judicialMemberIds && judicialMemberIds.length ? this.getUsersData$(judicialMemberIds) : of([]);
return judicialMemberIds && judicialMemberIds.length && judicialMemberIds[0] ? this.getUsersData$(judicialMemberIds) : of([]);
})
);
}

public getUsersByPanelRequirements$(): Observable<string[]> {
return this.hearingStore.pipe(select(fromHearingStore.getHearingRequest)).pipe(
map((hearingRequest) => {
const hearingJudgeIds: string[] = [];
if (hearingRequest.hearingRequestMainModel?.hearingResponse?.hearingDaySchedule?.length) {
const hearingJudgeId = hearingRequest.hearingRequestMainModel.hearingResponse.hearingDaySchedule[0].hearingJudgeId;
if (hearingJudgeId?.trim().length > 0) {
hearingJudgeIds.push(hearingJudgeId);
}
}
return hearingJudgeIds;
})
);
return this.hearingStore.select(getHearingJudgeIds);
}

public getUsersData$(judgePersonalCodesList: string[]): Observable<JudicialUserModel[]> {
Expand Down
67 changes: 67 additions & 0 deletions src/hearings/store/selectors/hearing-judges.selectors.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { getHearingJudgeIds } from './hearing-judges.selectors';
import { select, Store, StoreModule } from '@ngrx/store';
import { reducers, State } from '../reducers';
import { TestBed } from '@angular/core/testing';

describe('Hearing Judges selectors', () => {
let store: Store<State>;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
StoreModule.forRoot({}),
StoreModule.forFeature('hearings', reducers)
]
});
store = TestBed.inject(Store);
spyOn(store, 'dispatch').and.callThrough();
});

describe('getHearingJudgeIds', () => {
it('should return hearings judge ids state', () => {
let result = null;
store.pipe(select(getHearingJudgeIds)).subscribe((value) => {
result = value;
});
expect(result).toEqual([]);
});
it('should return an empty array if state is undefined', () => {
const state = undefined;
const result = getHearingJudgeIds.projector(state);
expect(result).toEqual([]);
});
it('should return an empty array if hearingList is undefined', () => {
const state = { hearingList: undefined };
const result = getHearingJudgeIds.projector(state);
expect(result).toEqual([]);
});
it('should return an empty array if hearingListMainModel is undefined', () => {
const state = { hearingList: { hearingListMainModel: undefined } };
const result = getHearingJudgeIds.projector(state);
expect(result).toEqual([]);
});
it('should return an empty array if caseHearings is undefined', () => {
const state = { hearingList: { hearingListMainModel: { caseHearings: undefined } } };
const result = getHearingJudgeIds.projector(state);
expect(result).toEqual([]);
});
it('should return an empty array if caseHearings is empty', () => {
const state = { hearingList: { hearingListMainModel: { caseHearings: [] } } };
const result = getHearingJudgeIds.projector(state);
expect(result).toEqual([]);
});
it('should return the correct judge ids for each hearing', () => {
const state = {
hearingList: {
hearingListMainModel: {
caseHearings: [
{ hearingDaySchedule: [{ hearingJudgeId: 1001 }, { hearingJudgeId: 1002 }] },
{ hearingDaySchedule: [{ hearingJudgeId: 1003 }] }
]
}
}
};
const result = getHearingJudgeIds.projector(state);
expect(result).toEqual([1001, 1002, 1003]);
});
});
});
18 changes: 18 additions & 0 deletions src/hearings/store/selectors/hearing-judges.selectors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createSelector } from '@ngrx/store';
import * as fromFeature from '../reducers';
export const getHearingJudgeIds = createSelector(
fromFeature.getHearingsFeatureState,
(state: fromFeature.State) => {
if (!state) {
return [];
}
const caseHearings = state.hearingList && state.hearingList.hearingListMainModel && state.hearingList.hearingListMainModel.caseHearings || [];
return caseHearings.reduce((acc, caseHearing) => {
if (caseHearing.hearingDaySchedule) {
const judges = caseHearing.hearingDaySchedule.map((schedule) => schedule.hearingJudgeId);
return acc.concat(judges);
}
return acc;
}, []);
}
);
2 changes: 1 addition & 1 deletion yarn-audit-known-issues

Large diffs are not rendered by default.

0 comments on commit 8cb5579

Please sign in to comment.