Skip to content

Commit

Permalink
bug fixes during local testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaed Parkar committed Nov 7, 2023
1 parent e9fe8cb commit 20478ca
Show file tree
Hide file tree
Showing 18 changed files with 250 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using AdminWebsite.UnitTests.Helper;
using BookingsApi.Client;
using BookingsApi.Contract.V1.Requests;
using BookingsApi.Contract.V1.Requests.Enums;
using BookingsApi.Contract.V1.Responses;
using BookingsApi.Contract.V2.Enums;
using BookingsApi.Contract.V2.Requests;
Expand All @@ -32,6 +33,7 @@
using BookingStatus = BookingsApi.Contract.V1.Enums.BookingStatus;
using CaseResponse = BookingsApi.Contract.V1.Responses.CaseResponse;
using EndpointResponse = BookingsApi.Contract.V1.Responses.EndpointResponse;
using JudiciaryParticipantRequest = AdminWebsite.Contracts.Requests.JudiciaryParticipantRequest;
using LinkedParticipantResponse = BookingsApi.Contract.V1.Responses.LinkedParticipantResponse;
using LinkedParticipantType = BookingsApi.Contract.V1.Enums.LinkedParticipantType;

Expand Down Expand Up @@ -358,6 +360,11 @@ public void Setup()
Pin = "pin",
Sip = "sip"
}
},
JudiciaryParticipants = new List<JudiciaryParticipantResponse>()
{
new (){FullName = "Judge Fudge", FirstName = "John", LastName = "Doe", HearingRoleCode = JudiciaryParticipantHearingRoleCode.Judge, PersonalCode = "1234"},
new (){FullName = "Jane Doe", FirstName = "Jane", LastName = "Doe", HearingRoleCode = JudiciaryParticipantHearingRoleCode.PanelMember, PersonalCode = "4567"}
}
};
}
Expand Down Expand Up @@ -605,15 +612,36 @@ public async Task Should_return_updated_hearingV2()
LinkedParticipantContactEmail = "[email protected]",
Type = AdminWebsite.Contracts.Enums.LinkedParticipantType.Interpreter
}
}
},
});
_addNewParticipantRequest.JudiciaryParticipants = new List<JudiciaryParticipantRequest>()
{
new()
{
PersonalCode = "4567", DisplayName = "Jane Doe 2", Role = JudiciaryParticipantHearingRoleCode.PanelMember.ToString()
},
new()
{
PersonalCode = "5678", DisplayName = "New Judge Fudge", Role = JudiciaryParticipantHearingRoleCode.Judge.ToString()
}
};
var result = await _controller.EditHearing(_validId, _addNewParticipantRequest);
var hearing = (AdminWebsite.Contracts.Responses.HearingDetailsResponse)((OkObjectResult)result.Result).Value;
hearing.Id.Should().Be(updatedHearing.Id);
_bookingsApiClient.Verify(x => x.UpdateHearingDetails2Async(It.IsAny<Guid>(),
It.Is<UpdateHearingRequestV2>(u =>
!u.Cases.IsNullOrEmpty())),
Times.Once);

_bookingsApiClient.Verify(x => x.RemoveJudiciaryParticipantFromHearingAsync(hearing.Id, "1234"),
Times.Once);

_bookingsApiClient.Verify(x => x.UpdateJudiciaryParticipantAsync(hearing.Id, "4567", It.IsAny<UpdateJudiciaryParticipantRequest>()),
Times.Once);

_bookingsApiClient.Verify(
x => x.AddJudiciaryParticipantsToHearingAsync(hearing.Id,
It.IsAny<IEnumerable<BookingsApi.Contract.V1.Requests.JudiciaryParticipantRequest>>()), Times.Once);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe('EndpointsComponent', () => {
expect(component.duplicateDa).toBe(false);
expect(component.failedValidation).toBe(false);
expect(component.hearing.endpoints[0].displayName).toBe('200');
expect(component.hearing.endpoints[0].defenceAdvocate).toBe('');
expect(component.hearing.endpoints[0].defenceAdvocate).toBeNull();
expect(videoHearingsServiceSpy.updateHearingRequest).toHaveBeenCalled();
expect(routerSpy.navigate).toHaveBeenCalledWith(['/other-information']);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,13 @@ export class EndpointsComponent extends BookingBaseComponent implements OnInit,
for (const control of this.endpoints.controls) {
const endpointModel = new EndpointModel();
if (control.value.displayName.trim() !== '') {
const displayNameText = SanitizeInputText(control.value.displayName);
endpointModel.displayName = displayNameText;
let defenceAdvocate = null;
if (control.value.defenceAdvocate !== this.constants.None) {
defenceAdvocate = control.value.defenceAdvocate;
}
endpointModel.displayName = SanitizeInputText(control.value.displayName);
endpointModel.id = control.value.id;
endpointModel.defenceAdvocate = control.value.defenceAdvocate !== this.constants.None ? control.value.defenceAdvocate : '';
endpointModel.defenceAdvocate = defenceAdvocate;
newEndpointsArray.push(endpointModel);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ describe('AddJudicialOfficeHoldersComponent', () => {
]);
judicialServiceSpy = jasmine.createSpyObj('JudicialService', ['searchJudicialMembers']);
videoHearingsServiceSpy.getCurrentRequest.and.returnValue(hearing);
bookingServiceSpy = jasmine.createSpyObj('BookingService', ['getParticipantEmail', 'removeParticipantEmail']);
bookingServiceSpy = jasmine.createSpyObj('BookingService', ['getParticipantEmail', 'removeParticipantEmail', 'isEditMode']);
bookingServiceSpy.isEditMode.and.returnValue(false);
loggerSpy = jasmine.createSpyObj('Logger', ['debug', 'warn']);
routerSpy = jasmine.createSpyObj('Router', ['navigate']);
await TestBed.configureTestingModule({
Expand Down Expand Up @@ -107,10 +108,17 @@ describe('AddJudicialOfficeHoldersComponent', () => {
});

describe('continueToNextStep', () => {
it('should navigate to the add participants page', () => {
it('should navigate to the add participants page when not in edit mode', () => {
bookingServiceSpy.isEditMode.and.returnValue(false);
component.continueToNextStep();
expect(routerSpy.navigate).toHaveBeenCalledWith([PageUrls.AddParticipants]);
});

it('should navigate to the summary page when in edit mode', () => {
bookingServiceSpy.isEditMode.and.returnValue(true);
component.continueToNextStep();
expect(routerSpy.navigate).toHaveBeenCalledWith([PageUrls.Summary]);
});
});

describe('prepoplateFormForEdit', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,13 @@ export class AddJudicialOfficeHoldersComponent implements OnInit, OnDestroy {
}

continueToNextStep() {
this.logger.debug(`${this.loggerPrefix} Navigating to add participants.`);
this.router.navigate([PageUrls.AddParticipants]);
if (this.bookingService.isEditMode()) {
this.logger.debug(`${this.loggerPrefix} In edit mode. Returning to summary.`);
this.router.navigate([PageUrls.Summary]);
} else {
this.logger.debug(`${this.loggerPrefix} Navigating to add participants.`);
this.router.navigate([PageUrls.AddParticipants]);
}
}

refreshPanelMemberText() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { JudiciaryParticipantResponse } from 'src/app/services/clients/api-client';

export type JudicaryRoleCode = 'Judge' | 'PanelMember';

export class JudicialMemberDto {
Expand All @@ -11,4 +13,18 @@ export class JudicialMemberDto {
public telephone: string,
public personalCode: string
) {}

static fromJudiciaryParticipantResponse(response: JudiciaryParticipantResponse): JudicialMemberDto {
const dto = new JudicialMemberDto(
response.first_name,
response.last_name,
response.full_name,
response.email,
response.work_phone,
response.personal_code
);
dto.roleCode = response.role_code as JudicaryRoleCode;
dto.displayName = response.display_name;
return dto;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ videoHearingsServiceSpy = jasmine.createSpyObj<VideoHearingsService>('VideoHeari
]);
const launchDarklyServiceSpy = jasmine.createSpyObj<LaunchDarklyService>('LaunchDarklyService', ['getFlag']);
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.eJudFeature).and.returnValue(of(true));
launchDarklyServiceSpy.getFlag.withArgs(FeatureFlags.useV2Api).and.returnValue(of(false));
const bookingStatusService = new BookingStatusService(videoHearingsServiceSpy);

describe('SummaryComponent with valid request', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class SummaryComponent implements OnInit, OnDestroy {
@ViewChild(RemoveInterpreterPopupComponent) removeInterpreterPopupComponent: RemoveInterpreterPopupComponent;
judgeAssigned: boolean;
ejudFeatureFlag = false;
useApiV2 = false;
saveFailedMessages: string[];

constructor(
Expand All @@ -95,6 +96,24 @@ export class SummaryComponent implements OnInit, OnDestroy {
this.ejudFeatureFlag = result;
})
);

this.$subscriptions.push(
this.featureService
.getFlag<boolean>(FeatureFlags.eJudFeature)
.pipe(first())
.subscribe(result => {
this.ejudFeatureFlag = result;
})
);

this.$subscriptions.push(
this.featureService
.getFlag<boolean>(FeatureFlags.useV2Api)
.pipe(first())
.subscribe(result => {
this.useApiV2 = result;
})
);
}

ngOnInit() {
Expand Down Expand Up @@ -143,17 +162,26 @@ export class SummaryComponent implements OnInit, OnDestroy {

private confirmRemoveParticipant() {
const participant = this.hearing.participants.find(x => x.email.toLowerCase() === this.selectedParticipantEmail.toLowerCase());
const title = participant?.title ? `${participant.title}` : '';
this.removerFullName = participant ? `${title} ${participant.first_name} ${participant.last_name}` : '';

const isInterpretee =
(participant.linked_participants &&
participant.linked_participants.length > 0 &&
participant.hearing_role_name.toLowerCase() !== HearingRoles.INTERPRETER) ||
this.hearing.participants.some(p => p.interpreterFor === participant.email);
if (isInterpretee) {
this.showConfirmRemoveInterpretee = true;
} else {

if (participant) {
const title = participant?.title ? `${participant.title}` : '';
this.removerFullName = participant ? `${title} ${participant.first_name} ${participant.last_name}` : '';

const isInterpretee =
(participant.linked_participants &&
participant.linked_participants.length > 0 &&
participant.hearing_role_name.toLowerCase() !== HearingRoles.INTERPRETER) ||
this.hearing.participants.some(p => p.interpreterFor === participant.email);
if (isInterpretee) {
this.showConfirmRemoveInterpretee = true;
} else {
this.showConfirmationRemoveParticipant = true;
}
}

const judicalParticipant = this.hearing.judiciaryParticipants.findIndex(x => x.email === this.selectedParticipantEmail);
if (judicalParticipant > -1) {
this.removerFullName = this.hearing.judiciaryParticipants[judicalParticipant].fullName;
this.showConfirmationRemoveParticipant = true;
}
}
Expand Down Expand Up @@ -184,10 +212,17 @@ export class SummaryComponent implements OnInit, OnDestroy {
this.hearing.participants.splice(indexOfParticipant, 1);
this.removeLinkedParticipant(this.selectedParticipantEmail);
this.hearing = { ...this.hearing };
this.hearingService.updateHearingRequest(this.hearing);
this.hearingService.setBookingHasChanged(true);
this.bookingService.removeParticipantEmail();
}

const judicalParticipant = this.hearing.judiciaryParticipants.findIndex(x => x.email === this.selectedParticipantEmail);
if (judicalParticipant > -1) {
this.hearing.judiciaryParticipants.splice(judicalParticipant, 1);
this.hearing = { ...this.hearing };
}

this.hearingService.updateHearingRequest(this.hearing);
this.hearingService.setBookingHasChanged(true);
this.bookingService.removeParticipantEmail();
}

private retrieveHearingSummary() {
Expand Down Expand Up @@ -472,6 +507,10 @@ export class SummaryComponent implements OnInit, OnDestroy {
}

navToAddJudge() {
this.router.navigate([PageUrls.AssignJudge]);
if (this.useApiV2) {
this.router.navigate([PageUrls.AddJudicialOfficeHolders]);
} else {
this.router.navigate([PageUrls.AssignJudge]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ export class AppInsightsLogger implements LogAdapter {
this.appInsights.loadAppInsights();
this.oidcService.userData$.subscribe(ud => {
this.appInsights.addTelemetryInitializer((envelope: ITelemetryItem) => {
const remoteDepedencyType = 'RemoteDependencyData';
if (envelope.baseType === remoteDepedencyType && (envelope.baseData.name as string)) {
const name = envelope.baseData.name as string;
if (name.startsWith('HEAD /assets/images/favicons/favicon.ico?')) {
// ignore favicon requests used to poll for availability
return false;
}
}
envelope.tags['ai.cloud.role'] = 'vh-admin-web';
envelope.tags['ai.user.id'] = ud.userData.preferred_username.toLowerCase();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7401,6 +7401,8 @@ export class EditHearingRequest implements IEditHearingRequest {
case!: EditCaseRequest;
/** List of participants in hearing */
participants!: EditParticipantRequest[] | undefined;
/** List of judiciary participants in hearing */
judiciary_participants?: JudiciaryParticipantRequest[] | undefined;
telephone_participants?: EditTelephoneParticipantRequest[] | undefined;
/** Any other information about the hearing */
other_information?: string | undefined;
Expand Down Expand Up @@ -7432,6 +7434,11 @@ export class EditHearingRequest implements IEditHearingRequest {
this.participants = [] as any;
for (let item of _data['participants']) this.participants!.push(EditParticipantRequest.fromJS(item));
}
if (Array.isArray(_data['judiciary_participants'])) {
this.judiciary_participants = [] as any;
for (let item of _data['judiciary_participants'])
this.judiciary_participants!.push(JudiciaryParticipantRequest.fromJS(item));
}
if (Array.isArray(_data['telephone_participants'])) {
this.telephone_participants = [] as any;
for (let item of _data['telephone_participants'])
Expand Down Expand Up @@ -7465,6 +7472,10 @@ export class EditHearingRequest implements IEditHearingRequest {
data['participants'] = [];
for (let item of this.participants) data['participants'].push(item.toJSON());
}
if (Array.isArray(this.judiciary_participants)) {
data['judiciary_participants'] = [];
for (let item of this.judiciary_participants) data['judiciary_participants'].push(item.toJSON());
}
if (Array.isArray(this.telephone_participants)) {
data['telephone_participants'] = [];
for (let item of this.telephone_participants) data['telephone_participants'].push(item.toJSON());
Expand Down Expand Up @@ -7494,6 +7505,8 @@ export interface IEditHearingRequest {
case: EditCaseRequest;
/** List of participants in hearing */
participants: EditParticipantRequest[] | undefined;
/** List of judiciary participants in hearing */
judiciary_participants?: JudiciaryParticipantRequest[] | undefined;
telephone_participants?: EditTelephoneParticipantRequest[] | undefined;
/** Any other information about the hearing */
other_information?: string | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import { ParticipantModel } from '../common/model/participant.model';
export class RecordingGuardService {
excludedCaseTypes: string[] = ['Court of Appeal Criminal Division', 'Crime Crown Court'];
mandatoryRecordingRoles: string[] = ['Interpreter'];
mandatoryRecordingRoleCodes: string[] = ['INTP'];

switchOffRecording(caseType: string): boolean {
return this.excludedCaseTypes.indexOf(caseType) > -1;
}

mandatoryRecordingForHearingRole(participants: ParticipantModel[]) {
return participants.some(pat => this.mandatoryRecordingRoles.includes(pat.hearing_role_name.trim()));
return (
participants.some(pat => this.mandatoryRecordingRoles.includes(pat.hearing_role_name?.trim())) ||
participants.some(pat => this.mandatoryRecordingRoleCodes.includes(pat.hearing_role_code?.trim()))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
LinkedParticipantResponse,
BookingStatus,
AllocatedCsoResponse,
JusticeUserResponse
JusticeUserResponse,
JudiciaryParticipantResponse
} from './clients/api-client';
import { HearingModel } from '../common/model/hearing.model';
import { CaseModel } from '../common/model/case.model';
Expand Down Expand Up @@ -201,6 +202,19 @@ describe('Video hearing service', () => {
model.other_information = 'note';
model.cases = [caseModel];
model.participants = [];
model.judiciary_participants = [
new JudiciaryParticipantResponse({
title: 'Mr',
first_name: 'Dan',
last_name: 'Smith',
display_name: 'Judge Dan Smith',
email: '[email protected]',
full_name: 'Dan Smith',
personal_code: '1234',
work_phone: '123123123',
role_code: 'Judge'
})
];
model.audio_recording_required = true;

const request = service.mapHearingDetailsResponseToHearingModel(model);
Expand All @@ -215,6 +229,8 @@ describe('Video hearing service', () => {
expect(request.scheduled_date_time).toEqual(new Date(date));
expect(request.scheduled_duration).toBe(30);
expect(request.audio_recording_required).toBeTruthy();
expect(request.judiciaryParticipants[0]).toBeTruthy();
expect(request.judiciaryParticipants[0].displayName).toBe('Judge Dan Smith');
});

it('should map ParticipantResponse to ParticipantModel', () => {
Expand Down
Loading

0 comments on commit 20478ca

Please sign in to comment.