Skip to content

Commit

Permalink
Merge branch 'master' into bug/VIH-10362-v1-ejud-judge-name-not-popul…
Browse files Browse the repository at this point in the history
…ating
  • Loading branch information
oliver-scott authored Dec 11, 2023
2 parents 5beaa3b + d93b208 commit d783c2f
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export const Constants = {
Observer: 'Observer',
Interpreter: 'Interpreter'
},
UserRoles: {
Judge: 'Judge',
StaffMember: 'Staff Member'
},
ManageJusticeUsers: {
EmptySearchResults:
'No users matching this search criteria were found. Please check the search and try again. Or, add the team member.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { HearingModel } from 'src/app/common/model/hearing.model';
import { BookingPersistService } from './bookings-persist.service';
import { v4 as uuid } from 'uuid';
import { CaseModel } from '../common/model/case.model';
import { ParticipantModel } from '../common/model/participant.model';
import { JudicialMemberDto } from '../booking/judicial-office-holders/models/add-judicial-member.model';

function MockGroupedBookings(hearings: BookingsDetailsModel[]): BookingsListModel {
const model = new BookingsListModel(new Date());
Expand Down Expand Up @@ -87,6 +89,88 @@ describe('BookingsPersistService', () => {
const updatedHearing = service.bookingList[0].BookingsDetails[0];
expect(updatedHearing.HearingCaseName).toBe(updatedCase.name);
});

it('should update judge name for selected hearing', () => {
service.bookingList = [MockGroupedBookings([MockBookedHearing(), MockBookedHearing()])];

service.selectedGroupIndex = 0;
service.selectedItemIndex = 0;

const hearing = new HearingModel();
hearing.court_id = 1;
hearing.court_room = 'court room';
hearing.court_name = 'court';
const participants: ParticipantModel[] = [];
const judge = new ParticipantModel({ is_judge: true, display_name: 'Judge Test' });
participants.push(judge);
hearing.participants = participants;

const updatedCase = new CaseModel();
updatedCase.name = 'updated case';
hearing.cases = [updatedCase];

hearing.hearing_id = service.bookingList[0].BookingsDetails[0].HearingId;
service.updateBooking(hearing);

const updatedHearing = service.bookingList[0].BookingsDetails[0];
expect(updatedHearing.JudgeName).toBe(judge.display_name);
});

it('should update judge name for selected hearing with judiciary participant judge', () => {
service.bookingList = [MockGroupedBookings([MockBookedHearing(), MockBookedHearing()])];

service.selectedGroupIndex = 0;
service.selectedItemIndex = 0;

const hearing = new HearingModel();
hearing.court_id = 1;
hearing.court_room = 'court room';
hearing.court_name = 'court';
const judiciaryParticipants: JudicialMemberDto[] = [];
const judge = new JudicialMemberDto('Judge', 'One', 'Judge One', 'email', 'telephone', 'personalCode');
judge.displayName = 'Judge Test';
judge.roleCode = 'Judge';
judiciaryParticipants.push(judge);
hearing.judiciaryParticipants = judiciaryParticipants;

const updatedCase = new CaseModel();
updatedCase.name = 'updated case';
hearing.cases = [updatedCase];

hearing.hearing_id = service.bookingList[0].BookingsDetails[0].HearingId;
service.updateBooking(hearing);

const updatedHearing = service.bookingList[0].BookingsDetails[0];
expect(updatedHearing.JudgeName).toBe(judge.displayName);
});

it('should update judge name for selected hearing with judiciary participants but no judge', () => {
service.bookingList = [MockGroupedBookings([MockBookedHearing(), MockBookedHearing()])];

service.selectedGroupIndex = 0;
service.selectedItemIndex = 0;

const hearing = new HearingModel();
hearing.court_id = 1;
hearing.court_room = 'court room';
hearing.court_name = 'court';
const judiciaryParticipants: JudicialMemberDto[] = [];
const participant = new JudicialMemberDto('Panel', 'Member', 'Panel Member', 'email', 'telephone', 'personalCode');
participant.displayName = 'Panel Member';
participant.roleCode = 'PanelMember';
judiciaryParticipants.push(participant);
hearing.judiciaryParticipants = judiciaryParticipants;

const updatedCase = new CaseModel();
updatedCase.name = 'updated case';
hearing.cases = [updatedCase];

hearing.hearing_id = service.bookingList[0].BookingsDetails[0].HearingId;
service.updateBooking(hearing);

const updatedHearing = service.bookingList[0].BookingsDetails[0];
expect(updatedHearing.JudgeName).toBe('');
});
});

describe('#resetAll', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Injectable } from '@angular/core';
import { BookingsListModel, BookingsDetailsModel } from '../common/model/bookings-list.model';
import { HearingModel } from '../common/model/hearing.model';
import { ParticipantModel } from '../common/model/participant.model';

@Injectable({ providedIn: 'root' })
export class BookingPersistService {
Expand Down Expand Up @@ -59,7 +58,7 @@ export class BookingPersistService {
if (this.isValidDate(hearing.updated_date)) {
hearingUpdate.LastEditDate = new Date(hearing.updated_date);
}
hearingUpdate.JudgeName = this.getJudgeName(hearing.participants);
hearingUpdate.JudgeName = this.getJudgeName(hearing);
return hearingUpdate;
}
}
Expand All @@ -73,8 +72,13 @@ export class BookingPersistService {
return false;
}

getJudgeName(participants: ParticipantModel[]) {
const judge = participants.find(x => x.case_role_name === 'Judge');
getJudgeName(hearing: HearingModel) {
if (hearing.judiciaryParticipants && hearing.judiciaryParticipants.length > 0) {
const judiciaryJudge = hearing.judiciaryParticipants.find(x => x.roleCode === 'Judge');
return judiciaryJudge ? judiciaryJudge.displayName : '';
}

const judge = hearing.participants.find(x => x.is_judge);
return judge ? judge.display_name : '';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,23 @@ describe('Video hearing service', () => {
participant.telephone_number = '123123123';
participant.case_role_name = 'Respondent';
participant.hearing_role_name = 'Litigant in person';
participant.user_role_name = 'Individual';
participants.push(participant);

const judgeParticipant = new ParticipantResponse();
judgeParticipant.title = 'Mr';
judgeParticipant.first_name = 'Judge';
judgeParticipant.middle_names = 'MiddleNames';
judgeParticipant.last_name = 'Test';
judgeParticipant.username = '[email protected]';
judgeParticipant.display_name = 'Judge Test';
judgeParticipant.contact_email = '[email protected]';
judgeParticipant.telephone_number = '123123123';
judgeParticipant.case_role_name = null;
judgeParticipant.hearing_role_name = null;
judgeParticipant.user_role_name = 'Judge';
participants.push(judgeParticipant);

const model = service.mapParticipantResponseToParticipantModel(participants);

expect(model[0].title).toEqual(participant.title);
Expand All @@ -260,6 +275,19 @@ describe('Video hearing service', () => {
expect(model[0].phone).toEqual(participant.telephone_number);
expect(model[0].case_role_name).toEqual(participant.case_role_name);
expect(model[0].hearing_role_name).toEqual(participant.hearing_role_name);
expect(model[0].is_judge).toBeFalse();

expect(model[1].title).toEqual(judgeParticipant.title);
expect(model[1].first_name).toEqual(judgeParticipant.first_name);
expect(model[1].middle_names).toEqual(judgeParticipant.middle_names);
expect(model[1].last_name).toEqual(judgeParticipant.last_name);
expect(model[1].username).toEqual(judgeParticipant.username);
expect(model[1].display_name).toEqual(judgeParticipant.display_name);
expect(model[1].email).toEqual(judgeParticipant.contact_email);
expect(model[1].phone).toEqual(judgeParticipant.telephone_number);
expect(model[1].case_role_name).toEqual(judgeParticipant.case_role_name);
expect(model[1].hearing_role_name).toEqual(judgeParticipant.hearing_role_name);
expect(model[1].is_judge).toBeTrue();
});

it('should map ParticipantModel toParticipantResponse', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import {
BookingStatus,
AllocatedCsoResponse,
HearingRoleResponse,
JudiciaryParticipantRequest,
JudiciaryParticipantResponse
JudiciaryParticipantRequest
} from './clients/api-client';
import { HearingModel } from '../common/model/hearing.model';
import { CaseModel } from '../common/model/case.model';
Expand Down Expand Up @@ -433,11 +432,8 @@ export class VideoHearingsService {
participant.hearing_role_code = p.hearing_role_code;
participant.representee = p.representee;
participant.company = p.organisation;
participant.is_judge =
p.case_role_name === Constants.HearingRoles.Judge || p.hearing_role_code === Constants.HearingRoleCodes.Judge;
participant.is_staff_member =
p.case_role_name === Constants.HearingRoles.StaffMember ||
p.hearing_role_code === Constants.HearingRoleCodes.StaffMember;
participant.is_judge = p.user_role_name === Constants.UserRoles.Judge;
participant.is_staff_member = p.user_role_name === Constants.UserRoles.StaffMember;
participant.linked_participants = this.mapLinkedParticipantResponseToLinkedParticipantModel(p.linked_participants);
participant.user_role_name = p.user_role_name;
participants.push(participant);
Expand Down

0 comments on commit d783c2f

Please sign in to comment.