diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/AgreedRentChangeController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/AgreedRentChangeController.scala index 614f5ee3..20b100b2 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/AgreedRentChangeController.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/AgreedRentChangeController.scala @@ -23,6 +23,7 @@ import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingActio import uk.gov.hmrc.ngrraldfrontend.config.AppConfig import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios import uk.gov.hmrc.ngrraldfrontend.models.components.NavBarPageContents.createDefaultNavBar +import uk.gov.hmrc.ngrraldfrontend.models.components.Yes import uk.gov.hmrc.ngrraldfrontend.models.forms.AgreedRentChangeForm import uk.gov.hmrc.ngrraldfrontend.models.forms.AgreedRentChangeForm.form import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId @@ -71,7 +72,11 @@ class AgreedRentChangeController @Inject()(agreedRentChangeView: AgreedRentChang credId = CredId(request.credId.getOrElse("")), agreedRentChange = radioValue.radioValue ) - Future.successful(Redirect(routes.WhatTypeOfLeaseRenewalController.show.url)) + if(radioValue.radioValue == "Yes"){ + Future.successful(Redirect(routes.ProvideDetailsOfFirstSecondRentPeriodController.show.url)) + }else { + Future.successful(Redirect(routes.WhatTypeOfLeaseRenewalController.show.url)) + } ) } } diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/AgreementController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/AgreementController.scala index 45ca7b32..742ceed4 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/AgreementController.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/AgreementController.scala @@ -156,9 +156,9 @@ class AgreementController @Inject()(view: AgreementView, formWithErrors => val correctedFormErrors = formWithErrors.errors.map { formError => (formError.key, formError.messages) match - case ("", messages) if messages.contains("agreement.radio.breakClause.required.error") => + case ("", messages) if messages.contains("agreement.radio.conditional.breakClause.required.error") => formError.copy(key = "about-break-clause") - case ("", messages) if messages.contains("agreement.radio.breakClause.tooLong.error") => + case ("", messages) if messages.contains("agreement.radio.conditional.breakClause.tooLong.error") => formError.copy(key = "about-break-clause") case ("", messages) => formError.copy(key = "agreementEndDate") diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/ProvideDetailsOfFirstSecondRentPeriodController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/ProvideDetailsOfFirstSecondRentPeriodController.scala new file mode 100644 index 00000000..c80aa212 --- /dev/null +++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/ProvideDetailsOfFirstSecondRentPeriodController.scala @@ -0,0 +1,201 @@ +/* + * Copyright 2025 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 uk.gov.hmrc.ngrraldfrontend.controllers + +import play.api.data.Form +import play.api.i18n.{I18nSupport, Messages} +import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} +import play.twirl.api.Html +import uk.gov.hmrc.govukfrontend.views.Aliases.* +import uk.gov.hmrc.govukfrontend.views.viewmodels.dateinput.DateInput +import uk.gov.hmrc.http.NotFoundException +import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction} +import uk.gov.hmrc.ngrraldfrontend.config.AppConfig +import uk.gov.hmrc.ngrraldfrontend.models.components.* +import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios +import uk.gov.hmrc.ngrraldfrontend.models.components.NavBarPageContents.createDefaultNavBar +import uk.gov.hmrc.ngrraldfrontend.models.forms.ProvideDetailsOfFirstSecondRentPeriodForm +import uk.gov.hmrc.ngrraldfrontend.models.forms.ProvideDetailsOfFirstSecondRentPeriodForm.form +import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId +import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo +import uk.gov.hmrc.ngrraldfrontend.views.html.ProvideDetailsOfFirstSecondRentPeriodView +import uk.gov.hmrc.ngrraldfrontend.views.html.components.InputText +import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController + +import javax.inject.Inject +import scala.concurrent.{ExecutionContext, Future} + +class ProvideDetailsOfFirstSecondRentPeriodController @Inject()(view: ProvideDetailsOfFirstSecondRentPeriodView, + authenticate: AuthRetrievals, + inputText: InputText, + hasLinkedProperties: PropertyLinkingAction, + raldRepo: RaldRepo, + mcc: MessagesControllerComponents + )(implicit appConfig: AppConfig, ec: ExecutionContext) extends FrontendController(mcc) with I18nSupport { + + def firstDateStartInput()(implicit messages: Messages) : DateInput = DateInput( + id = "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date", + namePrefix = Some("provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date"), + fieldset = Some(Fieldset( + legend = Some(Legend( + content = Text(messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.label")), + classes = "govuk-fieldset__legend--s", + isPageHeading = true + )) + )), + hint = Some(Hint( + id = Some("provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.hint"), + content = Text(messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.hint")) + )) + ) + + def firstDateEndInput()(implicit messages: Messages): DateInput = DateInput( + id = "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date", + namePrefix = Some("provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date"), + fieldset = Some(Fieldset( + legend = Some(Legend( + content = Text(messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.label")), + classes = "govuk-fieldset__legend--s", + isPageHeading = true + )) + )), + hint = Some(Hint( + id = Some("provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.hint"), + content = Text(messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.hint")) + )) + ) + + private def firstRentPeriodYesButton(form: Form[ProvideDetailsOfFirstSecondRentPeriodForm])(implicit messages: Messages): NGRRadioButtons = NGRRadioButtons( + radioContent = "provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.yes", + radioValue = yesPayedRent, + conditionalHtml = Some(inputText( + form = form, + id = "RentPeriodAmount", + name = "RentPeriodAmount", + label = messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.conditional.hint.bold"), + isVisible = true, + hint = Some(Hint( + content = Text(messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.conditional.hint")) + )), + classes = Some("govuk-input--width-10"), + prefix = Some(PrefixOrSuffix(content = Text("£"))) + )) + ) + + private def firstRentPeriodRadio(form: Form[ProvideDetailsOfFirstSecondRentPeriodForm])(implicit messages: Messages): NGRRadio = { + val ngrRadioButtons: Seq[NGRRadioButtons] = Seq( + firstRentPeriodYesButton(form), + NGRRadioButtons(radioContent = "provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.no", radioValue = noRentPayed), + ) + NGRRadio( + NGRRadioName("provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio"), + ngrTitle = Some(Legend(content = Text(messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.label")), classes = "govuk-fieldset__legend--m", isPageHeading = true)), + NGRRadioButtons = ngrRadioButtons + ) + } + + def secondDateStartInput()(implicit messages: Messages): DateInput = DateInput( + id = "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date", + namePrefix = Some("provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date"), + fieldset = Some(Fieldset( + legend = Some(Legend( + content = Text(messages("provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.label")), + classes = "govuk-fieldset__legend--s", + isPageHeading = true + )) + )), + hint = Some(Hint( + id = Some("provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.hint"), + content = Text(messages("provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.hint")) + )) + ) + + def secondDateEndInput()(implicit messages: Messages): DateInput = DateInput( + id = "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date", + namePrefix = Some("provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date"), + fieldset = Some(Fieldset( + legend = Some(Legend( + content = Text(messages("provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.label")), + classes = "govuk-fieldset__legend--s", + isPageHeading = true + )) + )), + hint = Some(Hint( + id = Some("provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.hint"), + content = Text(messages("provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.hint")) + )) + ) + + def show: Action[AnyContent] = { + (authenticate andThen hasLinkedProperties).async { implicit request => + request.propertyLinking.map(property => + Future.successful(Ok(view( + navigationBarContent = createDefaultNavBar, + selectedPropertyAddress = property.addressFull, + form, + firstDateStartInput(), + firstDateEndInput(), + buildRadios(form, firstRentPeriodRadio(form)), + secondDateStartInput(), + secondDateEndInput() + ))) + ).getOrElse(throw new NotFoundException("Couldn't find property in mongo")) + } + } + + def submit: Action[AnyContent] = { + (authenticate andThen hasLinkedProperties).async { implicit request => + form + .bindFromRequest() + .fold( + formWithErrors => + val correctedFormErrors = formWithErrors.errors.map { formError => + (formError.key, formError.messages) match + case ("", messages) => + formError.copy(key = "RentPeriodAmount") + case _ => + formError + } + val formWithCorrectedErrors = formWithErrors.copy(errors = correctedFormErrors) + + request.propertyLinking.map(property => + Future.successful(BadRequest(view( + createDefaultNavBar, + selectedPropertyAddress = property.addressFull, + formWithCorrectedErrors, + firstDateStartInput(), + firstDateEndInput(), + buildRadios(formWithErrors, firstRentPeriodRadio(formWithCorrectedErrors)), + secondDateStartInput(), + secondDateEndInput() + )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo")), + provideDetailsOfFirstSecondRentPeriodForm => + raldRepo.insertProvideDetailsOfFirstSecondRentPeriod( + CredId(request.credId.getOrElse("")), + provideDetailsOfFirstSecondRentPeriodForm.firstDateStartInput.makeString, + provideDetailsOfFirstSecondRentPeriodForm.firstDateEndInput.makeString, + provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodRadio, + provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodAmount, + provideDetailsOfFirstSecondRentPeriodForm.secondDateStartInput.makeString, + provideDetailsOfFirstSecondRentPeriodForm.secondDateEndInput.makeString, + provideDetailsOfFirstSecondRentPeriodForm.secondHowMuchIsRent, + ) + Future.successful(Redirect(routes.WhatIsYourRentBasedOnController.show.url)) + ) + } + } +} diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/TypeOfLeaseRenewalController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/TypeOfLeaseRenewalController.scala deleted file mode 100644 index e69de29b..00000000 diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/ProvideDetailsOfFirstSecondRentPeriod.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/ProvideDetailsOfFirstSecondRentPeriod.scala new file mode 100644 index 00000000..19d1adb3 --- /dev/null +++ b/app/uk/gov/hmrc/ngrraldfrontend/models/ProvideDetailsOfFirstSecondRentPeriod.scala @@ -0,0 +1,33 @@ +/* + * Copyright 2025 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 uk.gov.hmrc.ngrraldfrontend.models + +import play.api.libs.json.{Json, OFormat} + +case class ProvideDetailsOfFirstSecondRentPeriod( + firstDateStart: String, + firstDateEnd: String, + firstRentPeriodRadio: Boolean, + firstRentPeriodAmount: Option[String], + secondDateStart: String, + secondDateEnd: String, + secondHowMuchIsRent: String + ) + +object ProvideDetailsOfFirstSecondRentPeriod { + implicit val format: OFormat[ProvideDetailsOfFirstSecondRentPeriod] = Json.format[ProvideDetailsOfFirstSecondRentPeriod] +} \ No newline at end of file diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/RaldUserAnswers.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/RaldUserAnswers.scala index 40f839a4..2a4639aa 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/models/RaldUserAnswers.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/models/RaldUserAnswers.scala @@ -32,7 +32,8 @@ final case class RaldUserAnswers( agreedRentChange: Option[String] = None, agreementVerbal: Option[AgreementVerbal] = None, hasRentFreePeriod: Option[Boolean] = None, - agreement: Option[Agreement] = None + agreement: Option[Agreement] = None, + provideDetailsOfFirstSecondRentPeriod: Option[ProvideDetailsOfFirstSecondRentPeriod] = None ) diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/components/NGRRadio.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/components/NGRRadio.scala index ea0a1d80..c98580a7 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/models/components/NGRRadio.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/models/components/NGRRadio.scala @@ -59,6 +59,10 @@ case object NoOpenEnded extends Agreement case object YesBreakClause extends Agreement case object NoBreakClause extends Agreement +sealed trait firstRentPeriod extends RadioEntry +case object yesPayedRent extends RadioEntry +case object noRentPayed extends RadioEntry + case class NGRRadioName(key: String) case class NGRRadioButtons(radioContent: String, diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/AgreementForm.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/AgreementForm.scala index aa307b6b..fa4630f5 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/AgreementForm.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/AgreementForm.scala @@ -25,6 +25,7 @@ import uk.gov.hmrc.ngrraldfrontend.models.* import uk.gov.hmrc.ngrraldfrontend.models.forms.AgreementVerbalForm.{dateValidation, firstError, isDateEmpty, isDateValid} import uk.gov.hmrc.ngrraldfrontend.models.forms.WhatIsYourRentBasedOnForm.firstError import uk.gov.hmrc.ngrraldfrontend.models.forms.mappings.Mappings +import scala.util.Try final case class AgreementForm( agreementStart: NGRDate, @@ -147,7 +148,6 @@ object AgreementForm extends CommonFormValidators with Mappings with DateMapping isEndDateValid("agreement.endDate.format.error") ) ) - ) } } diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/ProvideDetailsOfFirstSecondRentPeriodForm.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/ProvideDetailsOfFirstSecondRentPeriodForm.scala new file mode 100644 index 00000000..43fed57e --- /dev/null +++ b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/ProvideDetailsOfFirstSecondRentPeriodForm.scala @@ -0,0 +1,168 @@ +/* + * Copyright 2025 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 uk.gov.hmrc.ngrraldfrontend.models.forms + +import play.api.data.Forms.{mapping, of} +import play.api.data.format.Formatter +import play.api.data.validation.{Constraint, Invalid, Valid} +import play.api.data.{Form, FormError} +import play.api.i18n.* +import play.api.libs.json.{Json, OFormat} +import uk.gov.hmrc.ngrraldfrontend.models.* +import uk.gov.hmrc.ngrraldfrontend.models.forms.AgreementVerbalForm.{isDateEmpty, isDateValid} +import uk.gov.hmrc.ngrraldfrontend.models.forms.mappings.Mappings + +import scala.util.Try + +final case class ProvideDetailsOfFirstSecondRentPeriodForm( + firstDateStartInput: NGRDate, + firstDateEndInput: NGRDate, + firstRentPeriodRadio: String, + firstRentPeriodAmount: Option[BigDecimal], + secondDateStartInput: NGRDate, + secondDateEndInput: NGRDate, + secondHowMuchIsRent: BigDecimal, + ) + +object ProvideDetailsOfFirstSecondRentPeriodForm extends CommonFormValidators with Mappings with DateMappings{ + implicit val format: OFormat[ProvideDetailsOfFirstSecondRentPeriodForm] = Json.format[ProvideDetailsOfFirstSecondRentPeriodForm] + + private def errorKeys(whichDate: String): Map[DateErrorKeys, String] = Map( + Required -> s"provideDetailsOfFirstSecondRentPeriod.$whichDate.required.error", + DayAndMonth -> s"provideDetailsOfFirstSecondRentPeriod.$whichDate.day.month.required.error", + DayAndYear -> s"provideDetailsOfFirstSecondRentPeriod.$whichDate.day.year.required.error", + MonthAndYear -> s"provideDetailsOfFirstSecondRentPeriod.$whichDate.month.year.required.error", + Day -> s"provideDetailsOfFirstSecondRentPeriod.$whichDate.day.required.error", + Month -> s"provideDetailsOfFirstSecondRentPeriod.$whichDate.month.required.error", + Year -> s"provideDetailsOfFirstSecondRentPeriod.$whichDate.year.required.error" + ) + + private lazy val radioFirstPeriodRequiredError = "provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.error.required" + private val firstDateStartInput = "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date" + private val firstDateEndInput = "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date" + private val firstRentPeriodRadio = "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" + private val RentPeriodAmount = "RentPeriodAmount" + private val SecondRentPeriodAmount = "SecondRentPeriodAmount" + private val secondDateStartInput = "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date" + private val secondDateEndInput = "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date" + private lazy val annualRentEmptyError = "provideDetailsOfFirstSecondRentPeriod.secondPeriod.amount.error.required" + private lazy val provideDetailsOfFirstSecondRentPeriodSecondPeriodAmountFormatError = "provideDetailsOfFirstSecondRentPeriod.firstPeriod.amount.error.required" + + + val messagesApi: MessagesApi = new DefaultMessagesApi() + val lang: Lang = Lang.defaultLang + val messages: Messages = MessagesImpl(lang, messagesApi) + + def unapply(provideDetailsOfFirstSecondRentPeriodForm: ProvideDetailsOfFirstSecondRentPeriodForm): Option[( + NGRDate, NGRDate, String, Option[BigDecimal], NGRDate, NGRDate, BigDecimal)] = + Some( + (provideDetailsOfFirstSecondRentPeriodForm.firstDateStartInput, + provideDetailsOfFirstSecondRentPeriodForm.firstDateEndInput, + provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodRadio, + provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodAmount, + provideDetailsOfFirstSecondRentPeriodForm.secondDateStartInput, + provideDetailsOfFirstSecondRentPeriodForm.secondDateEndInput, + provideDetailsOfFirstSecondRentPeriodForm.secondHowMuchIsRent, + ) + ) + + + def bigDecimalWithFormatError: Formatter[BigDecimal] = new Formatter[BigDecimal] { + override def bind(key: String, data: Map[String, String]): Either[Seq[FormError], BigDecimal] = { + data.get(key).filter(_.nonEmpty) match { + case Some(value) => + Try(BigDecimal(value)).toEither.left.map(_ => + Seq(FormError(key, annualRentEmptyError)) + ) + case None => + Left(Seq(FormError(key, annualRentEmptyError))) + } + } + override def unbind(key: String, value: BigDecimal): Map[String, String] = + Map(key -> value.toString()) + } + + private def optionalBigDecimalWithFormatError: Formatter[Option[BigDecimal]] = new Formatter[Option[BigDecimal]] { + override def bind(key: String, data: Map[String, String]): Either[Seq[FormError], Option[BigDecimal]] = { + data.get(key).map(_.trim).filter(_.nonEmpty) match { + case Some(value) => + Try(BigDecimal(value)).toEither match { + case Right(parsed) => Right(Some(parsed)) + case Left(_) => Left(Seq(FormError(key, "provideDetailsOfFirstSecondRentPeriod.firstPeriod.amount.error.required"))) + } + case None => Right(None) // Field is optional and not provided + } + } + + override def unbind(key: String, value: Option[BigDecimal]): Map[String, String] = + value.map(v => Map(key -> v.toString)).getOrElse(Map.empty) + } + + + private def isOptionalBigDecimalEmptyOrInvalid[A]: Constraint[A] = + Constraint((input: A) => + val provideDetailsOfFirstSecondRentPeriodForm = input.asInstanceOf[ProvideDetailsOfFirstSecondRentPeriodForm] + if (provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodRadio.equals("yesPayedRent") && provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodAmount.getOrElse(None) == None) + Invalid(provideDetailsOfFirstSecondRentPeriodSecondPeriodAmountFormatError) + else + Valid + ) + + + def form: Form[ProvideDetailsOfFirstSecondRentPeriodForm] = { + Form( + mapping( + firstDateStartInput -> dateMapping + .verifying( + firstError( + isDateEmpty(errorKeys("first.startDate")), + isDateValid("provideDetailsOfFirstSecondRentPeriod.startDate.format.error") + ) + ), + firstDateEndInput -> dateMapping + .verifying( + firstError( + isDateEmpty(errorKeys("first.endDate")), + isDateValid("provideDetailsOfFirstSecondRentPeriod.endDate.format.error") + ) + ), + firstRentPeriodRadio -> text(radioFirstPeriodRequiredError), + RentPeriodAmount -> of(optionalBigDecimalWithFormatError), + secondDateStartInput -> dateMapping + .verifying( + firstError( + isDateEmpty(errorKeys("second.startDate")), + isDateValid("provideDetailsOfFirstSecondRentPeriod.startDate.format.error") + ) + ), + secondDateEndInput -> dateMapping + .verifying( + firstError( + isDateEmpty(errorKeys("second.endDate")), + isDateValid("provideDetailsOfFirstSecondRentPeriod.endDate.format.error") + ) + ), + SecondRentPeriodAmount -> of(bigDecimalWithFormatError) + )(ProvideDetailsOfFirstSecondRentPeriodForm.apply)(ProvideDetailsOfFirstSecondRentPeriodForm.unapply) + .verifying( + firstError( + isOptionalBigDecimalEmptyOrInvalid + ) + ) + ) + } +} diff --git a/app/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepo.scala b/app/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepo.scala index a3785185..25c69a54 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepo.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepo.scala @@ -124,9 +124,36 @@ case class RaldRepo @Inject()(mongo: MongoComponent, findAndUpdateByCredId(credId = credId, answers: _*) } + def insertProvideDetailsOfFirstSecondRentPeriod( + credId: CredId, + firstDateStart: String, + firstDateEnd: String, + firstRentPeriodRadio: String, + firstRentPeriodAmount: Option[BigDecimal], + secondDateStart: String, + secondDateEnd: String, + secondHowMuchIsRent: BigDecimal + ): Future[Option[RaldUserAnswers]] = { + val firstDateStartVal = Updates.set("ProvideDetailsOfFirstSecondRentPeriod.firstDateStart", firstDateStart) + val firstDateEndVal = Updates.set("ProvideDetailsOfFirstSecondRentPeriod.firstDateEnd", firstDateEnd) + val firstRentPeriodRadioVal = Updates.set("ProvideDetailsOfFirstSecondRentPeriod.firstRentPeriodRadio", firstRentPeriodRadio match { + case answer if (answer == "yesPayedRent") => true + case _ => false + }) + val firstRentPeriodAmountVal = Updates.set("ProvideDetailsOfFirstSecondRentPeriod.firstRentPeriodAmount", firstRentPeriodAmount match { + case Some(value) => value.toString() + case _ => null + }) + val secondDateStartVal = Updates.set("ProvideDetailsOfFirstSecondRentPeriod.secondDateStart", secondDateStart) + val secondDateEndVal = Updates.set("ProvideDetailsOfFirstSecondRentPeriod.secondDateEnd", secondDateEnd) + val secondHowMuchIsRentVal = Updates.set("ProvideDetailsOfFirstSecondRentPeriod.secondHowMuchIsRent", secondHowMuchIsRent.toString) + val answers = Seq(firstDateStartVal, firstDateEndVal, firstRentPeriodRadioVal, firstRentPeriodAmountVal, secondDateStartVal, secondDateEndVal, secondHowMuchIsRentVal) + findAndUpdateByCredId(credId = credId, answers: _*) + } + def insertRentBased(credId: CredId, rentBased: String, rentBasedOtherText:Option[String]): Future[Option[RaldUserAnswers]] = { val updates = Seq(Updates.set("rentBasedOn.rentBased", rentBased), - Updates.set("rentBasedOn.otherDesc", rentBasedOtherText.getOrElse(null))) + Updates.set("rentBasedOn.otherDesc", rentBasedOtherText.orNull)) findAndUpdateByCredId(credId, updates: _*) } @@ -153,7 +180,7 @@ case class RaldRepo @Inject()(mongo: MongoComponent, def insertAgreementVerbal(credId: CredId, startDate: String, openEnded: Boolean, endDate: Option[String]): Future[Option[RaldUserAnswers]] = { val updates = Seq(Updates.set("agreementVerbal.startDate", startDate), Updates.set("agreementVerbal.openEnded", openEnded), - Updates.set("agreementVerbal.endDate", endDate.getOrElse(null))) + Updates.set("agreementVerbal.endDate", endDate.orNull)) findAndUpdateByCredId(credId, updates: _*) } diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/ProvideDetailsOfFirstSecondRentPeriodView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/ProvideDetailsOfFirstSecondRentPeriodView.scala.html new file mode 100644 index 00000000..f79809c4 --- /dev/null +++ b/app/uk/gov/hmrc/ngrraldfrontend/views/ProvideDetailsOfFirstSecondRentPeriodView.scala.html @@ -0,0 +1,82 @@ +@* + * Copyright 2025 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. + *@ + +@import uk.gov.hmrc.ngrraldfrontend.config.AppConfig + +@import uk.gov.hmrc.govukfrontend.views.html.components.implicits._ +@import uk.gov.hmrc.hmrcfrontend.views.html.components.implicits._ +@import uk.gov.hmrc.ngrraldfrontend.models.components.NavigationBarContent +@import uk.gov.hmrc.ngrraldfrontend.viewmodels.govuk.all._ +@import uk.gov.hmrc.govukfrontend.views.html.components._ +@import uk.gov.hmrc.ngrraldfrontend.views.html.components._ +@import uk.gov.hmrc.ngrraldfrontend.models.forms.ProvideDetailsOfFirstSecondRentPeriodForm + +@this( +layout: Layout, +formHelper: FormWithCSRF, +govukErrorSummary: GovukErrorSummary, +dateInputField: DateTextFields, +govukRadios : GovukRadios, +inputText: components.InputText, +saveAndContinueButton: saveAndContinueButton +) + +@( + navigationBarContent: NavigationBarContent, + selectedPropertyAddress: String, + form: Form[ProvideDetailsOfFirstSecondRentPeriodForm], + firstDateStartInput: DateInput, + firstDateEndInput:DateInput, + openEndedRadio: Radios, + secondDateStartInput: DateInput, + secondDateEndInput: DateInput +)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig) + +@layout(pageTitle = Some(messages("provideDetailsOfFirstSecondRentPeriod.title")), showBackLink = true, fullWidth = false, navigationBarContent = Some(navigationBarContent)) { + + @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.ProvideDetailsOfFirstSecondRentPeriodController.submit, Symbol("autoComplete") -> "off") { + + @if(form.errors.nonEmpty) { + @govukErrorSummary(ErrorSummaryViewModel(form)) + } + + @selectedPropertyAddress +

@messages("provideDetailsOfFirstSecondRentPeriod.title")

+
+ @messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.subheading") + @dateInputField(form, firstDateStartInput) + @dateInputField(form, firstDateEndInput) + @govukRadios(openEndedRadio) +
+ @messages("provideDetailsOfFirstSecondRentPeriod.secondPeriod.subheading.1") + @dateInputField(form, secondDateStartInput) + @dateInputField(form, secondDateEndInput) + @inputText( + form = form, + id = "SecondRentPeriodAmount", + name = "SecondRentPeriodAmount", + label = messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.conditional.hint.bold"), + isPageHeading = true, + hint = Some(Hint( + content = Text(messages("provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.conditional.hint")) + )), + isVisible = true, + classes = Some("govuk-input--width-10"), + prefix = Some(PrefixOrSuffix(content = Text("£"))) + ) + @saveAndContinueButton(msg = messages("service.saveAndContinue"), isStartButton = false) + } +} \ No newline at end of file diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/components/InputComponent.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/components/InputComponent.scala.html new file mode 100644 index 00000000..76463f28 --- /dev/null +++ b/app/uk/gov/hmrc/ngrraldfrontend/views/components/InputComponent.scala.html @@ -0,0 +1,25 @@ +@* + * Copyright 2025 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. + *@ + +@import uk.gov.hmrc.govukfrontend.views.html.components._ +@import uk.gov.hmrc.govukfrontend.views.viewmodels.input.Input + +@this(govukInput : GovukInput) + +@(input: Input) + + +@govukInput(input) \ No newline at end of file diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/components/InputText.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/components/InputText.scala.html index 1ae506b6..8de4cc8e 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/views/components/InputText.scala.html +++ b/app/uk/gov/hmrc/ngrraldfrontend/views/components/InputText.scala.html @@ -34,20 +34,20 @@ )(implicit messages: Messages) @govukInput(Input( - id, - name, - classes = classes.fold("")(x => x), - label = Label( - content = Text(messages(label, headingMessageArgs: _*)), - isPageHeading = isPageHeading, - classes = if(isVisible && isPageHeading) "govuk-label--m " else if(isVisible) "govuk-label" else "govuk-visually-hidden" - ), - hint = hint, - prefix = prefix, - value = if(populateField) form(name).value else None, - errorMessage = form.errors(name) match { -case Nil => None -case errors => Some(ErrorMessage(content = HtmlContent(errors.map(err => messages(err.message)).mkString("
")))) -}, - autocomplete = Some(autoComplete) + id, + name, + classes = classes.fold("")(x => x), + label = Label( + content = Text(messages(label, headingMessageArgs: _*)), + isPageHeading = isPageHeading, + classes = if(isVisible && isPageHeading) "govuk-label--m " else if(isVisible) "govuk-label" else "govuk-visually-hidden" + ), + hint = hint, + prefix = prefix, + value = if(populateField) form(name).value else None, + errorMessage = form.errors(name) match { + case Nil => None + case errors => Some(ErrorMessage(content = HtmlContent(errors.map(err => messages(err.message)).mkString("
")))) + }, + autocomplete = Some(autoComplete) )) \ No newline at end of file diff --git a/conf/app.routes b/conf/app.routes index b438f6dd..b919020e 100644 --- a/conf/app.routes +++ b/conf/app.routes @@ -22,7 +22,9 @@ GET /have-you-agreed-rent-changes-with-landlord uk.gov.hmrc.ngrraldfront POST /have-you-agreed-rent-changes-with-landlord uk.gov.hmrc.ngrraldfrontend.controllers.AgreedRentChangeController.submit GET /agreement-verbal uk.gov.hmrc.ngrraldfrontend.controllers.AgreementVerbalController.show POST /agreement-verbal uk.gov.hmrc.ngrraldfrontend.controllers.AgreementVerbalController.submit -GET /do-you-have-a-rent-free-period uk.gov.hmrc.ngrraldfrontend.controllers.CheckRentFreePeriodController.show -POST /do-you-have-a-rent-free-period uk.gov.hmrc.ngrraldfrontend.controllers.CheckRentFreePeriodController.submit -GET /agreement uk.gov.hmrc.ngrraldfrontend.controllers.AgreementController.show -POST /agreement uk.gov.hmrc.ngrraldfrontend.controllers.AgreementController.submit \ No newline at end of file +GET /do-you-have-a-rent-free-period uk.gov.hmrc.ngrraldfrontend.controllers.CheckRentFreePeriodController.show +POST /do-you-have-a-rent-free-period uk.gov.hmrc.ngrraldfrontend.controllers.CheckRentFreePeriodController.submit +GET /agreement uk.gov.hmrc.ngrraldfrontend.controllers.AgreementController.show +POST /agreement uk.gov.hmrc.ngrraldfrontend.controllers.AgreementController.submit +GET /provide-details-of-first-second-rent-period uk.gov.hmrc.ngrraldfrontend.controllers.ProvideDetailsOfFirstSecondRentPeriodController.show +POST /provide-details-of-first-second-rent-period uk.gov.hmrc.ngrraldfrontend.controllers.ProvideDetailsOfFirstSecondRentPeriodController.submit \ No newline at end of file diff --git a/conf/messages b/conf/messages index 8b03e2fb..db06ba6a 100644 --- a/conf/messages +++ b/conf/messages @@ -47,13 +47,13 @@ whatTypeOfAgreement.written = Licence or other type of written agreement whatTypeOfAgreement.verbal = Verbal agreement whatTypeOfAgreement.error.required = Select what type of agreement you have -#typeOfLeaseRenewal +#TypeOfLeaseRenewal typeOfLeaseRenewal.title = What type of lease renewal is it? typeOfLeaseRenewal.option1 = A renewed agreement typeOfLeaseRenewal.option2 = A surrender and renewal typeOfLeaseRenewal.required.error = Select what type of lease renewal it is -#landlord +#Landlord landlord.title = Landlord landlord.p1 = What is the landlord''s full name? landlord.p2 = What is your relationship with the landlord? @@ -90,7 +90,7 @@ whatIsYourRentBasedOn.error.required = Select what your rent is based on whatIsYourRentBasedOn.otherText.error.required = Tell us how your rent was agreed whatIsYourRentBasedOn.otherText.error.maxLength = Maximum character allowed is 250 -#howMuchIsTotalAnnualRent +#HowMuchIsTotalAnnualRent howMuchIsTotalAnnualRent.title = How much is your total annual rent? howMuchIsTotalAnnualRent.p1 = This is the amount you pay each year (excluding VAT) even if: howMuchIsTotalAnnualRent.b1 = you pay monthly or quarterly @@ -100,7 +100,7 @@ howMuchIsTotalAnnualRent.empty.error = Enter your new total annual rent, in poun howMuchIsTotalAnnualRent.tooLarge.error = New total annual rent must be £9,999,999.99 or less howMuchIsTotalAnnualRent.format.error = New total annual rent must be a number, like 30,000 -#agreedRentChange +#AgreedRentChange agreedRentChange.title = Have you agreed in advance with the landlord when and by how much rent goes up? agreedRentChange.p1 = For example, the agreement says that the rent will increase from £5,000 to £7,000 a year after 12 months. This is often known as a stepped rent. agreedRentChange.empty.error = Select yes if you have agreed with your landlord in advance when and by how much rent goes up @@ -134,12 +134,12 @@ agreementVerbal.endDate.monthAndYear.required.error = Date your agreement ends m agreementVerbal.endDate.invalid.error = Date your agreement ends must be a real date agreementVerbal.endDate.isBefore.startDate.error = Date your agreement ends must be after agreement started -#checkRentPeriod +#CheckRentPeriod checkRentPeriod.title = Do you have a rent-free period at the start of your agreement? checkRentPeriod.p1 = A rent-free period is when you do not pay any rent checkRentPeriod.empty.error = Select yes if you have a rent-free period at the start of your agreement. -#agreement +#Agreement agreement.title = Agreement agreement.subheading.1 = When did your agreement start? agreement.hint.1 = For example, 27 6 2026 @@ -173,3 +173,61 @@ agreement.radio.openEnded.required.error = Select yes if your agreement is open- agreement.radio.breakClause.required.error = Select yes if your agreement has a break clause agreement.radio.conditional.breakClause.required.error = Tell us about your break clause or clauses agreement.radio.conditional.breakClause.tooLong.error = Maximum character allowed is 250 + +#ProvideDetailsOfFirstSecondRentPeriod +provideDetailsOfFirstSecondRentPeriod.title = Provide details of each rent period +provideDetailsOfFirstSecondRentPeriod.firstPeriod.subheading = First rent period +provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.label = Start date +provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.hint = For example, 27 6 2026 +provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.label = End date +provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.hint = For example, 27 6 2026 +provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.label = Do you pay rent in this period? +provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.conditional.hint.bold = How much is the rent for this period (excluding VAT)? +provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.conditional.hint = Enter the amount you pay each year (excluding VAT) even if the period is for more or less than a year. +provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.yes = Yes +provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.no = No, this is a rent-free period +provideDetailsOfFirstSecondRentPeriod.secondPeriod.subheading.1 = Second rent period +provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.label = Start date +provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.hint = For example, 27 6 2026 +provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.label = End date +provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.hint = For example, 27 6 2026 +provideDetailsOfFirstSecondRentPeriod.secondPeriod.subheading.2 = How much is the rent for this period (excluding VAT)? +provideDetailsOfFirstSecondRentPeriod.secondPeriod.hint = Enter the amount you pay each year (excluding VAT) even if the period is for more or less than a year + +provideDetailsOfFirstSecondRentPeriod.first.startDate.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.first.startDate.day.month.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.first.startDate.day.year.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.first.startDate.month.year.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.first.startDate.day.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.first.startDate.month.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.first.startDate.year.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.first.startDate.format.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.first.endDate.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.first.endDate.day.month.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.first.endDate.day.year.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.first.endDate.month.year.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.first.endDate.day.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.first.endDate.month.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.first.endDate.year.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.first.endDate.format.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.second.startDate.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.second.startDate.day.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.second.startDate.day.month.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.second.startDate.day.year.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.second.startDate.month.year.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.second.startDate.day.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.second.startDate.month.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.second.startDate.year.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.second.startDate.format.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.second.endDate.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.second.endDate.day.month.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.second.endDate.day.year.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.second.endDate.month.year.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.second.endDate.day.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.second.endDate.month.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.second.endDate.year.required.error = Date you will start paying rent must be a real date. +provideDetailsOfFirstSecondRentPeriod.second.endDate.format.error = Date you will start paying rent must be a real date. + +provideDetailsOfFirstSecondRentPeriod.firstPeriod.radio.error.required = Select yes if you pay rent in this period. +provideDetailsOfFirstSecondRentPeriod.firstPeriod.amount.error.required = Enter the rent for the first rent period, in pounds. +provideDetailsOfFirstSecondRentPeriod.secondPeriod.amount.error.required = Enter the rent for the second rent period, in pounds. \ No newline at end of file diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/AgreedRentChangeControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/AgreedRentChangeControllerSpec.scala index a518690a..9d22bc08 100644 --- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/AgreedRentChangeControllerSpec.scala +++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/AgreedRentChangeControllerSpec.scala @@ -53,7 +53,7 @@ class AgreedRentChangeControllerSpec extends ControllerSpecSupport { val result = controller.submit()(authenticatedFakeRequest(fakePostRequest)) status(result) mustBe SEE_OTHER - redirectLocation(result) mustBe Some(routes.WhatTypeOfLeaseRenewalController.show.url) + redirectLocation(result) mustBe Some(routes.ProvideDetailsOfFirstSecondRentPeriodController.show.url) } "Return BAD_REQUEST for missing input and the correct view" in { mockRequest() diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/ProvideDetailsOfFirstSecondRentPeriodSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/ProvideDetailsOfFirstSecondRentPeriodSpec.scala new file mode 100644 index 00000000..6bf8e235 --- /dev/null +++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/ProvideDetailsOfFirstSecondRentPeriodSpec.scala @@ -0,0 +1,643 @@ +/* + * Copyright 2025 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 uk.gov.hmrc.ngrraldfrontend.controllers + +import org.mockito.ArgumentMatchers.any +import org.mockito.Mockito.when +import play.api.http.Status.{BAD_REQUEST, OK, SEE_OTHER} +import play.api.test.Helpers.{await, contentAsString, defaultAwaitTimeout, redirectLocation, status} +import play.api.test.FakeRequest +import play.api.test.Helpers.status +import uk.gov.hmrc.auth.core.Nino +import uk.gov.hmrc.http.{HeaderNames, NotFoundException} +import uk.gov.hmrc.ngrraldfrontend.helpers.ControllerSpecSupport +import uk.gov.hmrc.ngrraldfrontend.models.AgreementType.NewAgreement +import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, RaldUserAnswers} +import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId +import uk.gov.hmrc.ngrraldfrontend.views.html.ProvideDetailsOfFirstSecondRentPeriodView +import uk.gov.hmrc.ngrraldfrontend.views.html.components.{DateTextFields, InputText} + +import scala.concurrent.Future + +class ProvideDetailsOfFirstSecondRentPeriodSpec extends ControllerSpecSupport { + val pageTitle = "Provide details of each rent period" + val view: ProvideDetailsOfFirstSecondRentPeriodView = inject[ProvideDetailsOfFirstSecondRentPeriodView] + val mockInputText: InputText = inject[InputText] + val controller: ProvideDetailsOfFirstSecondRentPeriodController = new ProvideDetailsOfFirstSecondRentPeriodController( + view, + mockAuthJourney, + mockInputText, + mockPropertyLinkingAction, + mockRaldRepo, mcc + )(mockConfig, ec) + + "Agreement controller" must { + "method show" must { + "Return OK and the correct view" in { + when(mockRaldRepo.findByCredId(any())) thenReturn (Future.successful(Some(RaldUserAnswers(credId = CredId(null), NewAgreement, selectedProperty = property)))) + val result = controller.show()(authenticatedFakeRequest()) + status(result) mustBe OK + val content = contentAsString(result) + content must include(pageTitle) + } + "Return NotFoundException when property is not found in the mongo" in { + mockRequestWithoutProperty() + val exception = intercept[NotFoundException] { + await(controller.show(authenticatedFakeRequest())) + } + exception.getMessage contains "Couldn't find property in mongo" mustBe true + } + } + + "method submit" must { + "Return OK and the correct view after submitting with first start date, first end date no radio button selected for first rent period" + + "and second rent date start, end and amount is added" in { + when(mockRaldRepo.findByCredId(any())) thenReturn (Future.successful(Some(RaldUserAnswers(credId = CredId(null), NewAgreement, selectedProperty = property)))) + mockRequest(hasCredId = true) + val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit) + .withFormUrlEncodedBody( + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "noRentPayed", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.year" -> "2026", + "SecondRentPeriodAmount" -> "10000.00", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/what-is-your-rent-based-on") + }) + status(result) mustBe SEE_OTHER + redirectLocation(result) mustBe Some(routes.WhatIsYourRentBasedOnController.show.url) + } + "Return OK and the correct view after submitting with first start date, first end date yes radio button selected for first rent period with first rent amount" + + "and second rent date start, end and amount is added" in { + when(mockRaldRepo.findByCredId(any())) thenReturn (Future.successful(Some(RaldUserAnswers(credId = CredId(null), NewAgreement, selectedProperty = property)))) + mockRequest(hasCredId = true) + val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit) + .withFormUrlEncodedBody( + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "yesPayedRent", + "RentPeriodAmount" -> "20000.00", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.year" -> "2026", + "SecondRentPeriodAmount" -> "10000.00", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/what-is-your-rent-based-on") + }) + status(result) mustBe SEE_OTHER + redirectLocation(result) mustBe Some(routes.WhatIsYourRentBasedOnController.show.url) + } + "Return Form with Errors when no day is added to the first periods start date" in { + mockRequest(hasCredId = true) + val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit) + .withFormUrlEncodedBody( + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.day" -> "", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "yesPayedRent", + "RentPeriodAmount" -> "20000.00", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.year" -> "2026", + "SecondRentPeriodAmount" -> "10000.00", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") + }) + status(result) mustBe BAD_REQUEST + val content = contentAsString(result) + content must include(pageTitle) + } + "Return Form with Errors when no month is added to the first periods start date" in { + mockRequest(hasCredId = true) + val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit) + .withFormUrlEncodedBody( + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.month" -> "", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "yesPayedRent", + "RentPeriodAmount" -> "20000.00", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.year" -> "2026", + "SecondRentPeriodAmount" -> "10000.00", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") + }) + status(result) mustBe BAD_REQUEST + val content = contentAsString(result) + content must include(pageTitle) + } + "Return Form with Errors when no year is added to the first periods start date" in { + mockRequest(hasCredId = true) + val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit) + .withFormUrlEncodedBody( + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.year" -> "", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "yesPayedRent", + "RentPeriodAmount" -> "20000.00", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.year" -> "2026", + "SecondRentPeriodAmount" -> "10000.00", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") + }) + status(result) mustBe BAD_REQUEST + val content = contentAsString(result) + content must include(pageTitle) + } + "Return Form with Errors when no day is added to the first periods end date" in { + mockRequest(hasCredId = true) + val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit) + .withFormUrlEncodedBody( + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.day" -> "", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "yesPayedRent", + "RentPeriodAmount" -> "20000.00", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.year" -> "2026", + "SecondRentPeriodAmount" -> "10000.00", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") + }) + status(result) mustBe BAD_REQUEST + val content = contentAsString(result) + content must include(pageTitle) + } + "Return Form with Errors when no month is added to the first periods end date" in { + mockRequest(hasCredId = true) + val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit) + .withFormUrlEncodedBody( + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.month" -> "", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "yesPayedRent", + "RentPeriodAmount" -> "20000.00", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.year" -> "2026", + "SecondRentPeriodAmount" -> "10000.00", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") + }) + status(result) mustBe BAD_REQUEST + val content = contentAsString(result) + content must include(pageTitle) + } + + "Return Form with Errors when no year is added to the first periods end date" in { + mockRequest(hasCredId = true) + val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit) + .withFormUrlEncodedBody( + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.year" -> "", + "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "yesPayedRent", + "RentPeriodAmount" -> "20000.00", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.year" -> "2026", + "SecondRentPeriodAmount" -> "10000.00", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") + }) + status(result) mustBe BAD_REQUEST + val content = contentAsString(result) + content must include(pageTitle) + } + "Return Form with Errors when no day is added to the second period start date" in { + mockRequest(hasCredId = true) + val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit) + .withFormUrlEncodedBody( + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "yesPayedRent", + "RentPeriodAmount" -> "20000.00", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.day" -> "", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.year" -> "2026", + "SecondRentPeriodAmount" -> "10000.00", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") + }) + status(result) mustBe BAD_REQUEST + val content = contentAsString(result) + content must include(pageTitle) + } + + "Return Form with Errors when no month is added to the second period start date" in { + mockRequest(hasCredId = true) + val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit) + .withFormUrlEncodedBody( + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "yesPayedRent", + "RentPeriodAmount" -> "20000.00", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.month" -> "", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.year" -> "2026", + "SecondRentPeriodAmount" -> "10000.00", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") + }) + status(result) mustBe BAD_REQUEST + val content = contentAsString(result) + content must include(pageTitle) + } + "Return Form with Errors when no year is added to the second period start date" in { + mockRequest(hasCredId = true) + val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit) + .withFormUrlEncodedBody( + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "yesPayedRent", + "RentPeriodAmount" -> "20000.00", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.year" -> "", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.year" -> "2026", + "SecondRentPeriodAmount" -> "10000.00", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") + }) + status(result) mustBe BAD_REQUEST + val content = contentAsString(result) + content must include(pageTitle) + } + "Return Form with Errors when no day is added to the second period end date" in { + mockRequest(hasCredId = true) + val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit) + .withFormUrlEncodedBody( + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "yesPayedRent", + "RentPeriodAmount" -> "20000.00", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.day" -> "", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.year" -> "2026", + "SecondRentPeriodAmount" -> "10000.00", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") + }) + status(result) mustBe BAD_REQUEST + val content = contentAsString(result) + content must include(pageTitle) + } + "Return Form with Errors when no month is added to the second period end date" in { + mockRequest(hasCredId = true) + val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit) + .withFormUrlEncodedBody( + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "yesPayedRent", + "RentPeriodAmount" -> "20000.00", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.month" -> "", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.year" -> "2026", + "SecondRentPeriodAmount" -> "10000.00", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") + }) + status(result) mustBe BAD_REQUEST + val content = contentAsString(result) + content must include(pageTitle) + } + "Return Form with Errors when no year is added to the second period end date" in { + mockRequest(hasCredId = true) + val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit) + .withFormUrlEncodedBody( + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "yesPayedRent", + "RentPeriodAmount" -> "20000.00", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.year" -> "", + "SecondRentPeriodAmount" -> "10000.00", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") + }) + status(result) mustBe BAD_REQUEST + val content = contentAsString(result) + content must include(pageTitle) + } + "Return Form with Errors when no first rent period radio is selected" in { + mockRequest(hasCredId = true) + val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit) + .withFormUrlEncodedBody( + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "", + "RentPeriodAmount" -> "20000.00", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.year" -> "2026", + "SecondRentPeriodAmount" -> "10000.00", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") + }) + status(result) mustBe BAD_REQUEST + val content = contentAsString(result) + content must include(pageTitle) + } + "Return Form with Errors when no rent period amount is added and firstRentPeriodRadio has yesPayedRent selected" in { + mockRequest(hasCredId = true) + val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit) + .withFormUrlEncodedBody( + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "yesPayedRent", + "RentPeriodAmount" -> "", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.year" -> "2026", + "SecondRentPeriodAmount" -> "10000.00", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") + }) + status(result) mustBe BAD_REQUEST + val content = contentAsString(result) + content must include(pageTitle) + } + "Return Form with Errors when no rent second period amount is added" in { + mockRequest(hasCredId = true) + val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit) + .withFormUrlEncodedBody( + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "yesPayedRent", + "RentPeriodAmount" -> "20000.00", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.year" -> "2026", + "SecondRentPeriodAmount" -> "", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") + }) + status(result) mustBe BAD_REQUEST + val content = contentAsString(result) + content must include(pageTitle) + } + "Return Form with Errors when no radio is selected for first rent" in { + mockRequest(hasCredId = true) + val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit) + .withFormUrlEncodedBody( + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "", + "RentPeriodAmount" -> "20000.00", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.year" -> "2026", + "SecondRentPeriodAmount" -> "10000", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") + }) + status(result) mustBe BAD_REQUEST + val content = contentAsString(result) + content must include(pageTitle) + } + "Return Form with Errors when format is wrong for RentPeriodAmount" in { + mockRequest(hasCredId = true) + val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit) + .withFormUrlEncodedBody( + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "yesPayedRent", + "RentPeriodAmount" -> "hello", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.year" -> "2026", + "SecondRentPeriodAmount" -> "10000", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") + }) + status(result) mustBe BAD_REQUEST + val content = contentAsString(result) + content must include(pageTitle) + } + "Return Form with Errors when format is wrong for SecondRentPeriodAmount" in { + mockRequest(hasCredId = true) + val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit) + .withFormUrlEncodedBody( + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.firstPeriod.end.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "yesPayedRent", + "RentPeriodAmount" -> "20000.00", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.start.date.year" -> "2026", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.day" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.month" -> "12", + "provideDetailsOfFirstSecondRentPeriod.secondPeriod.end.date.year" -> "2026", + "SecondRentPeriodAmount" -> "hello", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") + }) + status(result) mustBe BAD_REQUEST + val content = contentAsString(result) + content must include(pageTitle) + } + "Return Exception if no address is in the mongo" in { + mockRequestWithoutProperty() + val exception = intercept[NotFoundException] { + await(controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit) + .withFormUrlEncodedBody(("what-type-of-agreement-radio", "")) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some(""))))) + } + exception.getMessage contains "Couldn't find property in mongo" mustBe true + } + } + } +} + + diff --git a/test/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepoSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepoSpec.scala index 729d65dc..426cb7bd 100644 --- a/test/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepoSpec.scala +++ b/test/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepoSpec.scala @@ -23,7 +23,7 @@ import uk.gov.hmrc.mongo.test.DefaultPlayMongoRepositorySupport import uk.gov.hmrc.ngrraldfrontend.helpers.{TestData, TestSupport} import uk.gov.hmrc.ngrraldfrontend.models.AgreementType.NewAgreement import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId -import uk.gov.hmrc.ngrraldfrontend.models.{Agreement, AgreementVerbal, Landlord, RaldUserAnswers, RentBasedOn} +import uk.gov.hmrc.ngrraldfrontend.models.* class RaldRepoSpec extends TestSupport with TestData with DefaultPlayMongoRepositorySupport[RaldUserAnswers] { @@ -213,7 +213,6 @@ class RaldRepoSpec extends TestSupport with TestData "insert agreement with no break clause info and no open end date successfully" in { val agreementStart = "12-12-2026" val openEndedRadio = "YesOpenEnded" - val openEndedDate = None val breakClauseRadio = "NoBreakClause" val breakClauseInfo = None @@ -248,6 +247,40 @@ class RaldRepoSpec extends TestSupport with TestData ) } + "handle non-yesPayedRent value correctly by setting boolean to false" in { + val result = await(repository.insertProvideDetailsOfFirstSecondRentPeriod( + credId = credId, + firstDateStart = "2025-01-01", + firstDateEnd = "2025-01-31", + firstRentPeriodRadio = "noRentPaid", + firstRentPeriodAmount = None, + secondDateStart = "2025-02-01", + secondDateEnd = "2025-02-28", + secondHowMuchIsRent = BigDecimal(1000) + )) + + val actual = await(repository.findByCredId(credId)) + + result mustBe actual + } + + "handle yesPayedRent value correctly by setting boolean to true and take first rent period amount" in { + val result = await(repository.insertProvideDetailsOfFirstSecondRentPeriod( + credId = credId, + firstDateStart = "2025-01-01", + firstDateEnd = "2025-01-31", + firstRentPeriodRadio = "yesPayedRent", + firstRentPeriodAmount = Some(1000), + secondDateStart = "2025-02-01", + secondDateEnd = "2025-02-28", + secondHowMuchIsRent = BigDecimal(1000) + )) + + val actual = await(repository.findByCredId(credId)) + + result mustBe actual + } + "insert rent based on with other desc successfully" in { await( repository.insertRentBased( @@ -304,7 +337,7 @@ class RaldRepoSpec extends TestSupport with TestData actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, agreedRentChange = Some("Yes"))) } - "insert hasRentFreePeriod successfully" in { + "insert hasRentFreePeriod successfully with Yes" in { val hasRentFreePeriod = "Yes" await(repository.insertHasRentFreePeriod(credId, hasRentFreePeriod)) @@ -312,6 +345,14 @@ class RaldRepoSpec extends TestSupport with TestData actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, hasRentFreePeriod = Some(true))) } + "insert hasRentFreePeriod successfully with No" in { + val hasRentFreePeriod = "No" + + await(repository.insertHasRentFreePeriod(credId, hasRentFreePeriod)) + val actual = await(repository.findByCredId(credId)) + actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, hasRentFreePeriod = Some(false))) + } + "credId doesn't exist in mongoDB" in { val actual = await(repository.findByCredId(credId2)) actual mustBe None