From fcaadceb8dbe4deaaf75bbc06a4b03d7b6a1451f Mon Sep 17 00:00:00 2001 From: ccatosdevelopment <110388345+ccatosdevelopment@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:00:26 +0000 Subject: [PATCH] PSR-1630 | Implement Loans check and update page --- .../LoansCheckAndUpdateController.scala | 117 ++++++++++++++++++ conf/app.routes | 3 + conf/messages.en | 11 ++ .../LoansCheckAndUpdateControllerSpec.scala | 77 ++++++++++++ 4 files changed, 208 insertions(+) create mode 100644 app/controllers/nonsipp/loansmadeoroutstanding/LoansCheckAndUpdateController.scala create mode 100644 test/controllers/nonsipp/loansmadeoroutstanding/LoansCheckAndUpdateControllerSpec.scala diff --git a/app/controllers/nonsipp/loansmadeoroutstanding/LoansCheckAndUpdateController.scala b/app/controllers/nonsipp/loansmadeoroutstanding/LoansCheckAndUpdateController.scala new file mode 100644 index 000000000..91b010f03 --- /dev/null +++ b/app/controllers/nonsipp/loansmadeoroutstanding/LoansCheckAndUpdateController.scala @@ -0,0 +1,117 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package controllers.nonsipp.loansmadeoroutstanding + +import viewmodels.implicits._ +import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} +import com.google.inject.Inject +import controllers.nonsipp.loansmadeoroutstanding.LoansCheckAndUpdateController._ +import cats.implicits.toShow +import controllers.actions.IdentifyAndRequireData +import pages.nonsipp.common.OtherRecipientDetailsPage +import pages.nonsipp.loansmadeoroutstanding._ +import config.RefinedTypes.Max5000 +import controllers.PSRController +import views.html.ContentTablePageView +import models.SchemeId.Srn +import utils.DateTimeUtils.localDateShow +import models.{IdentitySubject, Money, NormalMode} +import play.api.i18n.MessagesApi +import viewmodels.DisplayMessage +import viewmodels.DisplayMessage.{ListMessage, Message, ParagraphMessage} +import viewmodels.models.{ContentTablePageViewModel, FormPageViewModel} + +import java.time.LocalDate + +class LoansCheckAndUpdateController @Inject()( + override val messagesApi: MessagesApi, + identifyAndRequireData: IdentifyAndRequireData, + val controllerComponents: MessagesControllerComponents, + view: ContentTablePageView +) extends PSRController { + + def onPageLoad(srn: Srn, index: Max5000): Action[AnyContent] = identifyAndRequireData(srn) { implicit request => + ( + for { + recipientName <- List( + request.userAnswers.get(IndividualRecipientNamePage(srn, index)), + request.userAnswers.get(CompanyRecipientNamePage(srn, index)), + request.userAnswers.get(PartnershipRecipientNamePage(srn, index)), + request.userAnswers.get(OtherRecipientDetailsPage(srn, index, IdentitySubject.LoanRecipient)).map(_.name) + ).flatten.headOption.getOrRecoverJourney + datePeriodDetails <- request.userAnswers.get(DatePeriodLoanPage(srn, index)).getOrRecoverJourney + amountOfTheLoan <- request.userAnswers.get(AmountOfTheLoanPage(srn, index)).getOrRecoverJourney + } yield Ok( + view( + viewModel( + srn, + index, + recipientName, + datePeriodDetails._1, + amountOfTheLoan.loanAmount + ) + ) + ) + ).merge + } + + def onSubmit(srn: Srn, index: Max5000): Action[AnyContent] = identifyAndRequireData(srn) { _ => + Redirect(routes.AmountOfTheLoanController.onPageLoad(srn, index, NormalMode)) + } +} + +object LoansCheckAndUpdateController { + + def viewModel( + srn: Srn, + index: Max5000, + recipientName: String, + dateOfTheLoan: LocalDate, + amountOfTheLoan: Money + ): FormPageViewModel[ContentTablePageViewModel] = { + + val rows: List[(DisplayMessage, DisplayMessage)] = List( + Message("loansCheckAndUpdate.table.one") -> Message(recipientName), + Message("loansCheckAndUpdate.table.two") -> Message(dateOfTheLoan.show), + Message("loansCheckAndUpdate.table.three") -> Message(amountOfTheLoan.displayAs) + ) + + FormPageViewModel( + mode = NormalMode, + title = "loansCheckAndUpdate.title", + heading = "loansCheckAndUpdate.heading", + description = None, + page = ContentTablePageViewModel( + inset = None, + beforeTable = Some(ParagraphMessage("loansCheckAndUpdate.paragraph")), + afterTable = Some( + ParagraphMessage("loansCheckAndUpdate.bullet.paragraph") ++ ListMessage + .Bullet( + "loansCheckAndUpdate.bullet.one", + "loansCheckAndUpdate.bullet.two" + ) + ), + rows = rows + ), + refresh = None, + buttonText = "loansCheckAndUpdate.button", + details = None, + onSubmit = routes.LoansCheckAndUpdateController.onSubmit(srn, index), + optViewOnlyDetails = None + ) + } +} diff --git a/conf/app.routes b/conf/app.routes index 7a2d93c87..a2548d3f9 100755 --- a/conf/app.routes +++ b/conf/app.routes @@ -426,6 +426,9 @@ POST /:srn/remove-loan/:index GET /:srn/change-remove-loan/:index controllers.nonsipp.loansmadeoroutstanding.RemoveLoanController.onPageLoad(srn: Srn, index: Max5000, mode: Mode = CheckMode) POST /:srn/change-remove-loan/:index controllers.nonsipp.loansmadeoroutstanding.RemoveLoanController.onSubmit(srn: Srn, index: Max5000, mode: Mode = CheckMode) +GET /:srn/check-update-loans-information/:index controllers.nonsipp.loansmadeoroutstanding.LoansCheckAndUpdateController.onPageLoad(srn: Srn, index: Max5000) +GET /:srn/submit-check-update-loans-information/:index controllers.nonsipp.loansmadeoroutstanding.LoansCheckAndUpdateController.onSubmit(srn: Srn, index: Max5000) + GET /:srn/check-answers-financial-details controllers.nonsipp.schemedesignatory.FinancialDetailsCheckYourAnswersController.onPageLoad(srn: Srn, mode: Mode = NormalMode) POST /:srn/submit-check-answers-financial-details controllers.nonsipp.schemedesignatory.FinancialDetailsCheckYourAnswersController.onSubmit(srn: Srn, mode: Mode = NormalMode) GET /:srn/change-check-answers-financial-details controllers.nonsipp.schemedesignatory.FinancialDetailsCheckYourAnswersController.onPageLoad(srn: Srn, mode: Mode = CheckMode) diff --git a/conf/messages.en b/conf/messages.en index 90ca5c8e3..a7a26b594 100755 --- a/conf/messages.en +++ b/conf/messages.en @@ -1643,6 +1643,17 @@ removeLoan.title = Are you sure you want to remove this loan? removeLoan.heading = Are you sure you want to remove the loan of £{0} to {1}? removeLoan.error.required = Select yes if you are sure you want to remove this loan +loansCheckAndUpdate.title = Check and update the loans information +loansCheckAndUpdate.heading = Check and update the loans information +loansCheckAndUpdate.paragraph = You need to add data to this loan. +loansCheckAndUpdate.table.one = Recipient’s name +loansCheckAndUpdate.table.two = Date of the loan +loansCheckAndUpdate.table.three = Total loan amount +loansCheckAndUpdate.bullet.paragraph = Missing data could include: +loansCheckAndUpdate.bullet.one = Capital Repayment details +loansCheckAndUpdate.bullet.two = any outstanding arrears details +loansCheckAndUpdate.button = Add missing data + financialDetailsCheckYourAnswersController.title = Check your answers financialDetailsCheckYourAnswersController.heading = Check your answers financialDetailsCheckYourAnswersController.viewOnly.title = Financial details diff --git a/test/controllers/nonsipp/loansmadeoroutstanding/LoansCheckAndUpdateControllerSpec.scala b/test/controllers/nonsipp/loansmadeoroutstanding/LoansCheckAndUpdateControllerSpec.scala new file mode 100644 index 000000000..ebd9303b3 --- /dev/null +++ b/test/controllers/nonsipp/loansmadeoroutstanding/LoansCheckAndUpdateControllerSpec.scala @@ -0,0 +1,77 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package controllers.nonsipp.loansmadeoroutstanding + +import models.ConditionalYesNo._ +import play.api.mvc.Call +import models.IdentityType.Individual +import controllers.ControllerBaseSpec +import views.html.ContentTablePageView +import models.{ConditionalYesNo, NormalMode, Security} +import pages.nonsipp.common.IdentityTypePage +import pages.nonsipp.loansmadeoroutstanding._ +import models.IdentitySubject.LoanRecipient + +class LoansCheckAndUpdateControllerSpec extends ControllerBaseSpec { + + private val conditionalYesSecurity: ConditionalYes[Security] = ConditionalYesNo.yes(security) + + private def onPageLoad: Call = routes.LoansCheckAndUpdateController.onPageLoad(srn, index1of5000) + private def onSubmit: Call = routes.LoansCheckAndUpdateController.onSubmit(srn, index1of5000) + + private val prePopUserAnswers = defaultUserAnswers + .unsafeSet(IdentityTypePage(srn, index1of5000, LoanRecipient), Individual) + .unsafeSet(IndividualRecipientNamePage(srn, index1of5000), recipientName) + .unsafeSet(IndividualRecipientNinoPage(srn, index1of5000), conditionalYesNoNino) + .unsafeSet(IsIndividualRecipientConnectedPartyPage(srn, index1of5000), true) + .unsafeSet(DatePeriodLoanPage(srn, index1of5000), (localDate, money, loanPeriod)) + .unsafeSet(AmountOfTheLoanPage(srn, index1of5000), partialAmountOfTheLoan) + .unsafeSet(AreRepaymentsInstalmentsPage(srn, index1of5000), true) + .unsafeSet(InterestOnLoanPage(srn, index1of5000), partialInterestOnLoan) + .unsafeSet(SecurityGivenForLoanPage(srn, index1of5000), conditionalYesSecurity) + + "LoansCheckAndUpdateController" - { + + act.like( + renderView(onPageLoad, prePopUserAnswers) { implicit app => implicit request => + injected[ContentTablePageView].apply( + LoansCheckAndUpdateController.viewModel( + srn = srn, + index = index1of5000, + recipientName = recipientName, + dateOfTheLoan = localDate, + amountOfTheLoan = money + ) + ) + }.withName(s"render correct view") + ) + + act.like( + redirectToPage(onSubmit, routes.AmountOfTheLoanController.onPageLoad(srn, index1of5000, NormalMode)) + ) + + act.like( + journeyRecoveryPage(onPageLoad) + .updateName("onPageLoad" + _) + ) + + act.like( + journeyRecoveryPage(onSubmit) + .updateName("onSubmit" + _) + ) + } +}