public IActionResult DeleteSubmission(string submissionId, [FromBody] DeleteCaseSubmissionRequest request) { var validator = new DeleteCaseSubmissionRequestValidator(); var validatioResults = validator.Validate(request); if (!validatioResults.IsValid) { return(BadRequest(validatioResults.ToString())); } try { _formSubmissionsUseCase.ExecuteDelete(submissionId, request); } catch (WorkerNotFoundException e) { return(UnprocessableEntity(e.Message)); } catch (DeleteSubmissionException e) { return(UnprocessableEntity(e.Message)); } catch (SubmissionAlreadyDeletedException e) { return(StatusCode(StatusCodes.Status410Gone, e.Message)); } return(NoContent()); }
public void ValidUpdateCaseSubmissionReturnsNoErrorsOnValidation() { var deleteCaseSubmissionRequest = TestHelpers.DeleteCaseSubmissionRequest(); var validator = new DeleteCaseSubmissionRequestValidator(); var validationResponse = validator.Validate(deleteCaseSubmissionRequest); validationResponse.IsValid.Should().Be(true); }
public void DeleteCaseSubmissionRequestValidationReturnsErrorWithMessageWhenDeletedByEmailIsNull() { var updateRequestWithoutDeletedByEmail = TestHelpers.DeleteCaseSubmissionRequest(); updateRequestWithoutDeletedByEmail.DeletedBy = null; var validator = new DeleteCaseSubmissionRequestValidator(); var validationResponse = validator.Validate(updateRequestWithoutDeletedByEmail); validationResponse.IsValid.Should().Be(false); validationResponse.Errors.Any(x => x.ErrorMessage.Contains("Provide who is deleting the submission")).Should().BeTrue(); }
public void DeleteCaseSubmissionRequestValidationReturnsErrorsWithInvalidProperties() { var badDeleteCaseSubmissionRequest = new List <(DeleteCaseSubmissionRequest, string)> { (TestHelpers.DeleteCaseSubmissionRequest(deletedBy: "invalid email"), "Provide a valid email address for who is deleting the submission"), (TestHelpers.DeleteCaseSubmissionRequest(deleteRequestedBy: " "), "Provide valid delete requested by name"), (TestHelpers.DeleteCaseSubmissionRequest(deletedReason: " "), "Provide valid delete reason"), }; var validator = new DeleteCaseSubmissionRequestValidator(); foreach (var(request, expectedErrorMessage) in badDeleteCaseSubmissionRequest) { var validationResponse = validator.Validate(request); validationResponse.IsValid.Should().Be(false); validationResponse.ToString().Should().Be(expectedErrorMessage); } }