Skip to content

Commit

Permalink
VIH-10156 Replace hardcoded case types for audio recording exclusion (#…
Browse files Browse the repository at this point in the history
…1466)

* Replace hardcoded case types

* Refactor test data

* Map to bookings api

* Use bookings api pr url

* TODOs

* Replace with ResponseTestData

* More code coverage

* Sonar fixes

* Test updates

* Revert test url

* Update nuget packages
  • Loading branch information
oliver-scott authored Jan 17, 2025
1 parent 98753a4 commit 53e65e7
Show file tree
Hide file tree
Showing 44 changed files with 450 additions and 165 deletions.
12 changes: 6 additions & 6 deletions AdminWebsite/AdminWebsite.IntegrationTests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,18 @@
},
"BookingsApi.Client": {
"type": "Transitive",
"resolved": "3.1.14",
"contentHash": "j+zkb9f2uRlGWS3Jte2ES43XfBO/r434V8WmcDYm5wBoy5acl26f1bPLbd0mXH/bjd78BDhAu6Oo7LXl5cN2JQ==",
"resolved": "3.1.17",
"contentHash": "cfFV34hEehmJxJBOKEKA1pR0M/uFiO3PxD1nYyAptn2YNEvm/qWJ6MNgBy9pQKMn985t7/8KvJGiM5u2UNREdA==",
"dependencies": {
"BookingsApi.Common.DotNet6": "3.1.14",
"BookingsApi.Common.DotNet6": "3.1.17",
"Microsoft.AspNetCore.Mvc.Core": "2.2.5",
"System.Text.Json": "8.0.5"
}
},
"BookingsApi.Common.DotNet6": {
"type": "Transitive",
"resolved": "3.1.14",
"contentHash": "/N0w8827EwMPO9Suz1R9evG8G8DFPPYOhcUixyqxZDvPkgr4uqjgK7uX41OP2TtADgPBrDVPs66G1DmbKGfWXg==",
"resolved": "3.1.17",
"contentHash": "QoMDKjJjHXXBVUaNvDlaggxaR9aSjgm4BI125rjAYmDkbYVEPlOZqVSDy5z748fX7+xbg2eEwHRD5GE7XNJicA==",
"dependencies": {
"System.Text.Json": "8.0.5"
}
Expand Down Expand Up @@ -1502,7 +1502,7 @@
"type": "Project",
"dependencies": {
"AspNetCore.HealthChecks.Uris": "[8.0.1, )",
"BookingsApi.Client": "[3.1.14, )",
"BookingsApi.Client": "[3.1.17, )",
"FluentValidation.AspNetCore": "[11.3.0, )",
"LaunchDarkly.ServerSdk": "[8.5.0, )",
"MicroElements.Swashbuckle.FluentValidation": "[6.0.0, )",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AdminWebsite.Controllers.ReferenceData;
using AdminWebsite.Mappers;
using AdminWebsite.Services;
using BookingsApi.Contract.V2.Responses;
using Microsoft.AspNetCore.Mvc;

namespace AdminWebsite.UnitTests.Controllers.ReferenceData;

public class HearingTypesControllerTests
{
private Mock<IReferenceDataService> _referenceDataService;
private HearingTypesController _controller;

[SetUp]
public void SetUp()
{
_referenceDataService = new Mock<IReferenceDataService>();
_controller = new HearingTypesController(_referenceDataService.Object);
}

[Test]
public async Task Should_return_list_of_hearing_types()
{
// Arrange
var types = new List<CaseTypeResponseV2>
{
new()
{
Id = 1,
Name = "Name1",
ServiceId = "123",
IsAudioRecordingAllowed = true
},
new()
{
Id = 2,
Name = "Name2",
ServiceId = "456",
IsAudioRecordingAllowed = false
}
};

_referenceDataService.Setup(x => x.GetNonDeletedCaseTypesAsync(It.IsAny<CancellationToken>()))
.ReturnsAsync(types);

// Act
var response = await _controller.GetHearingTypes();

// Assert
var result = (OkObjectResult)response.Result;
result.Value.Should().BeEquivalentTo(types.Select(t => t.Map()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static HearingDetailsResponseV2 Build()
.With(x => x.Participants = new List<ParticipantResponseV2>())
.With(x => x.JudicialOfficeHolders = new List<JudiciaryParticipantResponse>())
.With(x => x.Cases = new List<CaseResponseV2> { Builder<CaseResponseV2>.CreateNew().Build() })
.With(x => x.ServiceIsAudioRecordingAllowed = true)
.Build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void Should_map_all_properties_for_BookingsResponse_V1()
ScheduledDateTime = DateTime.UtcNow,
ScheduledDuration = 1,
CaseTypeName = "caseTypeName",
CaseTypeIsAudioRecordingAllowed = true,
CourtRoom = "courtRoom",
CourtAddress = "courtAddress",
JudgeName = "judgeName",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public void should_map_v2_model_to_hearing_detail_response()
actual.ScheduledDateTime.Should().Be(hearing.ScheduledDateTime);
actual.ScheduledDuration.Should().Be(hearing.ScheduledDuration);
actual.HearingVenueCode.Should().Be(hearing.HearingVenueCode);
actual.ServiceId.Should().Be(hearing.ServiceId);
actual.CaseType.Should().NotBeNull();
actual.CaseType.Name.Should().Be(hearing.ServiceName);
actual.CaseType.ServiceId.Should().Be(hearing.ServiceId);
actual.CaseType.IsAudioRecordingAllowed.Should().Be(hearing.ServiceIsAudioRecordingAllowed);
actual.ConferenceSupplier.Should().Be(AdminWebsite.Contracts.Enums.VideoSupplier.Vodafone);
actual.AllocatedToUsername.Should().Be(hearing.AllocatedToUsername);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using AdminWebsite.Mappers;
using BookingsApi.Contract.V2.Responses;

namespace AdminWebsite.UnitTests.Mappers;

public class HearingTypeResponseMapperTests
{
[Test]
public void Should_map_v2()
{
// Arrange
var type = new CaseTypeResponseV2
{
Id = 1,
Name = "Name",
ServiceId = "123",
IsAudioRecordingAllowed = true
};

// Act
var result = type.Map();

// Assert
result.Id.Should().Be(type.Id);
result.Group.Should().Be(type.Name);
result.ServiceId.Should().Be(type.ServiceId);
result.IsAudioRecordingAllowed.Should().Be(type.IsAudioRecordingAllowed);
}
}
12 changes: 6 additions & 6 deletions AdminWebsite/AdminWebsite.UnitTests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,18 @@
},
"BookingsApi.Client": {
"type": "Transitive",
"resolved": "3.1.14",
"contentHash": "j+zkb9f2uRlGWS3Jte2ES43XfBO/r434V8WmcDYm5wBoy5acl26f1bPLbd0mXH/bjd78BDhAu6Oo7LXl5cN2JQ==",
"resolved": "3.1.17",
"contentHash": "cfFV34hEehmJxJBOKEKA1pR0M/uFiO3PxD1nYyAptn2YNEvm/qWJ6MNgBy9pQKMn985t7/8KvJGiM5u2UNREdA==",
"dependencies": {
"BookingsApi.Common.DotNet6": "3.1.14",
"BookingsApi.Common.DotNet6": "3.1.17",
"Microsoft.AspNetCore.Mvc.Core": "2.2.5",
"System.Text.Json": "8.0.5"
}
},
"BookingsApi.Common.DotNet6": {
"type": "Transitive",
"resolved": "3.1.14",
"contentHash": "/N0w8827EwMPO9Suz1R9evG8G8DFPPYOhcUixyqxZDvPkgr4uqjgK7uX41OP2TtADgPBrDVPs66G1DmbKGfWXg==",
"resolved": "3.1.17",
"contentHash": "QoMDKjJjHXXBVUaNvDlaggxaR9aSjgm4BI125rjAYmDkbYVEPlOZqVSDy5z748fX7+xbg2eEwHRD5GE7XNJicA==",
"dependencies": {
"System.Text.Json": "8.0.5"
}
Expand Down Expand Up @@ -2231,7 +2231,7 @@
"type": "Project",
"dependencies": {
"AspNetCore.HealthChecks.Uris": "[8.0.1, )",
"BookingsApi.Client": "[3.1.14, )",
"BookingsApi.Client": "[3.1.17, )",
"FluentValidation.AspNetCore": "[11.3.0, )",
"LaunchDarkly.ServerSdk": "[8.5.0, )",
"MicroElements.Swashbuckle.FluentValidation": "[6.0.0, )",
Expand Down
2 changes: 1 addition & 1 deletion AdminWebsite/AdminWebsite/AdminWebsite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="8.0.1" />
<PackageReference Include="BookingsApi.Client" Version="3.1.14" />
<PackageReference Include="BookingsApi.Client" Version="3.1.17" />
<PackageReference Include="LaunchDarkly.ServerSdk" Version="8.5.0" />
<PackageReference Include="MicroElements.Swashbuckle.FluentValidation" Version="6.0.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.61.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { InterpreterSelectedDto } from '../interpreter-form/interpreter-selected
import { FeatureFlagDirective } from 'src/app/src/app/shared/feature-flag.directive';
import { VHBooking } from 'src/app/common/model/vh-booking';
import { VHParticipant } from 'src/app/common/model/vh-participant';
import { ResponseTestData } from 'src/app/testing/data/response-test-data';

let component: AddParticipantComponent;
let fixture: ComponentFixture<AddParticipantComponent>;
Expand Down Expand Up @@ -178,8 +179,7 @@ function initHearingRequest(): VHBooking {
newHearing.hearingVenueId = -1;
newHearing.scheduledDuration = 0;
newHearing.participants = participants;
newHearing.caseType = 'Test Service';
newHearing.caseTypeServiceId = 'AA1';
newHearing.caseType = ResponseTestData.getCaseTypeModelTestData();
return newHearing;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ <h2 class="govuk-error-summary__title" id="error-summary-title">Please complete
<label class="govuk-label govuk-!-width-one-half" for="caseType">Service</label>
<!--suppress XmlDuplicatedId -->
<select *ngIf="!this.editMode" class="govuk-select govuk-!-width-one-half" id="caseType" formControlName="caseType">
<option *ngFor="let availableCaseType of availableCaseTypes" [ngValue]="availableCaseType">
{{ availableCaseType }}
<option *ngFor="let caseType of selectableCaseTypes" [ngValue]="caseType">
{{ caseType }}
</option>
</select>
<!--suppress XmlDuplicatedId -->
<input
*ngIf="this.editMode"
id="caseType"
[placeholder]="this.hearing.caseType"
[placeholder]="this.hearing.caseType.name"
class="govuk-input govuk-!-width-one-half"
type="text"
formControlName="caseType"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { ReferenceDataService } from 'src/app/services/reference-data.service';
import { VHBooking } from 'src/app/common/model/vh-booking';
import { VHParticipant } from 'src/app/common/model/vh-participant';
import { HearingRoles } from 'src/app/common/model/hearing-roles.model';
import { ResponseTestData } from 'src/app/testing/data/response-test-data';
import { PageUrls } from 'src/app/shared/page-url.constants';

function initHearingRequest(): VHBooking {
const newHearing = new VHBooking();
Expand All @@ -36,7 +38,7 @@ function initHearingRequest(): VHBooking {
function initExistingHearingRequest(): VHBooking {
const existingRequest = new VHBooking();
existingRequest.hearingVenueId = 1;
existingRequest.caseType = 'Generic';
existingRequest.caseType = ResponseTestData.getCaseTypeModelTestData();

return existingRequest;
}
Expand Down Expand Up @@ -154,6 +156,26 @@ describe('CreateHearingComponent with multiple Services', () => {
expect(caseTypeControl.valid).toBeTruthy();
});

describe('saveHearingDetails when form is valid and fully populated', () => {
beforeEach(() => {
caseNumberControl.setValue('12345');
caseNameControl.setValue('Case Name');
caseTypeControl.setValue('Tax');
});

it('should navigate to summary when in edit mode', () => {
component.editMode = true;
component.saveHearingDetails();
expect(routerSpy.navigate).toHaveBeenCalledWith([PageUrls.Summary]);
});

it('should navigate to hearing schedule when not in edit mode', () => {
component.editMode = false;
component.saveHearingDetails();
expect(routerSpy.navigate).toHaveBeenCalledWith([PageUrls.HearingSchedule]);
});
});

describe('supplier overrides', () => {
beforeEach(() => {
launchDarklyServiceSpy.getFlag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { takeUntil } from 'rxjs/operators';
import { combineLatest, Subject } from 'rxjs';
import { ServiceIds } from '../models/supplier-override';
import { ReferenceDataService } from 'src/app/services/reference-data.service';
import { CaseTypeModel } from 'src/app/common/model/case-type.model';

@Component({
selector: 'app-create-hearing',
Expand All @@ -29,7 +30,7 @@ export class CreateHearingComponent extends BookingBaseComponent implements OnIn
failedSubmission: boolean;
hearing: VHBooking;
availableHearingTypes: HearingTypeResponse[];
availableCaseTypes: string[];
availableCaseTypes: CaseTypeModel[];
selectedCaseType: string;
selectedCaseTypeServiceId: string;
hasSaved: boolean;
Expand Down Expand Up @@ -100,21 +101,10 @@ export class CreateHearingComponent extends BookingBaseComponent implements OnIn
this.isExistingHearing = this.hearing?.hearingId && this.hearing?.hearingId?.length > 0;
this.logger.debug(`${this.loggerPrefix} Checking for existing hearing.`);

this.selectedCaseType = this.hearing.caseType;
this.selectedCaseTypeServiceId = this.hearing.caseTypeServiceId;
this.selectedCaseType = this.hearing.caseType?.name;
this.selectedCaseTypeServiceId = this.hearing.caseType?.serviceId;
if (this.hearing.caseType) {
this.selectedCaseType = this.hearing.caseType;
return;
} else {
this.selectedCaseType = Constants.PleaseSelect;
}

if (this.hearing.caseType) {
this.selectedCaseType = this.hearing.caseType;
this.logger.debug(`${this.loggerPrefix} Updating selected Service to current hearing Service.`, {
hearing: this.hearing.hearingId
});
this.hasSaved = true;
this.selectedCaseType = this.hearing.caseType.name;
} else {
this.selectedCaseType = Constants.PleaseSelect;
}
Expand Down Expand Up @@ -187,6 +177,10 @@ export class CreateHearingComponent extends BookingBaseComponent implements OnIn
return true;
}

get selectableCaseTypes(): string[] {
return this.availableCaseTypes.map(c => c.name);
}

isFirstDayOfMultiDay(): boolean {
const firstDay = this.hearing.hearingsInGroup[0];
const isFirstDay = this.hearing.hearingId === firstDay.hearingId;
Expand Down Expand Up @@ -244,13 +238,13 @@ export class CreateHearingComponent extends BookingBaseComponent implements OnIn
}

private updateHearingRequest() {
this.hearing.caseType = this.selectedCaseType;
this.hearing.caseType = this.availableCaseTypes.find(c => c.name === this.selectedCaseType);
const hearingCase = new CaseModel();
hearingCase.name = this.form.value.caseName;
hearingCase.number = this.form.value.caseNumber;
this.hearing.case = hearingCase;
this.hearing.caseTypeId = this.isExistingHearing ? this.hearing.caseTypeId : this.form.getRawValue().caseType;
this.hearing.caseTypeServiceId = this.selectedCaseTypeServiceId;
this.hearing.caseType.name = this.isExistingHearing ? this.hearing.caseType.name : this.form.getRawValue().caseType;
this.hearing.caseType.serviceId = this.selectedCaseTypeServiceId;
this.hearing.supplier = this.form.getRawValue().supplier ?? this.retrieveDefaultSupplier();
this.hearingService.updateHearingRequest(this.hearing);
this.logger.debug(`${this.loggerPrefix} Updated hearing request details`, { hearing: this.hearing });
Expand Down Expand Up @@ -286,16 +280,26 @@ export class CreateHearingComponent extends BookingBaseComponent implements OnIn
this.availableHearingTypes = hearingTypes;
this.availableHearingTypes.sort(this.dynamicSort('name'));
this.availableCaseTypes = this.availableHearingTypes
.map(h => h.group)
.map(
h =>
new CaseTypeModel({
name: h.group,
isAudioRecordingAllowed: h.is_audio_recording_allowed
})
)
.filter((value, index, self) => self.indexOf(value) === index)
.sort((a, b) => a.localeCompare(b));
.sort((a, b) => a.name.localeCompare(b.name));

if (this.availableCaseTypes.length === 1) {
this.selectedCaseType = this.availableCaseTypes[0];
this.selectedCaseType = this.availableCaseTypes[0].name;
this.form.get('caseType').setValue(this.selectedCaseType);
this.logger.debug(`${this.loggerPrefix} Only one available Service. Setting Service`);
} else {
this.availableCaseTypes.unshift(Constants.PleaseSelect);
this.availableCaseTypes.unshift(
new CaseTypeModel({
name: Constants.PleaseSelect
})
);
}
this.displaySupplierOverrideIfSupported();
}
Expand Down
Loading

0 comments on commit 53e65e7

Please sign in to comment.