Skip to content

Commit

Permalink
VIH-5185: Complete validation
Browse files Browse the repository at this point in the history
  • Loading branch information
rehmanab committed Nov 10, 2019
1 parent 6151c52 commit 6cd5f22
Show file tree
Hide file tree
Showing 5 changed files with 401 additions and 7 deletions.
9 changes: 7 additions & 2 deletions AdminWebsite/AdminWebsite/Controllers/HearingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using AdminWebsite.Security;
using AdminWebsite.Services;
using AdminWebsite.Validators;
using FluentValidation;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;

Expand All @@ -25,15 +26,18 @@ public class HearingsController : ControllerBase
private readonly IBookingsApiClient _bookingsApiClient;
private readonly IUserIdentity _userIdentity;
private readonly IUserAccountService _userAccountService;
private readonly AbstractValidator<BookNewHearingRequest> _bookNewHearingRequestValidator;

/// <summary>
/// Instantiates the controller
/// </summary>
public HearingsController(IBookingsApiClient bookingsApiClient, IUserIdentity userIdentity, IUserAccountService userAccountService)
public HearingsController(IBookingsApiClient bookingsApiClient, IUserIdentity userIdentity, IUserAccountService userAccountService,
AbstractValidator<BookNewHearingRequest> bookNewHearingRequestValidator)
{
_bookingsApiClient = bookingsApiClient;
_userIdentity = userIdentity;
_userAccountService = userAccountService;
_bookNewHearingRequestValidator = bookNewHearingRequestValidator;
}

/// <summary>
Expand All @@ -47,7 +51,8 @@ public HearingsController(IBookingsApiClient bookingsApiClient, IUserIdentity us
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
public async Task<ActionResult<HearingDetailsResponse>> Post([FromBody] BookNewHearingRequest request)
{
var result = new BookNewHearingRequestValidator().Validate(request);
var result = _bookNewHearingRequestValidator.Validate(request);

if (!result.IsValid)
{
ModelState.AddFluentValidationErrors(result.Errors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using AdminWebsite.Services;
using AdminWebsite.Swagger;
using AdminWebsite.UserAPI.Client;
using AdminWebsite.Validators;
using FluentValidation;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -79,7 +81,9 @@ public static IServiceCollection AddCustomTypes(this IServiceCollection serviceC

return new UserIdentity(userPrincipal);
});


serviceCollection.AddSingleton<AbstractValidator<BookNewHearingRequest>, BookNewHearingRequestValidator>();

return serviceCollection;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ namespace AdminWebsite.Validators
public class ParticipantRequestValidation : AbstractValidator<ParticipantRequest>
{
public static readonly string ContactEmailMessage = "Email is required in the correct format and between 1 - 255 characters";
public static readonly string DisplayNameMessage = "Display name is required and between 1 - 255 characters";
public static readonly string FirstNameMessage = "First name is required and between 1 - 255 characters";
public static readonly string LastNameMessage = "Lastname is required and between 1 - 255 characters";

public ParticipantRequestValidation()
{
RuleFor(x => x.Contact_email).NotEmpty().EmailAddress().MaximumLength(255).WithMessage(ContactEmailMessage);
RuleFor(x => x.Display_name).NotEmpty().MaximumLength(255).WithMessage(DisplayNameMessage);
RuleFor(x => x.First_name).NotEmpty().MaximumLength(255).WithMessage(FirstNameMessage);
RuleFor(x => x.Last_name).NotEmpty().MaximumLength(255).WithMessage(LastNameMessage);
}
}
}
135 changes: 131 additions & 4 deletions postman/Admin Web.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@
"pm.globals.set(\"doNotSendQuestionnaire\", \"True\");",
"pm.globals.set(\"scheduledDateTime\", \"2020-08-18 20:10:38\");",
"pm.globals.set(\"hearingRoomName\", \"Room 6.41C\");",
"pm.globals.set(\"judgeName\", \"Birmingham Courtroom115\");",
"pm.globals.set(\"judgeDisplayName\", \"Birmingham Courtroom115\");",
"pm.globals.set(\"emailJudge\", \"[email protected]\");",
"pm.globals.set(\"emailParticipant1\", \"[email protected]\");",
"pm.globals.set(\"emailParticipant2\", \"[email protected]\");"
"pm.globals.set(\"emailParticipant2\", \"[email protected]\");",
"pm.globals.set(\"firstname\", \"my first name\");",
"pm.globals.set(\"lastname\", \"my last name\");",
"pm.globals.set(\"displayname\", \"my display name\");",
"pm.globals.set(\"hearingDuration\", 60);",
"pm.globals.set(\"hearingVenueName\", \"Birmingham Civil and Family Justice Centre\");"
],
"type": "text/javascript"
}
Expand Down Expand Up @@ -124,7 +129,127 @@
],
"body": {
"mode": "raw",
"raw": "{\n \"scheduled_date_time\": \"{{scheduledDateTime}}\",\n \"scheduled_duration\": 45,\n \"hearing_venue_name\": \"Birmingham Civil and Family Justice Centre\",\n \"case_type_name\": \"{{caseType}}\",\n \"hearing_type_name\": \"{{hearingType}}\",\n \"cases\": [\n {\n \"number\": \"{{caseNumber}}\",\n \"name\": \"{{caseName}}\",\n \"is_lead_case\": false\n }\n ],\n \"participants\": [\n {\n \"title\": \"Judge\",\n \"first_name\": \"Birmingham\",\n \"middle_names\": \"\",\n \"last_name\": \"Courtroom115\",\n \"contact_email\": \"{{emailJudge}}\",\n \"telephone_number\": \"\",\n \"username\":\"{{emailJudge}}\",\n \"display_name\": \"{{judgeName}}\",\n \"case_role_name\": \"Judge\",\n \"hearing_role_name\": \"Judge\",\n \"house_number\": null,\n \"street\": null,\n \"postcode\": null,\n \"city\": null,\n \"county\": null\n },\n {\n \"title\": \"Mr\",\n \"first_name\": \"Atif\",\n \"last_name\": \"Representative\",\n \"contact_email\": \"{{emailParticipant1}}\",\n \"telephone_number\": \"0739053837\",\n \"username\": \"{{emailParticipant1}}\",\n \"display_name\": \"Atif Rep\",\n \"case_role_name\": \"Claimant\",\n \"hearing_role_name\": \"Claimant LIP\",\n \"solicitors_reference\": \"\",\n \"representee\": \"\",\n \"organisation_name\": \"MyCompany\",\n \"house_number\": \"123\",\n \"street\": \"London Road\",\n \"postcode\": \"SW1 1WS\",\n \"city\": \"London\",\n \"county\": \"London\"\n },\n {\n \"title\": \"Mr\",\n \"first_name\": \"Atif\",\n \"last_name\": \"Individual\",\n \"contact_email\":\"{{emailParticipant2}}\",\n \"telephone_number\": \"0739053837\",\n \"username\": \"{{emailParticipant2}}\",\n \"display_name\": \"Atif Indv\",\n \"case_role_name\": \"Defendant\",\n \"hearing_role_name\": \"Defendant LIP\",\n \"solicitors_reference\": \"\",\n \"representee\": \"\",\n \"organisation_name\": \"\",\n \"house_number\": \"123\",\n \"street\": \"Oseney Court\",\n \"postcode\": \"NW5 2BA\",\n \"city\": \"London\",\n \"county\": \"Greater London\"\n }\n ],\n \"hearing_room_name\": \"{{hearingRoomName}}\",\n \"other_information\": \"test1\",\n \"questionnaire_not_required\": \"{{doNotSendQuestionnaire}}\"\n}"
"raw": "{\n \"scheduled_date_time\": \"{{scheduledDateTime}}\",\n \"scheduled_duration\": \"{{hearingDuration}}\",\n \"hearing_venue_name\": \"Birmingham Civil and Family Justice Centre\",\n \"case_type_name\": \"{{caseType}}\",\n \"hearing_type_name\": \"{{hearingType}}\",\n \"cases\": [\n {\n \"number\": \"{{caseNumber}}\",\n \"name\": \"qwglkdrbg5732057037&^$\\u00A3*(){}><>?_++_` -+\\/*-+*{}[]#'\\/.,`!\\\"\\\"\\u00A3$%^&*()1##ss\",\n \"is_lead_case\": false\n }\n ],\n \"participants\": [\n {\n \"title\": \"Judge\",\n \"first_name\": \"{{firstname}}\",\n \"middle_names\": \"\",\n \"last_name\": \"{{lastname}}\",\n \"contact_email\": \"{{emailJudge}}\",\n \"telephone_number\": \"\",\n \"username\":\"{{emailJudge}}\",\n \"display_name\": \"{{judgeDisplayName}}\",\n \"case_role_name\": \"Judge\",\n \"hearing_role_name\": \"Judge\",\n \"house_number\": null,\n \"street\": null,\n \"postcode\": null,\n \"city\": null,\n \"county\": null\n },\n {\n \"title\": \"Mr\",\n \"first_name\": \"{{firstname}}\",\n \"last_name\": \"{{lastname}}\",\n \"contact_email\": \"{{emailParticipant1}}\",\n \"telephone_number\": \"0739053837\",\n \"username\": \"{{emailParticipant1}}\",\n \"display_name\": \"{{displayname}}\",\n \"case_role_name\": \"Claimant\",\n \"hearing_role_name\": \"Claimant LIP\",\n \"solicitors_reference\": \"\",\n \"representee\": \"\",\n \"organisation_name\": \"MyCompany\",\n \"house_number\": \"123\",\n \"street\": \"London Road\",\n \"postcode\": \"SW1 1WS\",\n \"city\": \"London\",\n \"county\": \"London\"\n },\n {\n \"title\": \"Mr\",\n \"first_name\": \"{{firstname}}\",\n \"last_name\": \"{{lastname}}\",\n \"contact_email\":\"{{emailParticipant2}}\",\n \"telephone_number\": \"0739053837\",\n \"username\": \"{{emailParticipant2}}\",\n \"display_name\": \"{{displayname}}\",\n \"case_role_name\": \"Defendant\",\n \"hearing_role_name\": \"Defendant LIP\",\n \"solicitors_reference\": \"\",\n \"representee\": \"\",\n \"organisation_name\": \"\",\n \"house_number\": \"123\",\n \"street\": \"Oseney Court\",\n \"postcode\": \"NW5 2BA\",\n \"city\": \"London\",\n \"county\": \"Greater London\"\n }\n ],\n \"hearing_room_name\": \"{{hearingRoomName}}\",\n \"other_information\": \"test1\",\n \"questionnaire_not_required\": \"{{doNotSendQuestionnaire}}\"\n}"
},
"url": {
"raw": "{{Endpoint}}/api/hearings/",
"host": [
"{{Endpoint}}"
],
"path": [
"api",
"hearings",
""
]
}
},
"response": []
},
{
"name": "Create Hearings Bad Request",
"event": [
{
"listen": "prerequest",
"script": {
"id": "a974c530-7182-4306-a083-5816a052f5e5",
"exec": [
"console.log('Have you set the bearer token in the folder pre-request scripts?');"
],
"type": "text/javascript"
}
},
{
"listen": "test",
"script": {
"id": "270139f2-27ca-47e9-8c51-63a8f5720502",
"exec": [
"pm.test(\"POST request should fail with 400 Bad Request\", function () {",
" pm.expect(pm.response.code).to.be.oneOf([400]);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{bearerToken}}",
"type": "string"
}
]
},
"method": "POST",
"header": [
{
"key": "Connection",
"value": "keep-alive"
},
{
"key": "Pragma",
"value": "no-cache"
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"key": "Origin",
"value": "https://localhost:5400"
},
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
},
{
"key": "User-Agent",
"value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36"
},
{
"key": "Request-Id",
"value": "|Yilo6.WU4SY"
},
{
"key": "DNT",
"value": "1"
},
{
"key": "Request-Context",
"value": "appId=cid-v1:11da21f3-e3c7-4b8c-88bc-9249f4cbeb10"
},
{
"key": "Sec-Fetch-Site",
"value": "same-origin"
},
{
"key": "Sec-Fetch-Mode",
"value": "cors"
},
{
"key": "Accept-Encoding",
"value": "gzip, deflate, br"
},
{
"key": "Accept-Language",
"value": "en-GB,en-US;q=0.9,en;q=0.8"
},
{
"key": "Cookie",
"value": "ai_user=uldnG|2019-11-04T13:13:46.916Z; ai_session=n8caC|1572873233293.36|1572873425692.385"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"scheduled_date_time\": \"{{scheduledDateTime}}\",\n \"scheduled_duration\": \"{{hearingDuration}}\",\n \"hearing_venue_name\": \"Birmingham Civil and Family Justice Centre\",\n \"case_type_name\": \"{{caseType}}\",\n \"hearing_type_name\": \"{{hearingType}}\",\n \"cases\": [\n {\n \"number\": \"{{caseNumber}}\",\n \"name\": \"{{caseName}}\",\n \"is_lead_case\": false\n }\n ],\n \"participants\": [\n {\n \"title\": \"Judge\",\n \"first_name\": \"{{firstname}}\",\n \"middle_names\": \"\",\n \"last_name\": \"{{lastname}}\",\n \"contact_email\": \"{{emailJudge}}\",\n \"telephone_number\": \"\",\n \"username\":\"{{emailJudge}}\",\n \"display_name\": \"{{judgeDisplayName}}\",\n \"case_role_name\": \"Judge\",\n \"hearing_role_name\": \"Judge\",\n \"house_number\": null,\n \"street\": null,\n \"postcode\": null,\n \"city\": null,\n \"county\": null\n },\n {\n \"title\": \"Mr\",\n \"first_name\": \"{{firstname}}\",\n \"last_name\": \"{{lastname}}\",\n \"contact_email\": \"{{emailParticipant1}}\",\n \"telephone_number\": \"0739053837\",\n \"username\": \"{{emailParticipant1}}\",\n \"display_name\": \"{{displayname}}\",\n \"case_role_name\": \"Claimant\",\n \"hearing_role_name\": \"Claimant LIP\",\n \"solicitors_reference\": \"\",\n \"representee\": \"\",\n \"organisation_name\": \"MyCompany\",\n \"house_number\": \"123\",\n \"street\": \"London Road\",\n \"postcode\": \"SW1 1WS\",\n \"city\": \"London\",\n \"county\": \"London\"\n },\n {\n \"title\": \"Mr\",\n \"first_name\": \"{{firstname}}\",\n \"last_name\": \"{{lastname}}\",\n \"contact_email\":\"{{emailParticipant2}}\",\n \"telephone_number\": \"0739053837\",\n \"username\": \"{{emailParticipant2}}\",\n \"display_name\": \"{{displayname}}\",\n \"case_role_name\": \"Defendant\",\n \"hearing_role_name\": \"Defendant LIP\",\n \"solicitors_reference\": \"\",\n \"representee\": \"\",\n \"organisation_name\": \"\",\n \"house_number\": \"123\",\n \"street\": \"Oseney Court\",\n \"postcode\": \"NW5 2BA\",\n \"city\": \"London\",\n \"county\": \"Greater London\"\n }\n ],\n \"hearing_room_name\": \"{{hearingRoomName}}\",\n \"other_information\": \"test1\",\n \"questionnaire_not_required\": \"{{doNotSendQuestionnaire}}\"\n}"
},
"url": {
"raw": "{{Endpoint}}/api/hearings/",
Expand All @@ -148,7 +273,9 @@
"id": "9a50a0ca-e0b6-4c33-9d75-b37d0613621f",
"type": "text/javascript",
"exec": [
"pm.environment.set(\"bearerToken\",'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IkJCOENlRlZxeWFHckdOdWVoSklpTDRkZmp6dyIsImtpZCI6IkJCOENlRlZxeWFHckdOdWVoSklpTDRkZmp6dyJ9.eyJhdWQiOiJkODNmODMzNi0zZDU5LTQ5YjYtOGUyYy1lZmNkYzZlY2Q0ZjMiLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC9mYjZlMGUyMi0wZGEzLTRjMzU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