Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-scott committed Dec 20, 2024
1 parent e9f8c51 commit 9364951
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export abstract class AddParticipantBaseDirective extends BookingBaseComponent i
this.displayErrorNoParticipants = false;
this.displayAdd();
this.enableFields();
this.participantDetails = this.participantDetails.clone();
this.participantDetails = participantDetails.clone();

if (participantDetails.isExistPerson) {
this.disableLastFirstNames();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ describe('ParticipantItemComponent', () => {
let debugElement: DebugElement;

bookingServiceSpy = jasmine.createSpyObj<BookingService>('BookingService', ['setEditMode', 'setParticipantEmail']);
const participant: any = {
const participant = new VHParticipant({
title: 'Mrs',
first_name: 'Sam',
firstName: 'Sam',
isJudiciaryMember: false
};
});

beforeEach(waitForAsync(() => {
videoHearingsServiceSpy = jasmine.createSpyObj<VideoHearingsService>(['isConferenceClosed', 'isHearingAboutToStart']);
Expand Down Expand Up @@ -141,22 +141,22 @@ describe('ParticipantItemComponent', () => {
});

it('should return true if participant is a judge', () => {
participant.is_judge = true;
participant.is_exist_person = true;
participant.hearingRoleName = Constants.HearingRoles.Judge;
participant.isExistPerson = true;
component.participant = participant;
fixture.detectChanges();
expect(component.isJudge).toBeTruthy();
});

it('should return true if participant is a staff member', () => {
participant.hearing_role_name = Constants.HearingRoles.StaffMember;
participant.hearingRoleName = Constants.HearingRoles.StaffMember;
component.participant = participant;
fixture.detectChanges();
expect(component.isStaffMember).toBeTruthy();
});

it('should return false if participant is not a staff member', () => {
participant.hearing_role_name = Constants.HearingRoles.PanelMember;
participant.hearingRoleName = Constants.HearingRoles.PanelMember;
component.participant = participant;
fixture.detectChanges();
expect(component.isStaffMember).toBeFalsy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ export class VHBooking {
constructor(init?: Partial<VHBooking>) {
Object.assign(this, init);

this.hearingId = init.hearingId ?? '';
this.scheduledDuration = init.scheduledDuration ?? 0;
this.participants = init.participants ?? [];
this.judiciaryParticipants = init.judiciaryParticipants ?? [];
this.endpoints = init.endpoints ?? [];
this.linkedParticipants = init.linkedParticipants ?? [];
this.hearingDates = init.hearingDates ?? [];
this.updatedDate = init.updatedDate ?? new Date();
this.supplier = init.supplier ?? VideoSupplier.Vodafone;
this.hearingId = init?.hearingId ?? '';
this.scheduledDuration = init?.scheduledDuration ?? 0;
this.participants = init?.participants ?? [];
this.judiciaryParticipants = init?.judiciaryParticipants ?? [];
this.endpoints = init?.endpoints ?? [];
this.linkedParticipants = init?.linkedParticipants ?? [];
this.hearingDates = init?.hearingDates ?? [];
this.updatedDate = init?.updatedDate ?? new Date();
this.supplier = init?.supplier ?? VideoSupplier.Vodafone;
}

get durationInHoursAndMinutes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { BHClient, JudgeAccountType, JudgeResponse, PersonResponseV2 } from './c
import { Constants } from '../common/constants';
import { LaunchDarklyService } from './launch-darkly.service';
import { VHParticipant } from '../common/model/vh-participant';
import * as ApiContractToClientModelMappers from '../common/model/api-contract-to-client-model-mappers';
import { mapJudgeResponseToVHParticipant, mapPersonResponseToVHParticipant } from '../common/model/api-contract-to-client-model-mappers';

let service: SearchService;

Expand Down Expand Up @@ -105,8 +105,6 @@ participant2.email = 'participant2Email';
const participantList: VHParticipant[] = [participant1, participant2];
let clientApiSpy: jasmine.SpyObj<BHClient>;
const launchDarklyServiceSpy = jasmine.createSpyObj<LaunchDarklyService>('LaunchDarklyService', ['getFlag']);
let mapPersonResponseToVHParticipantSpy: jasmine.Spy;
let mapJudgeResponseToVHParticipantSpy: jasmine.Spy;

describe('SearchService', () => {
beforeEach(() => {
Expand All @@ -115,13 +113,6 @@ describe('SearchService', () => {
clientApiSpy.postPersonBySearchTerm.and.returnValue(of(personList));
clientApiSpy.postJudgesBySearchTerm.and.returnValue(of(judgeList));

mapPersonResponseToVHParticipantSpy = spyOn(ApiContractToClientModelMappers, 'mapPersonResponseToVHParticipant').and.returnValue(
participant1
);
mapJudgeResponseToVHParticipantSpy = spyOn(ApiContractToClientModelMappers, 'mapJudgeResponseToVHParticipant').and.returnValue(
judgeParticipant1
);

TestBed.configureTestingModule({
imports: [HttpClientModule],
providers: [
Expand All @@ -143,33 +134,42 @@ describe('SearchService', () => {

it('should call searchEntries and map response when role is not judge or judiciary ', () => {
const terms = validSearchTerms;
const mappedParticipants: VHParticipant[] = [];

service.participantSearch(terms, roleRegular).subscribe(participants => {
expect(participants.length).toEqual(participantList.length);
mappedParticipants.push(...participants);
});
expect(service.searchEntries).toHaveBeenCalledWith(terms);
expect(service.searchEntries).toHaveBeenCalledTimes(1);
expect(service.searchJudgeAccounts).toHaveBeenCalledTimes(0);

expect(ApiContractToClientModelMappers.mapPersonResponseToVHParticipant).toHaveBeenCalledTimes(personList.length);
expect(mappedParticipants.length).toBe(personList.length);
personList.forEach(person => {
expect(ApiContractToClientModelMappers.mapPersonResponseToVHParticipant).toHaveBeenCalledWith(person);
const expectedMappedParticipant = mapPersonResponseToVHParticipant(person);
const matchingParticipant = mappedParticipants.find(p => compareWithoutExternalReferenceId(p, expectedMappedParticipant));
expect(matchingParticipant).toBeTruthy();
});
});

it('should call searchJudgeAccounts and map response when role is judge ', () => {
const terms = validSearchTerms;
const mappedParticipants: VHParticipant[] = [];

service.participantSearch(terms, roleJudge).subscribe(participants => {
expect(participants.length).toEqual(judgeParticipantList.length);
mappedParticipants.push(...participants);
});
expect(service.searchJudgeAccounts).toHaveBeenCalledWith(terms);
expect(service.searchJudgeAccounts).toHaveBeenCalledTimes(1);

expect(service.searchEntries).toHaveBeenCalledTimes(0);

expect(mapJudgeResponseToVHParticipantSpy).toHaveBeenCalledTimes(judgeList.length);
expect(mappedParticipants.length).toBe(judgeList.length);
judgeList.forEach(judge => {
expect(mapJudgeResponseToVHParticipantSpy).toHaveBeenCalledWith(judge);
const expectedMappedParticipant = mapJudgeResponseToVHParticipant(judge);
const matchingParticipant = mappedParticipants.find(p => compareWithoutExternalReferenceId(p, expectedMappedParticipant));
expect(matchingParticipant).toBeTruthy();
});
});
});
Expand Down Expand Up @@ -207,3 +207,10 @@ describe('SearchService', () => {
expect(list.length).toBeGreaterThan(0);
});
});

// The participant's external reference id is auto-generated so will not match in the assertion
function compareWithoutExternalReferenceId(obj1: any, obj2: any): boolean {
const { externalReferenceId: _, ...rest1 } = obj1;
const { externalReferenceId: __, ...rest2 } = obj2;
return JSON.stringify(rest1) === JSON.stringify(rest2);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import {
BHClient,
BookingStatus,
CancelMultiDayHearingRequest,
CaseResponse,
ClientSettingsResponse,
EditMultiDayHearingRequest,
HearingDetailsResponse,
JudiciaryParticipantResponse,
MultiHearingRequest,
UpdateHearingInGroupRequest,
VideoSupplier
Expand Down

0 comments on commit 9364951

Please sign in to comment.