Example #1
0
        public async Task <ModeratorOutcomeReviewViewModel> GetInModerationOutcomeReviewViewModel(ReviewModeratorOutcomeRequest request)
        {
            var viewModel = new ModeratorOutcomeReviewViewModel
            {
                Status = request.Status, ReviewComment = request.ReviewComment, ApplicationId = request.ApplicationId
            };

            var application = await _applicationApiClient.GetApplication(request.ApplicationId);

            var contact = await _applicationApiClient.GetContactForApplication(request.ApplicationId);

            if (application is null || contact is null)
            {
                return(null);
            }

            viewModel.ApplicantEmailAddress = contact.Email;

            if (application.ApplyData?.ApplyDetails != null)
            {
                viewModel.ApplicationRoute = application.ApplyData.ApplyDetails.ProviderRouteName;
                viewModel.Ukprn            = application.ApplyData.ApplyDetails.UKPRN;
                viewModel.ApplyLegalName   = application.ApplyData.ApplyDetails.OrganisationName;
                viewModel.SubmittedDate    = application.ApplyData.ApplyDetails.ApplicationSubmittedOn;
            }

            return(viewModel);
        }
        public void SetUp()
        {
            _applicationApiClient = new Mock <IRoatpApplicationApiClient>();
            _moderationApiClient  = new Mock <IRoatpModerationApiClient>();
            _orchestrator         = new Web.Services.ModeratorOutcomeOrchestrator(_applicationApiClient.Object, _moderationApiClient.Object);
            _application          = new Apply
            {
                ApplicationId         = _applicationId,
                ModerationStatus      = ModerationStatus.New,
                Assessor1ReviewStatus = AssessorReviewStatus.Approved,
                Assessor1UserId       = _userId,
                Assessor1Name         = _userDisplayName,
                Assessor2ReviewStatus = AssessorReviewStatus.Approved,
                Assessor2UserId       = $"{ _userId }-2",
                Assessor2Name         = $"{ _userDisplayName }-2",
                ApplyData             = new ApplyData
                {
                    ApplyDetails = new ApplyDetails
                    {
                        ProviderRouteName      = ApplicationRouteName,
                        UKPRN                  = Ukprn,
                        OrganisationName       = OrganisationName,
                        ApplicationSubmittedOn = ApplicationSubmittedOn
                    }
                }
            };

            _outcomes = new List <ModeratorPageReviewOutcome>();
            _contact  = new Contact {
                Email = Email
            };
            _request = new ReviewModeratorOutcomeRequest(_applicationId, _userId, Status, ReviewComment);
            _applicationApiClient.Setup(x => x.GetApplication(_applicationId)).ReturnsAsync(_application);
            _applicationApiClient.Setup(x => x.GetContactForApplication(_applicationId)).ReturnsAsync(_contact);

            _expectedViewModel = new ModeratorOutcomeReviewViewModel
            {
                ApplicationId         = _applicationId,
                Status                = Status,
                ApplicantEmailAddress = Email,
                Ukprn            = Ukprn,
                ReviewComment    = ReviewComment,
                ApplyLegalName   = OrganisationName,
                ApplicationRoute = ApplicationRouteName,
                SubmittedDate    = ApplicationSubmittedOn
            };
        }
        public async Task ReviewOutcome_goes_to_are_you_sure_when_no_error()
        {
            var command = new SubmitModeratorOutcomeCommand();

            _mockValidator.Setup(x => x.Validate(command))
            .ReturnsAsync(new ValidationResponse
            {
                Errors = new List <ValidationErrorDetail>()
            }
                          );

            var outcomeReviewViewModel = new ModeratorOutcomeReviewViewModel();

            _mockOrchestrator
            .Setup(x => x.GetInModerationOutcomeReviewViewModel(It.IsAny <ReviewModeratorOutcomeRequest>()))
            .ReturnsAsync(outcomeReviewViewModel);
            var result = await _controller.SubmitModeratorOutcome(_applicationId, command) as ViewResult;

            Assert.That(result.Model, Is.SameAs(outcomeReviewViewModel));
            _mockOrchestrator.Verify(x => x.GetInModerationOutcomeReviewViewModel(It.IsAny <ReviewModeratorOutcomeRequest>()), Times.Once);
        }
        public async Task Outcome_confirmation_directs_to_saved_page_when_save_is_successful()
        {
            var command = new SubmitModeratorOutcomeConfirmationCommand(string.Empty, "Yes");

            _mockValidator.Setup(x => x.Validate(command))
            .ReturnsAsync(new ValidationResponse()
                          );

            _mockModerationApiClient.Setup(x => x.SubmitModerationOutcome(_applicationId, It.IsAny <string>(),
                                                                          It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(true);

            var outcomeReviewViewModel = new ModeratorOutcomeReviewViewModel();

            _mockOrchestrator.Setup(x => x.GetInModerationOutcomeReviewViewModel(It.IsAny <ReviewModeratorOutcomeRequest>()))
            .ReturnsAsync(outcomeReviewViewModel);

            var result = await _controller.SubmitModeratorOutcomeConfirmation(_applicationId, string.Empty, command) as ViewResult;

            Assert.That(result.Model, Is.SameAs(outcomeReviewViewModel));
            _mockOrchestrator.Verify(x => x.GetInModerationOutcomeReviewViewModel(It.IsAny <ReviewModeratorOutcomeRequest>()), Times.Once);
        }