Skip to content

Commit

Permalink
fix code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaed Parkar committed Oct 10, 2023
1 parent 94cd5e8 commit 6edcdc0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ import { ParticipantModel } from '../../common/model/participant.model';
import { RemovePopupComponent } from '../../popups/remove-popup/remove-popup.component';
import { WaitPopupComponent } from '../../popups/wait-popup/wait-popup.component';
import { BookingService } from '../../services/booking.service';
import { BookingStatus, HearingDetailsResponse, UpdateBookingStatusResponse } from '../../services/clients/api-client';
import {
BookHearingException,
BookingStatus,
HearingDetailsResponse,
UpdateBookingStatusResponse,
ValidationProblemDetails
} from '../../services/clients/api-client';
import { Logger } from '../../services/logger';
import { RecordingGuardService } from '../../services/recording-guard.service';
import { VideoHearingsService } from '../../services/video-hearings.service';
Expand Down Expand Up @@ -577,7 +583,21 @@ describe('SummaryComponent with invalid request', () => {
const existingRequest = initBadHearingRequest();
videoHearingsServiceSpy.getCurrentRequest.and.returnValue(existingRequest);
videoHearingsServiceSpy.getHearingTypes.and.returnValue(of(MockValues.HearingTypesList));
videoHearingsServiceSpy.saveHearing.and.throwError('Fake error');

const validationProblem = new ValidationProblemDetails({
errors: {
FirstName: ['First name is required'],
LastName: ['Last Name is required'],
ContactEmail: ['Contact Email is required']
},
type: 'https://tools.ietf.org/html/rfc7231#section-6.5.1',
title: 'One or more validation errors occurred.',
status: 400
});

videoHearingsServiceSpy.saveHearing.and.throwError(
new BookHearingException('Bad Request', 400, 'One or more validation errors occurred.', null, validationProblem)
);

TestBed.configureTestingModule({
providers: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ describe('JusticeUserFormComponent', () => {
});

justiceUsersServiceSpy.addNewJusticeUser.and.returnValue(
throwError(new BookHearingException('Bad Request', 400, 'One or more validation errors occurred.', null, validationProblem))
throwError(
() => new BookHearingException('Bad Request', 400, 'One or more validation errors occurred.', null, validationProblem)
)
);

// act
Expand Down
8 changes: 1 addition & 7 deletions AdminWebsite/AdminWebsite/Controllers/HearingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public async Task<ActionResult<HearingDetailsResponse>> EditHearing(Guid hearing
{
_logger.LogWarning("No hearing id found to edit");
ModelState.AddModelError(nameof(hearingId), $"Please provide a valid {nameof(hearingId)}");
return BadRequest(ModelState);
return ValidationProblem(ModelState);
}

_logger.LogDebug("Attempting to edit hearing {Hearing}", hearingId);
Expand All @@ -276,12 +276,6 @@ public async Task<ActionResult<HearingDetailsResponse>> EditHearing(Guid hearing
}
catch (BookingsApiException e)
{
if (e.StatusCode is (int)HttpStatusCode.BadRequest)
{
var typedException = e as BookingsApiException<ValidationProblemDetails>;
return ValidationProblem(typedException!.Result);
}

_logger.LogError(e, "Failed to get hearing {Hearing}. Status Code {StatusCode} - Message {Message}",
hearingId, e.StatusCode, e.Response);
if (e.StatusCode != (int)HttpStatusCode.NotFound) throw;
Expand Down

0 comments on commit 6edcdc0

Please sign in to comment.