diff --git a/app/uk/gov/hmrc/ngrraldfrontend/actions/DataRetrievalAction.scala b/app/uk/gov/hmrc/ngrraldfrontend/actions/DataRetrievalAction.scala
new file mode 100644
index 00000000..4d348384
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/actions/DataRetrievalAction.scala
@@ -0,0 +1,53 @@
+/*
+ * 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.actions
+
+import play.api.mvc.Results.Redirect
+import play.api.mvc.{ActionTransformer, Result}
+import uk.gov.hmrc.http.{HeaderCarrier, NotFoundException}
+import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.connectors.NGRConnector
+import uk.gov.hmrc.ngrraldfrontend.models.AuthenticatedUserRequest
+import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
+import uk.gov.hmrc.ngrraldfrontend.models.requests.{IdentifierRequest, OptionalDataRequest}
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
+import uk.gov.hmrc.play.http.HeaderCarrierConverter
+
+import javax.inject.Inject
+import scala.concurrent.{ExecutionContext, Future}
+
+class DataRetrievalActionImpl @Inject()(
+ val sessionRepository: SessionRepository,
+ ngrConnector: NGRConnector,
+ appConfig: AppConfig
+ )(implicit val executionContext: ExecutionContext) extends DataRetrievalAction {
+
+ override protected def transform[A](request: AuthenticatedUserRequest[A]): Future[OptionalDataRequest[A]] = {
+
+ implicit val hc: HeaderCarrier = HeaderCarrierConverter.fromRequestAndSession(request, request.session)
+
+ sessionRepository.get(request.credId.getOrElse("")).flatMap { userAnswersOpt =>
+ ngrConnector.getLinkedProperty(CredId(request.credId.getOrElse(""))).map {
+ case Some(property) =>
+ OptionalDataRequest(request.request, request.credId.getOrElse(""), userAnswersOpt, property)
+ case None => throw new NotFoundException("Property not found")
+ }
+ }
+ }
+}
+
+trait DataRetrievalAction extends ActionTransformer[AuthenticatedUserRequest, OptionalDataRequest]
\ No newline at end of file
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/actions/PropertyLinkingAction.scala b/app/uk/gov/hmrc/ngrraldfrontend/actions/PropertyLinkingAction.scala
deleted file mode 100644
index 7ec05dbe..00000000
--- a/app/uk/gov/hmrc/ngrraldfrontend/actions/PropertyLinkingAction.scala
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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.actions
-
-import com.google.inject.ImplementedBy
-import play.api.mvc.*
-import play.api.mvc.Results.Redirect
-import uk.gov.hmrc.http.HeaderCarrier
-import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
-import uk.gov.hmrc.ngrraldfrontend.connectors.NGRConnector
-import uk.gov.hmrc.ngrraldfrontend.models.AuthenticatedUserRequest
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
-import uk.gov.hmrc.play.http.HeaderCarrierConverter
-
-import javax.inject.Inject
-import scala.concurrent.{ExecutionContext, Future}
-
-class PropertyLinkingActionImpl @Inject()(
- ngrConnector: NGRConnector,
- authenticate: AuthRetrievals,
- raldRepo: RaldRepo,
- appConfig: AppConfig,
- mcc: MessagesControllerComponents
- )(implicit ec: ExecutionContext) extends PropertyLinkingAction {
-
- override def invokeBlock[A](request: Request[A], block: AuthenticatedUserRequest[A] => Future[Result]): Future[Result] = {
-
- authenticate.invokeBlock(request, { implicit authRequest: AuthenticatedUserRequest[A] =>
- implicit val hc: HeaderCarrier = HeaderCarrierConverter.fromRequestAndSession(authRequest, authRequest.session)
-
- val credId = CredId(authRequest.credId.getOrElse(""))
- raldRepo.findByCredId(credId).flatMap {
- case Some(property) => block(authRequest.copy(propertyLinking = Some(property.selectedProperty)))
- case _ => ngrConnector.getLinkedProperty(credId).flatMap { property =>
- if (property.isDefined) {
- block(authRequest.copy(propertyLinking = property))
- } else {
- redirectToDashboard()
- }
- }
- }
- })
- }
-
- private def redirectToDashboard(): Future[Result] = {
- Future.successful(Redirect(s"${appConfig.ngrDashboardUrl}/dashboard"))
- }
-
- // $COVERAGE-OFF$
- override def parser: BodyParser[AnyContent] = mcc.parsers.defaultBodyParser
-
- override protected def executionContext: ExecutionContext = ec
- // $COVERAGE-ON$
-
-}
-
-@ImplementedBy(classOf[PropertyLinkingActionImpl])
-trait PropertyLinkingAction extends ActionBuilder[AuthenticatedUserRequest, AnyContent] with ActionFunction[Request, AuthenticatedUserRequest]
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/config/AppConfig.scala b/app/uk/gov/hmrc/ngrraldfrontend/config/AppConfig.scala
index 7f56b3d2..9f94674c 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/config/AppConfig.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/config/AppConfig.scala
@@ -28,8 +28,8 @@ trait AppConfig {
val ngrLoginRegistrationHost: String
val ngrDashboardUrl: String
val ngrLogoutUrl: String
- val timeToLive: String
def getString(key: String): String
+ val cacheTtl: Long
}
@Singleton
@@ -37,9 +37,9 @@ class FrontendAppConfig @Inject()(config: Configuration, servicesConfig: Service
override val features = new Features()(config)
override val nextGenerationRatesHost: String = servicesConfig.baseUrl("next-generation-rates")
override val ngrLoginRegistrationHost: String = servicesConfig.baseUrl("ngr-login-register-frontend")
- override val timeToLive: String = servicesConfig.getString("time-to-live.time")
override val ngrDashboardUrl: String = s"$dashboardHost/ngr-dashboard-frontend/dashboard"
override val ngrLogoutUrl: String = s"$dashboardHost/ngr-dashboard-frontend/signout"
+ override val cacheTtl: Long = config.get[Int]("mongodb.timeToLiveInSeconds")
def getString(key: String): String =
config.getOptional[String](key).filter(!_.isBlank).getOrElse(throwConfigNotFoundError(key))
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/config/Module.scala b/app/uk/gov/hmrc/ngrraldfrontend/config/Module.scala
index 09fde51a..b877e7c2 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/config/Module.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/config/Module.scala
@@ -17,12 +17,16 @@
package uk.gov.hmrc.ngrraldfrontend.config
import com.google.inject.AbstractModule
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, AuthRetrievalsImpl}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, AuthRetrievalsImpl, DataRetrievalAction, DataRetrievalActionImpl}
+
+import java.time.{Clock, ZoneOffset}
class Module extends AbstractModule {
override def configure(): Unit = {
bind(classOf[AppConfig]).to(classOf[FrontendAppConfig]).asEagerSingleton()
bind(classOf[AuthRetrievals]).to(classOf[AuthRetrievalsImpl]).asEagerSingleton()
+ bind(classOf[DataRetrievalAction]).to(classOf[DataRetrievalActionImpl]).asEagerSingleton()
+ bind(classOf[Clock]).toInstance(Clock.systemDefaultZone.withZone(ZoneOffset.UTC))
}
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/connectors/NGRConnector.scala b/app/uk/gov/hmrc/ngrraldfrontend/connectors/NGRConnector.scala
index 15b083b1..8e0a1371 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/connectors/NGRConnector.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/connectors/NGRConnector.scala
@@ -51,7 +51,7 @@ class NGRConnector @Inject()(http: HttpClientV2,
getPropertyLinkingUserAnswers(credId)
.map {
case Some(propertyLinkingUserAnswers) => Some(propertyLinkingUserAnswers.vmvProperty)
- case None => throw new NotFoundException("failed to find propertyLinkingUserAnswers from backend mongo")
+ case None => None
}
}
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/AgreedRentChangeController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/AgreedRentChangeController.scala
index 01a87e2a..6ccf3eb4 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/AgreedRentChangeController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/AgreedRentChangeController.scala
@@ -18,14 +18,15 @@ package uk.gov.hmrc.ngrraldfrontend.controllers
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
-import uk.gov.hmrc.http.NotFoundException
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.{Mode, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
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
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.AgreedRentChangePage
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.views.html.AgreedRentChangeView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
@@ -35,44 +36,44 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class AgreedRentChangeController @Inject()(agreedRentChangeView: AgreedRentChangeView,
authenticate: AuthRetrievals,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
+ getData: DataRetrievalAction,
+ sessionRepository: SessionRepository,
+ navigator: Navigator,
mcc: MessagesControllerComponents)(implicit appConfig: AppConfig, ec: ExecutionContext)
extends FrontendController(mcc) with I18nSupport {
- def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
+ def show(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(AgreedRentChangePage) match {
+ case None => form
+ case Some(value) => form.fill(AgreedRentChangeForm(value))
+ }
Future.successful(Ok(agreedRentChangeView(
- form = form,
- radios = buildRadios(form, AgreedRentChangeForm.ngrRadio(form)),
- propertyAddress = property.addressFull,
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ form = preparedForm,
+ radios = buildRadios(preparedForm, AgreedRentChangeForm.ngrRadio(preparedForm)),
+ propertyAddress = request.property.addressFull,
+ mode = mode
+ )))
}
}
- def submit: Action[AnyContent] =
- (authenticate andThen hasLinkedProperties).async { implicit request =>
+ def submit(mode: Mode): Action[AnyContent] =
+ (authenticate andThen getData).async { implicit request =>
form.bindFromRequest().fold(
formWithErrors => {
- request.propertyLinking.map(property =>
Future.successful(BadRequest(agreedRentChangeView(
form = formWithErrors,
radios = buildRadios(formWithErrors, AgreedRentChangeForm.ngrRadio(formWithErrors)),
- propertyAddress = property.addressFull
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ propertyAddress = request.property.addressFull,
+ mode = mode
+ )))
},
radioValue =>
- raldRepo.insertAgreedRentChange(
- credId = CredId(request.credId.getOrElse("")),
- agreedRentChange = radioValue.radioValue
- )
- if (radioValue.radioValue == "Yes") {
- Future.successful(Redirect(routes.ProvideDetailsOfFirstSecondRentPeriodController.show.url))
- } else {
- Future.successful(Redirect(routes.HowMuchIsTotalAnnualRentController.show.url))
- }
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(AgreedRentChangePage, radioValue.radioValue))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(AgreedRentChangePage, mode, updatedAnswers))
)
}
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/AgreementController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/AgreementController.scala
index 4aa7b9bb..103d1837 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/AgreementController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/AgreementController.scala
@@ -22,15 +22,16 @@ import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.govukfrontend.views.Aliases.*
import uk.gov.hmrc.govukfrontend.views.html.components.ErrorMessage
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.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.{Mode, Agreement, NGRDate, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.components.*
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.forms.AgreementForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.AgreementForm.form
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.AgreementPage
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.views.html.AgreementView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.{DateTextFields, NGRCharacterCountComponent}
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
@@ -42,10 +43,11 @@ import scala.concurrent.{ExecutionContext, Future}
class AgreementController @Inject()(view: AgreementView,
authenticate: AuthRetrievals,
dateTextFields: DateTextFields,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
ngrCharacterCountComponent: NGRCharacterCountComponent,
- mcc: MessagesControllerComponents
+ mcc: MessagesControllerComponents,
+ getData: DataRetrievalAction,
+ navigator: Navigator,
+ sessionRepository: SessionRepository
)(implicit appConfig: AppConfig, ec: ExecutionContext) extends FrontendController(mcc) with I18nSupport {
def dateInput()(implicit messages: Messages): DateInput = DateInput(
@@ -133,22 +135,36 @@ class AgreementController @Inject()(view: AgreementView,
}
- def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
- Future.successful(Ok(view(
- selectedPropertyAddress = property.addressFull,
- form,
- dateInput(),
- buildRadios(form, openEndedRadio(form)),
- buildRadios(form, breakClauseRadio(form))
- )))
- ).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ def show(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(AgreementPage) match {
+ case None => form
+ case Some(value) => form.fill(AgreementForm(NGRDate.fromString(value.agreementStart), if (value.isOpenEnded) {
+ "YesOpenEnded"
+ } else {
+ "NoOpenEnded"
+ }, value.openEndedDate match {
+ case Some(value) => Some(NGRDate.fromString(value))
+ case None => None
+ }, if (value.haveBreakClause) {
+ "YesBreakClause"
+ } else {
+ "NoBreakClause"
+ }, value.breakClauseInfo))
+ }
+ Future.successful(Ok(view(
+ selectedPropertyAddress = request.property.addressFull,
+ preparedForm,
+ dateInput(),
+ buildRadios(preparedForm, openEndedRadio(preparedForm)),
+ buildRadios(preparedForm, breakClauseRadio(preparedForm)),
+ mode = mode
+ )))
}
}
- def submit: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
+ def submit(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
form
.bindFromRequest()
.fold(
@@ -166,24 +182,30 @@ class AgreementController @Inject()(view: AgreementView,
}
val formWithCorrectedErrors = formWithErrors.copy(errors = correctedFormErrors)
- request.propertyLinking.map(property =>
Future.successful(BadRequest(view(
- selectedPropertyAddress = property.addressFull,
+ selectedPropertyAddress = request.property.addressFull,
formWithCorrectedErrors,
dateInput(),
buildRadios(formWithErrors, openEndedRadio(formWithCorrectedErrors)),
- buildRadios(formWithErrors, breakClauseRadio(formWithCorrectedErrors))
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo")),
+ buildRadios(formWithErrors, breakClauseRadio(formWithCorrectedErrors)),
+ mode = mode
+ ))),
agreementForm =>
- raldRepo.insertAgreement(
- CredId(request.credId.getOrElse("")),
- agreementForm.agreementStart.makeString,
- agreementForm.openEndedRadio,
+ val answers = Agreement(agreementForm.agreementStart.makeString,
+ agreementForm.openEndedRadio match {
+ case answer if(answer == "YesOpenEnded") => true
+ case _ => false
+ },
agreementForm.openEndedDate.map(value => value.makeString),
- agreementForm.breakClauseRadio,
- agreementForm.breakClauseInfo,
- )
- Future.successful(Redirect(routes.WhatIsYourRentBasedOnController.show.url))
+ agreementForm.breakClauseRadio match {
+ case openEndedRadio if(openEndedRadio == "YesBreakClause") => true
+ case _ => false
+ },
+ agreementForm.breakClauseInfo)
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(AgreementPage, answers))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(AgreementPage, mode, updatedAnswers))
)
}
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/AgreementVerbalController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/AgreementVerbalController.scala
index 60472cd6..1413d4ed 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/AgreementVerbalController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/AgreementVerbalController.scala
@@ -24,14 +24,16 @@ import uk.gov.hmrc.govukfrontend.views.viewmodels.dateinput.DateInput
import uk.gov.hmrc.govukfrontend.views.viewmodels.fieldset.Fieldset
import uk.gov.hmrc.govukfrontend.views.viewmodels.hint.Hint
import uk.gov.hmrc.http.NotFoundException
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.{Mode, AgreementVerbal, NGRDate, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.components.*
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.forms.AgreementVerbalForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.AgreementVerbalForm.form
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.AgreementVerbalPage
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.views.html.AgreementVerbalView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.DateTextFields
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
@@ -42,10 +44,11 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class AgreementVerbalController @Inject()(view: AgreementVerbalView,
authenticate: AuthRetrievals,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
dateTextFields: DateTextFields,
- mcc: MessagesControllerComponents
+ mcc: MessagesControllerComponents,
+ getData: DataRetrievalAction,
+ sessionRepository: SessionRepository,
+ navigator: Navigator
)(implicit appConfig: AppConfig, ec: ExecutionContext) extends FrontendController(mcc) with I18nSupport {
val yesButton: NGRRadioButtons = NGRRadioButtons("agreementVerbal.yes", Yes)
@@ -63,16 +66,25 @@ class AgreementVerbalController @Inject()(view: AgreementVerbalView,
Some(Legend(content = Text(messages("agreementVerbal.radio.title")), classes = "govuk-fieldset__legend--m", isPageHeading = true)),
Some("agreementVerbal.radio.hint"))
- def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
- Future.successful(Ok(view(form, buildRadios(form, ngrRadio(form)), property.addressFull)))
- ).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ def show(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(AgreementVerbalPage) match {
+ case None => form
+ case Some(value) => form.fill(AgreementVerbalForm(if (value.openEnded) {
+ "Yes"
+ } else {
+ "No"
+ },NGRDate.fromString(value.startDate), value.endDate match {
+ case Some(value) => Some(NGRDate.fromString(value))
+ case None => None
+ }))
+ }
+ Future.successful(Ok(view(preparedForm, buildRadios(preparedForm, ngrRadio(preparedForm)), request.property.addressFull, mode)))
}
}
- def submit: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
+ def submit(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
form
.bindFromRequest()
.fold(
@@ -97,20 +109,19 @@ class AgreementVerbalController @Inject()(view: AgreementVerbalView,
formError
}
val formWithCorrectedErrors = formWithErrors.copy(errors = correctedFormErrors)
-
- request.propertyLinking.map(property =>
Future.successful(BadRequest(view(formWithCorrectedErrors,
- buildRadios(formWithErrors, ngrRadio(formWithCorrectedErrors)), property.addressFull))))
- .getOrElse(throw new NotFoundException("Couldn't find property in mongo")),
+ buildRadios(formWithErrors, ngrRadio(formWithCorrectedErrors)), request.property.addressFull, mode))),
agreementVerbalForm =>
val openEnded: Boolean = agreementVerbalForm.radioValue.equals("Yes")
- raldRepo.insertAgreementVerbal(
- CredId(request.credId.getOrElse("")),
+ val answers: AgreementVerbal = AgreementVerbal(
agreementVerbalForm.agreementStartDate.makeString,
openEnded,
- if (openEnded) None else agreementVerbalForm.agreementEndDate.map(_.makeString)
- )
- Future.successful(Redirect(routes.HowMuchIsTotalAnnualRentController.show.url))
+ if (openEnded) None else agreementVerbalForm.agreementEndDate.map(_.makeString))
+
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(AgreementVerbalPage, answers))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(AgreementVerbalPage, mode, updatedAnswers))
)
}
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/CheckRentFreePeriodController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/CheckRentFreePeriodController.scala
index bb16c35e..3b73ce47 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/CheckRentFreePeriodController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/CheckRentFreePeriodController.scala
@@ -19,13 +19,15 @@ package uk.gov.hmrc.ngrraldfrontend.controllers
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.http.NotFoundException
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.{Landlord, Mode, NormalMode, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.forms.CheckRentFreePeriodForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.CheckRentFreePeriodForm.form
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.CheckRentFreePeriodPage
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.views.html.CheckRentFreePeriodView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
@@ -34,42 +36,45 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class CheckRentFreePeriodController @Inject()(checkRentFreePeriodView: CheckRentFreePeriodView,
- authenticate: AuthRetrievals,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
+ authenticate : AuthRetrievals,
+ getData: DataRetrievalAction,
+ navigator: Navigator,
+ sessionRepository: SessionRepository,
mcc: MessagesControllerComponents)(implicit appConfig: AppConfig, ec: ExecutionContext)
extends FrontendController(mcc) with I18nSupport {
- def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
+ def show(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(CheckRentFreePeriodPage) match {
+ case None => form
+ case Some(value) => form.fill(CheckRentFreePeriodForm(value))
+ }
Future.successful(Ok(checkRentFreePeriodView(
- form = form,
- radios = buildRadios(form, CheckRentFreePeriodForm.ngrRadio(form)),
- propertyAddress = property.addressFull,
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ form = preparedForm,
+ radios = buildRadios(preparedForm, CheckRentFreePeriodForm.ngrRadio(preparedForm)),
+ propertyAddress = request.property.addressFull,
+ mode = mode
+ )))
}
}
- def submit: Action[AnyContent] =
- (authenticate andThen hasLinkedProperties).async { implicit request =>
+ def submit(mode: Mode): Action[AnyContent] =
+ (authenticate andThen getData).async { implicit request =>
form.bindFromRequest().fold(
formWithErrors => {
- request.propertyLinking.map(property =>
Future.successful(BadRequest(checkRentFreePeriodView(
form = formWithErrors,
radios = buildRadios(formWithErrors, CheckRentFreePeriodForm.ngrRadio(formWithErrors)),
- propertyAddress = property.addressFull
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ propertyAddress = request.property.addressFull,
+ mode = mode
+ )))
},
radioValue =>
- raldRepo.insertHasRentFreePeriod(
- credId = CredId(request.credId.getOrElse("")),
- hasRentFreePeriod = radioValue.radioValue
- )
- radioValue.radioValue match
- case "No" => Future.successful(Redirect(routes.RentDatesAgreeStartController.show.url))
- case _ => Future.successful(Redirect(routes.RentFreePeriodController.show.url))
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId))
+ .set(CheckRentFreePeriodPage, radioValue.radioValue))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(CheckRentFreePeriodPage, mode, updatedAnswers))
)
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouAgreeRentWithLandlordController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouAgreeRentWithLandlordController.scala
index e840f456..655d1a9a 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouAgreeRentWithLandlordController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouAgreeRentWithLandlordController.scala
@@ -18,15 +18,16 @@ package uk.gov.hmrc.ngrraldfrontend.controllers
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
-import uk.gov.hmrc.http.NotFoundException
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.{Mode, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.components.*
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.forms.DidYouAgreeRentWithLandlordForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.DidYouAgreeRentWithLandlordForm.form
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.DidYouAgreeRentWithLandlordPage
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.views.html.DidYouAgreeRentWithLandlordView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
@@ -36,45 +37,44 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class DidYouAgreeRentWithLandlordController @Inject()(didYouAgreeRentWithLandlordView: DidYouAgreeRentWithLandlordView,
authenticate: AuthRetrievals,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
+ getData: DataRetrievalAction,
+ sessionRepository: SessionRepository,
+ navigator: Navigator,
mcc: MessagesControllerComponents)(implicit appConfig: AppConfig, ec: ExecutionContext)
extends FrontendController(mcc) with I18nSupport {
- def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
+ def show(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(DidYouAgreeRentWithLandlordPage) match {
+ case None => form
+ case Some(value) => form.fill(DidYouAgreeRentWithLandlordForm(value))
+ }
Future.successful(Ok(didYouAgreeRentWithLandlordView(
- selectedPropertyAddress = property.addressFull,
- form = form,
- ngrRadio = buildRadios(form, DidYouAgreeRentWithLandlordForm.ngrRadio(form)),
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ selectedPropertyAddress = request.property.addressFull,
+ form = preparedForm,
+ ngrRadio = buildRadios(preparedForm, DidYouAgreeRentWithLandlordForm.ngrRadio(preparedForm)),
+ mode = mode
+ )))
}
}
- def submit: Action[AnyContent] =
- (authenticate andThen hasLinkedProperties).async { implicit request =>
+ def submit(mode: Mode): Action[AnyContent] =
+ (authenticate andThen getData).async { implicit request =>
form.bindFromRequest().fold(
formWithErrors => {
- request.propertyLinking.map(property =>
Future.successful(BadRequest(didYouAgreeRentWithLandlordView(
form = formWithErrors,
ngrRadio = buildRadios(formWithErrors, DidYouAgreeRentWithLandlordForm.ngrRadio(formWithErrors)),
- selectedPropertyAddress = property.addressFull
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ selectedPropertyAddress = request.property.addressFull,
+ mode = mode
+ )))
},
radioValue =>
- raldRepo.insertDidYouAgreeRentWithLandlord(
- credId = CredId(request.credId.getOrElse("")),
- radioValue = radioValue.toString
- )
- if (radioValue.radioValue.toString == "YesTheLandlord") {
- Future.successful(Redirect(routes.CheckRentFreePeriodController.show.url))
- } else {
- //TODO
- Future.successful(Redirect(routes.CheckRentFreePeriodController.show.url))
- }
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(DidYouAgreeRentWithLandlordPage, radioValue.radioValue))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(DidYouAgreeRentWithLandlordPage, mode, updatedAnswers))
)
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/DoesYourRentIncludeParkingController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/DoesYourRentIncludeParkingController.scala
index 2ccaf5bd..d7b18ed6 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/DoesYourRentIncludeParkingController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/DoesYourRentIncludeParkingController.scala
@@ -18,14 +18,15 @@ package uk.gov.hmrc.ngrraldfrontend.controllers
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
-import uk.gov.hmrc.http.NotFoundException
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.{Mode, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.forms.DoesYourRentIncludeParkingForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.DoesYourRentIncludeParkingForm.form
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.DoesYourRentIncludeParkingPage
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.views.html.DoesYourRentIncludeParkingView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
@@ -34,45 +35,45 @@ import scala.concurrent.{ExecutionContext, Future}
class DoesYourRentIncludeParkingController @Inject()(doesYourRentIncludeParkingView: DoesYourRentIncludeParkingView,
authenticate: AuthRetrievals,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
+ getData: DataRetrievalAction,
+ sessionRepository: SessionRepository,
+ navigator: Navigator,
mcc: MessagesControllerComponents)(implicit appConfig: AppConfig, ec: ExecutionContext)
extends FrontendController(mcc) with I18nSupport {
- def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
+ def show(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(DoesYourRentIncludeParkingPage) match {
+ case None => form
+ case Some(value) => form.fill(DoesYourRentIncludeParkingForm(value))
+
+ }
Future.successful(Ok(doesYourRentIncludeParkingView(
- selectedPropertyAddress = property.addressFull,
- form = form,
- ngrRadio = buildRadios(form, DoesYourRentIncludeParkingForm.ngrRadio(form)),
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ selectedPropertyAddress = request.property.addressFull,
+ form = preparedForm,
+ ngrRadio = buildRadios(preparedForm, DoesYourRentIncludeParkingForm.ngrRadio(preparedForm)),
+ mode = mode
+ )))
}
}
- def submit: Action[AnyContent] =
- (authenticate andThen hasLinkedProperties).async { implicit request =>
+ def submit(mode: Mode): Action[AnyContent] =
+ (authenticate andThen getData).async { implicit request =>
form.bindFromRequest().fold(
formWithErrors => {
- request.propertyLinking.map(property =>
Future.successful(BadRequest(doesYourRentIncludeParkingView(
form = formWithErrors,
ngrRadio = buildRadios(formWithErrors, DoesYourRentIncludeParkingForm.ngrRadio(formWithErrors)),
- selectedPropertyAddress = property.addressFull
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ selectedPropertyAddress = request.property.addressFull,
+ mode = mode
+ )))
},
radioValue =>
- raldRepo.insertDoesYourRentIncludeParking(
- credId = CredId(request.credId.getOrElse("")),
- radioValue = radioValue.radio
- )
- if (radioValue.radio == "Yes") {
- Future.successful(Redirect(routes.HowManyParkingSpacesOrGaragesIncludedInRentController.show.url))
- } else {
- //TODO
- Future.successful(Redirect(routes.CheckRentFreePeriodController.show.url))
- }
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(DoesYourRentIncludeParkingPage, radioValue.radio))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(DoesYourRentIncludeParkingPage, mode, updatedAnswers))
)
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/HowManyParkingSpacesOrGaragesIncludedInRentController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/HowManyParkingSpacesOrGaragesIncludedInRentController.scala
index 4345074a..74b051bc 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/HowManyParkingSpacesOrGaragesIncludedInRentController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/HowManyParkingSpacesOrGaragesIncludedInRentController.scala
@@ -20,13 +20,14 @@ import play.api.data.{Form, FormError}
import play.api.i18n.{I18nSupport, Messages}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import play.twirl.api.HtmlFormat
-import uk.gov.hmrc.http.NotFoundException
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.{HowManyParkingSpacesOrGarages, Mode, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.forms.HowManyParkingSpacesOrGaragesIncludedInRentForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.HowManyParkingSpacesOrGaragesIncludedInRentForm.form
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.HowManyParkingSpacesOrGaragesIncludedInRentPage
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.views.html.HowManyParkingSpacesOrGaragesIncludedInRentView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.InputText
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
@@ -37,8 +38,9 @@ import scala.concurrent.{ExecutionContext, Future}
class HowManyParkingSpacesOrGaragesIncludedInRentController @Inject()(howManyParkingSpacesOrGaragesIncludedInRentView: HowManyParkingSpacesOrGaragesIncludedInRentView,
authenticate: AuthRetrievals,
inputText: InputText,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
+ getData: DataRetrievalAction,
+ sessionRepository: SessionRepository,
+ navigator: Navigator,
mcc: MessagesControllerComponents)(implicit appConfig: AppConfig, ec: ExecutionContext)
extends FrontendController(mcc) with I18nSupport {
@@ -56,21 +58,25 @@ class HowManyParkingSpacesOrGaragesIncludedInRentController @Inject()(howManyPar
}
- def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
+ def show(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(HowManyParkingSpacesOrGaragesIncludedInRentPage) match {
+ case None => form
+ case Some(value) => form.fill(HowManyParkingSpacesOrGaragesIncludedInRentForm(value.uncoveredSpaces.toInt, value.coveredSpaces.toInt, value.garages.toInt))
+ }
Future.successful(Ok(howManyParkingSpacesOrGaragesIncludedInRentView(
- form = form,
- propertyAddress = property.addressFull,
- uncoveredSpaces = generateInputText(form, "uncoveredSpaces"),
- coveredSpaces = generateInputText(form, "coveredSpaces"),
- garages = generateInputText(form, "garages"),
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ form = preparedForm,
+ propertyAddress = request.property.addressFull,
+ uncoveredSpaces = generateInputText(preparedForm, "uncoveredSpaces"),
+ coveredSpaces = generateInputText(preparedForm, "coveredSpaces"),
+ garages = generateInputText(preparedForm, "garages"),
+ mode = mode
+ )))
}
}
- def submit: Action[AnyContent] =
- (authenticate andThen hasLinkedProperties).async { implicit request =>
+ def submit(mode: Mode): Action[AnyContent] =
+ (authenticate andThen getData).async { implicit request =>
form.bindFromRequest().fold(
formWithErrors => {
val formWithCorrectedErrors = formWithErrors.errors.head match {
@@ -83,24 +89,21 @@ class HowManyParkingSpacesOrGaragesIncludedInRentController @Inject()(howManyPar
formWithErrors.copy(errors = Seq(uncoveredSpaces, coveredSpaces, garages))
case _ => formWithErrors
}
-
- request.propertyLinking.map(property =>
Future.successful(BadRequest(howManyParkingSpacesOrGaragesIncludedInRentView(
form = formWithCorrectedErrors,
- propertyAddress = property.addressFull,
+ propertyAddress = request.property.addressFull,
uncoveredSpaces = generateInputText(formWithCorrectedErrors, "uncoveredSpaces"),
coveredSpaces = generateInputText(formWithCorrectedErrors, "coveredSpaces"),
- garages = generateInputText(formWithCorrectedErrors, "garages")
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ garages = generateInputText(formWithCorrectedErrors, "garages"),
+ mode = mode
+ )))
},
- rentAmount =>
- raldRepo.insertHowManyParkingSpacesOrGaragesIncludedInRent(
- credId = CredId(request.credId.getOrElse("")),
- uncoveredSpaces = if(rentAmount.uncoveredSpaces == -1) 0 else rentAmount.uncoveredSpaces,
- coveredSpaces = if(rentAmount.coveredSpaces == -1) 0 else rentAmount.coveredSpaces,
- garages = if(rentAmount.garages == -1) 0 else rentAmount.garages
- )
- Future.successful(Redirect(routes.CheckRentFreePeriodController.show.url))
+ parkingSpacesOrGaragesIncluded =>
+ val answers = HowManyParkingSpacesOrGarages(parkingSpacesOrGaragesIncluded.uncoveredSpaces.toString, parkingSpacesOrGaragesIncluded.coveredSpaces.toString, parkingSpacesOrGaragesIncluded.garages.toString)
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(HowManyParkingSpacesOrGaragesIncludedInRentPage, answers))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(HowManyParkingSpacesOrGaragesIncludedInRentPage, mode, updatedAnswers))
)
}
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/HowMuchIsTotalAnnualRentController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/HowMuchIsTotalAnnualRentController.scala
index 50864e04..ee7acb01 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/HowMuchIsTotalAnnualRentController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/HowMuchIsTotalAnnualRentController.scala
@@ -18,13 +18,14 @@ package uk.gov.hmrc.ngrraldfrontend.controllers
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
-import uk.gov.hmrc.http.NotFoundException
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.{Mode, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.forms.HowMuchIsTotalAnnualRentForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.HowMuchIsTotalAnnualRentForm.form
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.HowMuchIsTotalAnnualRentPage
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.views.html.HowMuchIsTotalAnnualRentView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
@@ -34,38 +35,42 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class HowMuchIsTotalAnnualRentController @Inject()(howMuchIsTotalAnnualRentView: HowMuchIsTotalAnnualRentView,
authenticate: AuthRetrievals,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
+ getData: DataRetrievalAction,
+ sessionRepository: SessionRepository,
+ navigator: Navigator,
mcc: MessagesControllerComponents)(implicit appConfig: AppConfig, ec: ExecutionContext)
extends FrontendController(mcc) with I18nSupport {
- def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
+ def show(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(HowMuchIsTotalAnnualRentPage) match {
+ case None => form
+ case Some(value) => form.fill(HowMuchIsTotalAnnualRentForm(value))
+ }
Future.successful(Ok(howMuchIsTotalAnnualRentView(
- form = form,
- propertyAddress = property.addressFull,
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ form = preparedForm,
+ propertyAddress = request.property.addressFull,
+ mode = mode
+ )))
}
}
- def submit: Action[AnyContent] =
- (authenticate andThen hasLinkedProperties).async { implicit request =>
+ def submit(mode: Mode): Action[AnyContent] =
+ (authenticate andThen getData).async { implicit request =>
form.bindFromRequest().fold(
formWithErrors => {
- request.propertyLinking.map(property =>
Future.successful(BadRequest(howMuchIsTotalAnnualRentView(
form = formWithErrors,
- propertyAddress = property.addressFull
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ propertyAddress = request.property.addressFull,
+ mode = mode
+ )))
},
rentAmount =>
- raldRepo.insertAnnualRent(
- credId = CredId(request.credId.getOrElse("")),
- rentAmount = rentAmount.annualRent
- )
- Future.successful(Redirect(routes.CheckRentFreePeriodController.show.url))
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(HowMuchIsTotalAnnualRentPage, rentAmount.annualRent))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(HowMuchIsTotalAnnualRentPage, mode, updatedAnswers))
)
}
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/InterimRentSetByTheCourtController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/InterimRentSetByTheCourtController.scala
index 00600d15..b05a0393 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/InterimRentSetByTheCourtController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/InterimRentSetByTheCourtController.scala
@@ -21,13 +21,14 @@ import play.api.i18n.{I18nSupport, Messages}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import play.twirl.api.HtmlFormat
import uk.gov.hmrc.govukfrontend.views.Aliases.{Hint, PrefixOrSuffix, Text}
-import uk.gov.hmrc.http.NotFoundException
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.{InterimRentSetByTheCourt, Mode, NGRMonthYear, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.forms.InterimRentSetByTheCourtForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.InterimRentSetByTheCourtForm.form
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.InterimSetByTheCourtPage
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.views.html.InterimRentSetByTheCourtView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.InputText
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
@@ -37,9 +38,10 @@ import scala.concurrent.{ExecutionContext, Future}
class InterimRentSetByTheCourtController @Inject()(interimRentSetByTheCourtView: InterimRentSetByTheCourtView,
authenticate: AuthRetrievals,
- hasLinkedProperties: PropertyLinkingAction,
inputText: InputText,
- raldRepo: RaldRepo,
+ getData: DataRetrievalAction,
+ sessionRepository: SessionRepository,
+ navigator: Navigator,
mcc: MessagesControllerComponents)(implicit appConfig: AppConfig, ec: ExecutionContext)
extends FrontendController(mcc) with I18nSupport {
@@ -57,19 +59,23 @@ class InterimRentSetByTheCourtController @Inject()(interimRentSetByTheCourtView:
)
}
- def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
+ def show(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(InterimSetByTheCourtPage) match {
+ case None => form
+ case Some(value) => form.fill(InterimRentSetByTheCourtForm(BigDecimal(value.amount), NGRMonthYear.fromString(value.date)))
+ }
Future.successful(Ok(interimRentSetByTheCourtView(
- form = form,
- propertyAddress = property.addressFull,
- interimAmount = generateInputText(form, "interimAmount")
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ form = preparedForm,
+ propertyAddress = request.property.addressFull,
+ interimAmount = generateInputText(preparedForm, "interimAmount"),
+ mode = mode
+ )))
}
}
- def submit: Action[AnyContent] =
- (authenticate andThen hasLinkedProperties).async { implicit request =>
+ def submit(mode: Mode): Action[AnyContent] =
+ (authenticate andThen getData).async { implicit request =>
form.bindFromRequest().fold(
formWithErrors => {
val correctedFormErrors = formWithErrors.errors.map { formError =>
@@ -83,20 +89,19 @@ class InterimRentSetByTheCourtController @Inject()(interimRentSetByTheCourtView:
formError
}
val formWithCorrectedErrors = formWithErrors.copy(errors = correctedFormErrors)
- request.propertyLinking.map(property =>
Future.successful(BadRequest(interimRentSetByTheCourtView(
form = formWithCorrectedErrors,
- propertyAddress = property.addressFull,
- interimAmount = generateInputText(formWithCorrectedErrors, "interimAmount")
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ propertyAddress = request.property.addressFull,
+ interimAmount = generateInputText(formWithCorrectedErrors, "interimAmount"),
+ mode = mode
+ )))
},
interimRent =>
- raldRepo.insertInterimRentSetByTheCourt(
- credId = CredId(request.credId.getOrElse("")),
- amount = interimRent.amount,
- date = interimRent.date.makeString
- )
- Future.successful(Redirect(routes.CheckRentFreePeriodController.show.url))
+ val answers = InterimRentSetByTheCourt(interimRent.amount.toString(),interimRent.date.makeString)
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(InterimSetByTheCourtPage, answers))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(InterimSetByTheCourtPage, mode, updatedAnswers))
)
}
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordController.scala
index e9ed6f86..230ddeb2 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordController.scala
@@ -20,15 +20,16 @@ import play.api.data.Form
import play.api.i18n.{I18nSupport, Messages}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.govukfrontend.views.Aliases.*
-import uk.gov.hmrc.http.NotFoundException
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.{Landlord, Mode, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.components.*
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.forms.LandlordForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.LandlordForm.form
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.LandlordPage
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.views.html.LandlordView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.NGRCharacterCountComponent
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
@@ -39,10 +40,11 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class LandlordController @Inject()(view: LandlordView,
authenticate: AuthRetrievals,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
ngrCharacterCountComponent: NGRCharacterCountComponent,
- mcc: MessagesControllerComponents
+ mcc: MessagesControllerComponents,
+ getData : DataRetrievalAction,
+ sessionRepository: SessionRepository,
+ navigator: Navigator
)(implicit appConfig: AppConfig, ec: ExecutionContext) extends FrontendController(mcc) with I18nSupport {
def otherRelationship(form: Form[LandlordForm])(implicit messages: Messages): NGRRadioButtons = NGRRadioButtons(
@@ -73,25 +75,24 @@ class LandlordController @Inject()(view: LandlordView,
NGRRadioButtons = ngrRadioButtons :+ otherRelationship(form)
)
- def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
- Future.successful(Ok(view(
- selectedPropertyAddress = property.addressFull,
- form,
- buildRadios(form, ngrRadio(form))
- )))
- ).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ def show(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(LandlordPage) match {
+ case None => form
+ case Some(value) => form.fill(LandlordForm(value.landlordName,value.landLordType,value.landlordOtherDesc))
+ }
+ Future.successful(Ok(view(selectedPropertyAddress = request.property.addressFull, form = preparedForm, ngrRadio = buildRadios(preparedForm, ngrRadio(preparedForm)), mode))
+ )
+
}
}
- def submit: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
+ def submit(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
form
.bindFromRequest()
.fold(
formWithErrors =>
-
val correctedFormErrors = formWithErrors.errors.map { formError =>
(formError.key, formError.messages) match
case ("", messages) if messages.contains("landlord.radio.other.empty.error") =>
@@ -102,21 +103,18 @@ class LandlordController @Inject()(view: LandlordView,
formError
}
val formWithCorrectedErrors = formWithErrors.copy(errors = correctedFormErrors)
-
- request.propertyLinking.map(property =>
Future.successful(BadRequest(view(
- selectedPropertyAddress = property.addressFull,
+ selectedPropertyAddress = request.property.addressFull,
formWithCorrectedErrors,
- buildRadios(formWithErrors, ngrRadio(formWithCorrectedErrors))
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo")),
+ buildRadios(formWithErrors, ngrRadio(formWithCorrectedErrors)),
+ mode
+ ))),
landlordForm =>
- raldRepo.insertLandlord(
- CredId(request.credId.getOrElse("")),
- landlordForm.landlordName,
- landlordForm.landLordType,
- landlordForm.landlordOther
- )
- Future.successful(Redirect(routes.WhatTypeOfAgreementController.show.url))
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId))
+ .set(LandlordPage, Landlord(landlordForm.landlordName, landlordForm.landLordType, landlordForm.landlordOther)))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(LandlordPage, mode, updatedAnswers))
)
}
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/ProvideDetailsOfFirstSecondRentPeriodController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/ProvideDetailsOfFirstSecondRentPeriodController.scala
index 5dd18634..cfabed28 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/ProvideDetailsOfFirstSecondRentPeriodController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/ProvideDetailsOfFirstSecondRentPeriodController.scala
@@ -22,31 +22,32 @@ 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.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.{Mode, NGRDate, NormalMode, ProvideDetailsOfFirstSecondRentPeriod, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.components.*
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
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.utils.DateKeyFinder
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.ProvideDetailsOfFirstSecondRentPeriodPage
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
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, Singleton}
import scala.concurrent.{ExecutionContext, Future}
-import scala.math.BigDecimal.RoundingMode
@Singleton
class ProvideDetailsOfFirstSecondRentPeriodController @Inject()(view: ProvideDetailsOfFirstSecondRentPeriodView,
authenticate: AuthRetrievals,
inputText: InputText,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
- mcc: MessagesControllerComponents
+ mcc: MessagesControllerComponents,
+ getData: DataRetrievalAction,
+ sessionRepository: SessionRepository,
+ navigator: Navigator,
)(implicit appConfig: AppConfig, ec: ExecutionContext)
extends FrontendController(mcc) with I18nSupport with DateKeyFinder {
@@ -143,24 +144,35 @@ class ProvideDetailsOfFirstSecondRentPeriodController @Inject()(view: ProvideDet
))
)
- def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
+ def show(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(ProvideDetailsOfFirstSecondRentPeriodPage) match {
+ case None => form
+ case Some(value) => form.fill(ProvideDetailsOfFirstSecondRentPeriodForm(NGRDate.fromString(value.firstDateStart),NGRDate.fromString(value.firstDateEnd),value.firstRentPeriodRadio match {
+ case true => "yesPayedRent"
+ case false => "noRentPayed"
+ }, value.firstRentPeriodAmount match {
+ case Some(value) => Some(value)
+ case None => None
+ },
+ NGRDate.fromString(value.secondDateStart),NGRDate.fromString(value.secondDateEnd),BigDecimal(value.secondHowMuchIsRent)))
+
+ }
Future.successful(Ok(view(
- selectedPropertyAddress = property.addressFull,
- form,
+ selectedPropertyAddress = request.property.addressFull,
+ preparedForm,
firstDateStartInput(),
firstDateEndInput(),
- buildRadios(form, firstRentPeriodRadio(form)),
+ buildRadios(preparedForm, firstRentPeriodRadio(preparedForm)),
secondDateStartInput(),
- secondDateEndInput()
+ secondDateEndInput(),
+ mode = mode
)))
- ).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
}
}
- def submit: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
+ def submit(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
form
.bindFromRequest()
.fold(
@@ -181,29 +193,35 @@ class ProvideDetailsOfFirstSecondRentPeriodController @Inject()(view: ProvideDet
formError
}
val formWithCorrectedErrors = formWithErrors.copy(errors = correctedFormErrors)
-
- request.propertyLinking.map(property =>
Future.successful(BadRequest(view(
- selectedPropertyAddress = property.addressFull,
+ selectedPropertyAddress = request.property.addressFull,
formWithCorrectedErrors,
firstDateStartInput(),
firstDateEndInput(),
buildRadios(formWithErrors, firstRentPeriodRadio(formWithCorrectedErrors)),
secondDateStartInput(),
- secondDateEndInput()
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo")),
+ secondDateEndInput(),
+ mode
+ ))),
provideDetailsOfFirstSecondRentPeriodForm =>
- raldRepo.insertProvideDetailsOfFirstSecondRentPeriod(
- CredId(request.credId.getOrElse("")),
+ val provideDetailsOfFirstSecondRentPeriod: ProvideDetailsOfFirstSecondRentPeriod = ProvideDetailsOfFirstSecondRentPeriod(
provideDetailsOfFirstSecondRentPeriodForm.firstDateStartInput.makeString,
provideDetailsOfFirstSecondRentPeriodForm.firstDateEndInput.makeString,
- provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodRadio,
- provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodAmount.map(BigDecimal(_).setScale(2, RoundingMode.HALF_UP)).map(_.toString()),
+ provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodRadio match {
+ case "yesPayedRent" => true
+ case _ => false
+ },
+ provideDetailsOfFirstSecondRentPeriodForm.firstRentPeriodAmount match {
+ case Some(value) => Some(value)
+ case None => None
+ },
provideDetailsOfFirstSecondRentPeriodForm.secondDateStartInput.makeString,
provideDetailsOfFirstSecondRentPeriodForm.secondDateEndInput.makeString,
- provideDetailsOfFirstSecondRentPeriodForm.secondHowMuchIsRent,
- )
- Future.successful(Redirect(routes.RentPeriodsController.show.url))
+ provideDetailsOfFirstSecondRentPeriodForm.secondHowMuchIsRent.toString())
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(ProvideDetailsOfFirstSecondRentPeriodPage, provideDetailsOfFirstSecondRentPeriod))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(ProvideDetailsOfFirstSecondRentPeriodPage, NormalMode, updatedAnswers))
)
}
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentDatesAgreeController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentDatesAgreeController.scala
index 9df5e1e6..9de7d5fa 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentDatesAgreeController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentDatesAgreeController.scala
@@ -16,17 +16,19 @@
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 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.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
import uk.gov.hmrc.ngrraldfrontend.models.forms.RentDatesAgreeForm
+import uk.gov.hmrc.ngrraldfrontend.models.{Mode, NGRDate, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.forms.RentDatesAgreeForm.form
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.{AgreedRentChangePage, RentDatesAgreePage}
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.utils.DateKeyFinder
import uk.gov.hmrc.ngrraldfrontend.views.html.RentDatesAgreeView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
@@ -38,11 +40,11 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class RentDatesAgreeController @Inject()(rentDatesAgreeView: RentDatesAgreeView,
authenticate: AuthRetrievals,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
- mcc: MessagesControllerComponents
- )(implicit appConfig: AppConfig, ec: ExecutionContext)
- extends FrontendController(mcc) with I18nSupport with DateKeyFinder {
+ mcc: MessagesControllerComponents,
+ getData: DataRetrievalAction,
+ navigator: Navigator,
+ sessionRepository: SessionRepository
+ )(implicit appConfig: AppConfig, ec: ExecutionContext) extends FrontendController(mcc) with I18nSupport with DateKeyFinder{
def dateInput()(implicit messages: Messages): DateInput = DateInput(
id = "date",
@@ -60,19 +62,23 @@ class RentDatesAgreeController @Inject()(rentDatesAgreeView: RentDatesAgreeView,
))
)
- def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
+ def show(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(RentDatesAgreePage) match {
+ case None => form
+ case Some(value) => form.fill(RentDatesAgreeForm(NGRDate.fromString(value)))
+ }
Future.successful(Ok(rentDatesAgreeView(
- form = form,
+ form = preparedForm,
dateInput = dateInput(),
- propertyAddress = property.addressFull,
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ propertyAddress = request.property.addressFull,
+ mode = mode
+ )))
}
}
- def submit: Action[AnyContent] =
- (authenticate andThen hasLinkedProperties).async { implicit request =>
+ def submit(mode: Mode): Action[AnyContent] =
+ (authenticate andThen getData).async { implicit request =>
form.bindFromRequest().fold(
formWithErrors => {
val correctedFormErrors = formWithErrors.errors.map { formError =>
@@ -83,19 +89,18 @@ class RentDatesAgreeController @Inject()(rentDatesAgreeView: RentDatesAgreeView,
formError
}
val formWithCorrectedErrors = formWithErrors.copy(errors = correctedFormErrors)
- request.propertyLinking.map(property =>
Future.successful(BadRequest(rentDatesAgreeView(
form = formWithCorrectedErrors,
dateInput = dateInput(),
- propertyAddress = property.addressFull
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ propertyAddress = request.property.addressFull,
+ mode = mode
+ )))
},
dateValue =>
- raldRepo.insertRentDates(
- credId = CredId(request.credId.getOrElse("")),
- rentDates = dateValue.dateInput.makeString
- )
- Future.successful(Redirect(routes.WhatTypeOfLeaseRenewalController.show.url))
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(RentDatesAgreePage, dateValue.dateInput.makeString))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(RentDatesAgreePage, mode, updatedAnswers))
)
}
}
\ No newline at end of file
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentDatesAgreeStartController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentDatesAgreeStartController.scala
index 7c3ea34c..3be90621 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentDatesAgreeStartController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentDatesAgreeStartController.scala
@@ -18,13 +18,14 @@ package uk.gov.hmrc.ngrraldfrontend.controllers
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
-import uk.gov.hmrc.http.NotFoundException
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.{Mode, NGRDate, RentDatesAgreeStart, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.forms.RentDatesAgreeStartForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.RentDatesAgreeStartForm.form
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.RentDatesAgreeStartPage
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.utils.DateKeyFinder
import uk.gov.hmrc.ngrraldfrontend.views.html.RentDatesAgreeStartView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
@@ -35,22 +36,25 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class RentDatesAgreeStartController @Inject()(view: RentDatesAgreeStartView,
authenticate: AuthRetrievals,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
+ getData: DataRetrievalAction,
+ sessionRepository: SessionRepository,
+ navigator: Navigator,
mcc: MessagesControllerComponents
)(implicit appConfig: AppConfig, ec: ExecutionContext)
extends FrontendController(mcc) with I18nSupport with DateKeyFinder {
- def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
- Future.successful(Ok(view(form, property.addressFull)))
- ).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ def show(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ val preparedFrom = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(RentDatesAgreeStartPage) match {
+ case None => form
+ case Some(value) => form.fill(RentDatesAgreeStartForm(NGRDate.fromString(value.agreedDate), NGRDate.fromString(value.startPayingDate)))
+ }
+ Future.successful(Ok(view(preparedFrom, request.property.addressFull, mode)))
}
}
- def submit: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
+ def submit(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
form
.bindFromRequest()
.fold(
@@ -65,17 +69,12 @@ class RentDatesAgreeStartController @Inject()(view: RentDatesAgreeStartView,
formError
}
val formWithCorrectedErrors = formWithErrors.copy(errors = correctedFormErrors)
- request.propertyLinking.map(property =>
- Future.successful(BadRequest(view(formWithCorrectedErrors, property.addressFull))))
- .getOrElse(throw new NotFoundException("Couldn't find property in mongo")),
+ Future.successful(BadRequest(view(formWithCorrectedErrors, request.property.addressFull, mode))),
rentDatesAgreeStartForm =>
- raldRepo.insertRentAgreeStartDates(
- CredId(request.credId.getOrElse("")),
- rentDatesAgreeStartForm.agreedDate.makeString,
- rentDatesAgreeStartForm.startPayingDate.makeString
- )
- Future.successful(Redirect(routes.WhatYourRentIncludesController.show.url))
- )
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(RentDatesAgreeStartPage, RentDatesAgreeStart(rentDatesAgreeStartForm.agreedDate.makeString, rentDatesAgreeStartForm.startPayingDate.makeString)))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(RentDatesAgreeStartPage, mode, updatedAnswers)))
}
}
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentFreePeriodController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentFreePeriodController.scala
index 400153e6..e5ed6578 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentFreePeriodController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentFreePeriodController.scala
@@ -18,13 +18,14 @@ package uk.gov.hmrc.ngrraldfrontend.controllers
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
-import uk.gov.hmrc.http.NotFoundException
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.{Mode, RentFreePeriod, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.forms.RentFreePeriodForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.RentFreePeriodForm.form
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.RentFreePeriodPage
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.utils.DateKeyFinder
import uk.gov.hmrc.ngrraldfrontend.views.html.RentFreePeriodView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
@@ -35,37 +36,36 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class RentFreePeriodController @Inject()(view: RentFreePeriodView,
authenticate: AuthRetrievals,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
+ getData: DataRetrievalAction,
+ sessionRepository: SessionRepository,
+ navigator: Navigator,
mcc: MessagesControllerComponents
)(implicit appConfig: AppConfig, ec: ExecutionContext)
extends FrontendController(mcc) with I18nSupport with DateKeyFinder {
- def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
- Future.successful(Ok(view(form, property.addressFull)))
- ).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ def show(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(RentFreePeriodPage) match {
+ case None => form
+ case Some(value) => form.fill(RentFreePeriodForm(value.months,value.reasons))
+ }
+ Future.successful(Ok(view(preparedForm, request.property.addressFull, mode)))
}
}
- def submit: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- form
- .bindFromRequest()
- .fold(
- formWithErrors =>
- request.propertyLinking.map(property =>
- Future.successful(BadRequest(view(formWithErrors, property.addressFull))))
- .getOrElse(throw new NotFoundException("Couldn't find property in mongo")),
- rentFreePeriodForm =>
- raldRepo.insertRentFreePeriod(
- CredId(request.credId.getOrElse("")),
- rentFreePeriodForm.rentFreePeriodMonths,
- rentFreePeriodForm.reasons
- )
- Future.successful(Redirect(routes.RentDatesAgreeStartController.show.url))
- )
+ def submit(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ form
+ .bindFromRequest()
+ .fold(
+ formWithErrors =>
+ Future.successful(BadRequest(view(formWithErrors, request.property.addressFull, mode))),
+ rentFreePeriodForm =>
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(RentFreePeriodPage, RentFreePeriod(rentFreePeriodForm.rentFreePeriodMonths, rentFreePeriodForm.reasons)))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(RentFreePeriodPage, mode, updatedAnswers))
+ )
+ }
}
}
-}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentInterimController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentInterimController.scala
index f5110a62..dc0516fb 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentInterimController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentInterimController.scala
@@ -18,60 +18,61 @@ package uk.gov.hmrc.ngrraldfrontend.controllers
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
-import uk.gov.hmrc.http.NotFoundException
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.{Mode, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.forms.RentInterimForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.RentInterimForm.form
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.RentInterimPage
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.views.html.RentInterimView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
import javax.inject.Inject
import scala.concurrent.{ExecutionContext, Future}
-class RentInterimController @Inject()(rentInterimView: RentInterimView,
+class RentInterimController @Inject()(rentInterimView: RentInterimView,
authenticate: AuthRetrievals,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
+ getData: DataRetrievalAction,
+ navigator: Navigator,
+ sessionRepository: SessionRepository,
mcc: MessagesControllerComponents)(implicit appConfig: AppConfig, ec: ExecutionContext)
extends FrontendController(mcc) with I18nSupport {
- def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
+ def show(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(RentInterimPage) match {
+ case None => form
+ case Some(value) => form.fill(RentInterimForm(value))
+ }
Future.successful(Ok(rentInterimView(
- form = form,
- radios = buildRadios(form, RentInterimForm.ngrRadio(form)),
- propertyAddress = property.addressFull,
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ form = preparedForm,
+ radios = buildRadios(preparedForm, RentInterimForm.ngrRadio(preparedForm)),
+ propertyAddress = request.property.addressFull,
+ mode = mode
+ )))
}
}
- def submit: Action[AnyContent] =
- (authenticate andThen hasLinkedProperties).async { implicit request =>
+ def submit(mode: Mode): Action[AnyContent] =
+ (authenticate andThen getData).async { implicit request =>
form.bindFromRequest().fold(
formWithErrors => {
- request.propertyLinking.map(property =>
Future.successful(BadRequest(rentInterimView(
form = formWithErrors,
radios = buildRadios(formWithErrors, RentInterimForm.ngrRadio(formWithErrors)),
- propertyAddress = property.addressFull
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ propertyAddress = request.property.addressFull,
+ mode = mode
+ )))
},
radioValue =>
- raldRepo.insertAgreedRentChange(
- credId = CredId(request.credId.getOrElse("")),
- agreedRentChange = radioValue.radioValue
- )
- if (radioValue.radioValue == "Yes") {
- Future.successful(Redirect(routes.InterimRentSetByTheCourtController.show.url))
- } else {
- Future.successful(Redirect(routes.CheckRentFreePeriodController.show.url))
- }
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(RentInterimPage, radioValue.radioValue))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(RentInterimPage, mode, updatedAnswers))
)
}
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentPeriodsController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentPeriodsController.scala
index 6a91b149..868a75ce 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentPeriodsController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/RentPeriodsController.scala
@@ -22,15 +22,17 @@ import uk.gov.hmrc.govukfrontend.views.Aliases.Text
import uk.gov.hmrc.govukfrontend.views.viewmodels.*
import uk.gov.hmrc.govukfrontend.views.viewmodels.table.{Table, TableRow}
import uk.gov.hmrc.http.NotFoundException
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.{Mode, ProvideDetailsOfFirstSecondRentPeriod}
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.forms.RentPeriodsForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.RentPeriodsForm.form
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.models.{NGRDate, RaldUserAnswers}
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.models.UserAnswers
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.{ProvideDetailsOfFirstSecondRentPeriodPage, RentPeriodsPage}
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.utils.CurrencyHelper
import uk.gov.hmrc.ngrraldfrontend.views.html.RentPeriodView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
@@ -41,13 +43,14 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class RentPeriodsController @Inject()(view: RentPeriodView,
authenticate: AuthRetrievals,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
- mcc: MessagesControllerComponents
+ getData: DataRetrievalAction,
+ mcc: MessagesControllerComponents,
+ sessionRepository: SessionRepository,
+ navigator: Navigator,
)(implicit appConfig: AppConfig, ec: ExecutionContext)
extends FrontendController(mcc) with I18nSupport with CurrencyHelper {
- def firstTable(userAnswers: RaldUserAnswers)(implicit messages: Messages): Table =
+ def firstTable(rentPeriods: ProvideDetailsOfFirstSecondRentPeriod)(implicit messages: Messages): Table =
Table(
rows = Seq(
Seq(
@@ -55,9 +58,7 @@ class RentPeriodsController @Inject()(view: RentPeriodView,
content = Text(messages("rentPeriods.first.startDate"))
),
TableRow(
- content = Text(userAnswers.provideDetailsOfFirstSecondRentPeriod.map { dates =>
- NGRDate.formatDate(dates.firstDateStart)
- }.getOrElse("")),
+ content = Text(rentPeriods.firstDateStart),
attributes = Map(
"id" -> "first-period-start-date-id"
)
@@ -68,16 +69,13 @@ class RentPeriodsController @Inject()(view: RentPeriodView,
content = Text(messages("rentPeriods.first.endDate"))
),
TableRow(
- content = Text(userAnswers.provideDetailsOfFirstSecondRentPeriod.map { dates =>
- NGRDate.formatDate(dates.firstDateEnd)
- }.getOrElse("")),
+ content = Text(rentPeriods.firstDateEnd),
attributes = Map(
"id" -> "first-period-end-date-id"
)
)
),
- userAnswers.provideDetailsOfFirstSecondRentPeriod.map { userAnswers =>
- userAnswers.firstRentPeriodAmount match
+ rentPeriods.firstRentPeriodAmount match
case Some(answer) => Seq(
TableRow(
content = Text(messages("rentPeriods.first.rentValue"))
@@ -89,20 +87,19 @@ class RentPeriodsController @Inject()(view: RentPeriodView,
)
)
)
- case None => Seq()
- }.getOrElse(Seq()),
+ case None => Seq(),
Seq(
TableRow(
content = Text(messages("rentPeriods.first.doYouPay"))
),
TableRow(
- content = Text(userAnswers.provideDetailsOfFirstSecondRentPeriod.map { dates =>
- if (dates.firstRentPeriodRadio == true) {
+ content = Text(
+ if (rentPeriods.firstRentPeriodRadio) {
"Yes"
} else {
"No"
}
- }.getOrElse("")),
+ ),
attributes = Map(
"id" -> "first-period-has-pay-id"
)
@@ -115,16 +112,14 @@ class RentPeriodsController @Inject()(view: RentPeriodView,
firstCellIsHeader = true
)
- def secondTable(userAnswers: RaldUserAnswers)(implicit messages: Messages): Table = Table(
+ def secondTable(rentPeriods: ProvideDetailsOfFirstSecondRentPeriod)(implicit messages: Messages): Table = Table(
rows = Seq(
Seq(
TableRow(
content = Text(messages("rentPeriods.second.startDate"))
),
TableRow(
- content = Text(userAnswers.provideDetailsOfFirstSecondRentPeriod.map { dates =>
- NGRDate.formatDate(dates.secondDateStart)
- }.getOrElse("")),
+ content = Text(rentPeriods.secondDateStart),
attributes = Map(
"id" -> "second-period-start-date-id"
)
@@ -135,9 +130,7 @@ class RentPeriodsController @Inject()(view: RentPeriodView,
content = Text(messages("rentPeriods.second.endDate"))
),
TableRow(
- content = Text(userAnswers.provideDetailsOfFirstSecondRentPeriod.map { dates =>
- NGRDate.formatDate(dates.secondDateEnd)
- }.getOrElse("")),
+ content = Text(rentPeriods.secondDateEnd),
attributes = Map(
"id" -> "second-period-end-date-id"
)
@@ -148,9 +141,7 @@ class RentPeriodsController @Inject()(view: RentPeriodView,
content = Text(messages("rentPeriods.second.rentValue"))
),
TableRow(
- content = Text(userAnswers.provideDetailsOfFirstSecondRentPeriod.map { dates =>
- formatRentValue(dates.secondHowMuchIsRent.toDouble)
- }.getOrElse("")),
+ content = Text(rentPeriods.secondHowMuchIsRent),
attributes = Map(
"id" -> "second-period-rent-value-id"
)
@@ -163,45 +154,47 @@ class RentPeriodsController @Inject()(view: RentPeriodView,
firstCellIsHeader = true
)
- def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- raldRepo.findByCredId(CredId(request.credId.getOrElse(""))).flatMap {
- case Some(answers: RaldUserAnswers) =>
+ def show(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ request.userAnswers.getOrElse(UserAnswers(request.credId)).get(ProvideDetailsOfFirstSecondRentPeriodPage) match {
+ case Some(value) =>
+ val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(RentPeriodsPage) match {
+ case Some(value) => form.fill(RentPeriodsForm(value))
+ case None => form
+ }
Future.successful(Ok(view(
- selectedPropertyAddress = answers.selectedProperty.addressFull,
- form,
- firstTable = firstTable(answers),
- secondTable = secondTable(answers),
- ngrRadio = buildRadios(form, RentPeriodsForm.ngrRadio(form)))))
- case None =>
- throw new NotFoundException("Couldn't find user Answers")
+ selectedPropertyAddress = request.property.addressFull,
+ preparedForm,
+ firstTable = firstTable(value),
+ secondTable = secondTable(value),
+ ngrRadio = buildRadios(preparedForm, RentPeriodsForm.ngrRadio(preparedForm)),
+ mode = mode)))
+ case None => throw new Exception("Not found answers")
}
}
}
- def submit: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
+ def submit(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
form
.bindFromRequest()
.fold(
formWithErrors =>
- raldRepo.findByCredId(CredId(request.credId.getOrElse(""))).flatMap {
- case Some(answers: RaldUserAnswers) =>
- Future.successful(BadRequest(view(
- selectedPropertyAddress = answers.selectedProperty.addressFull,
- formWithErrors,
- firstTable = firstTable(answers),
- secondTable = secondTable(answers),
- buildRadios(formWithErrors, RentPeriodsForm.ngrRadio(formWithErrors)))))
+ request.userAnswers.getOrElse(UserAnswers(request.credId)).get(ProvideDetailsOfFirstSecondRentPeriodPage) match {
+ case Some(value) => Future.successful(BadRequest(view(
+ selectedPropertyAddress = request.property.addressFull,
+ formWithErrors,
+ firstTable = firstTable(value),
+ secondTable = secondTable(value),
+ buildRadios(formWithErrors, RentPeriodsForm.ngrRadio(formWithErrors)), mode = mode)))
case None => throw new NotFoundException("Couldn't find user Answers")
},
rentPeriodsForm =>
- raldRepo.insertRentPeriod(
- CredId(request.credId.getOrElse("")),
- rentPeriodsForm.radioValue
- )
- Future.successful(Redirect(routes.WhatTypeOfAgreementController.show.url))
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(RentPeriodsPage, rentPeriodsForm.radioValue))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(RentPeriodsPage, mode, updatedAnswers))
)
}
}
-}
+}
\ No newline at end of file
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutRentController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutRentController.scala
index 2c7597d6..7ee67bcd 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutRentController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutRentController.scala
@@ -18,13 +18,13 @@ package uk.gov.hmrc.ngrraldfrontend.controllers
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
-import uk.gov.hmrc.http.NotFoundException
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
import uk.gov.hmrc.ngrraldfrontend.models.AgreementType.RentAgreement
-import uk.gov.hmrc.ngrraldfrontend.models.RaldUserAnswers
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.models.{NormalMode, UserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.TellUsAboutRentPage
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.views.html.TellUsAboutYourAgreementView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
@@ -34,32 +34,24 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class TellUsAboutRentController @Inject()(view: TellUsAboutYourAgreementView,
authenticate: AuthRetrievals,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
- mcc: MessagesControllerComponents
+ navigator: Navigator,
+ mcc: MessagesControllerComponents,
+ getData: DataRetrievalAction,
+ sessionRepository: SessionRepository
)(implicit appConfig: AppConfig, ec: ExecutionContext) extends FrontendController(mcc) with I18nSupport {
def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
- Future.successful(Ok(view(selectedPropertyAddress = property.addressFull, agreement = RentAgreement))))
- .getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ (authenticate andThen getData).async { implicit request =>
+ Future.successful(Ok(view(selectedPropertyAddress = request.property.addressFull, agreement = RentAgreement)))
}
}
def submit: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
- raldRepo.upsertRaldUserAnswers(
- raldUserAnswers = RaldUserAnswers(
- credId = CredId(request.credId.getOrElse("")),
- agreementType = RentAgreement,
- selectedProperty = request.propertyLinking.getOrElse(throw new NotFoundException("failed to find property")),
- whatTypeOfAgreement = None
- )
- )
- )
- Future.successful(Redirect(routes.LandlordController.show.url))
+ (authenticate andThen getData).async { implicit request =>
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(TellUsAboutRentPage, RentAgreement))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(TellUsAboutRentPage, NormalMode, updatedAnswers))
}
}
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutYourNewAgreementController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutYourNewAgreementController.scala
index 7fe41fcb..7e459bd1 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutYourNewAgreementController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutYourNewAgreementController.scala
@@ -18,13 +18,13 @@ package uk.gov.hmrc.ngrraldfrontend.controllers
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
-import uk.gov.hmrc.http.NotFoundException
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
import uk.gov.hmrc.ngrraldfrontend.models.AgreementType.NewAgreement
-import uk.gov.hmrc.ngrraldfrontend.models.RaldUserAnswers
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.models.{NormalMode, UserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.TellUsAboutYourNewAgreementPage
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.views.html.TellUsAboutYourAgreementView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
@@ -34,32 +34,24 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class TellUsAboutYourNewAgreementController @Inject()(view: TellUsAboutYourAgreementView,
authenticate: AuthRetrievals,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
- mcc: MessagesControllerComponents
- )(implicit appConfig: AppConfig, ec: ExecutionContext) extends FrontendController(mcc) with I18nSupport {
+ mcc: MessagesControllerComponents,
+ getData: DataRetrievalAction,
+ sessionRepository: SessionRepository,
+ navigator: Navigator
+ )(implicit appConfig: AppConfig, ec:ExecutionContext) extends FrontendController(mcc) with I18nSupport {
def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
- Future.successful(Ok(view(selectedPropertyAddress = property.addressFull, agreement = NewAgreement))))
- .getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ (authenticate andThen getData).async { implicit request =>
+ Future.successful(Ok(view(selectedPropertyAddress = request.property.addressFull, agreement = NewAgreement)))
}
}
- def submit: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
- raldRepo.upsertRaldUserAnswers(
- raldUserAnswers = RaldUserAnswers(
- credId = CredId(request.credId.getOrElse("")),
- agreementType = NewAgreement,
- selectedProperty = request.propertyLinking.getOrElse(throw new NotFoundException("failed to find property")),
- whatTypeOfAgreement = None
- )
- )
- )
- Future.successful(Redirect(routes.LandlordController.show.url))
- }
+ def submit: Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(TellUsAboutYourNewAgreementPage, NewAgreement))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(TellUsAboutYourNewAgreementPage, NormalMode, updatedAnswers))
+ }
}
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutYourRenewedAgreementController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutYourRenewedAgreementController.scala
index 31feb3e7..984d9e1c 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutYourRenewedAgreementController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutYourRenewedAgreementController.scala
@@ -18,13 +18,13 @@ package uk.gov.hmrc.ngrraldfrontend.controllers
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
-import uk.gov.hmrc.http.NotFoundException
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
import uk.gov.hmrc.ngrraldfrontend.models.AgreementType.RenewedAgreement
-import uk.gov.hmrc.ngrraldfrontend.models.RaldUserAnswers
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.models.{NormalMode, UserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.TellUsAboutYourRenewedAgreementPage
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.views.html.TellUsAboutYourAgreementView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
@@ -34,32 +34,24 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class TellUsAboutYourRenewedAgreementController @Inject()(view: TellUsAboutYourAgreementView,
authenticate: AuthRetrievals,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
- mcc: MessagesControllerComponents
- )(implicit appConfig: AppConfig, ec: ExecutionContext) extends FrontendController(mcc) with I18nSupport {
+ mcc: MessagesControllerComponents,
+ getData: DataRetrievalAction,
+ sessionRepository: SessionRepository,
+ navigator: Navigator
+ )(implicit appConfig: AppConfig, ec:ExecutionContext) extends FrontendController(mcc) with I18nSupport {
def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
- Future.successful(Ok(view(selectedPropertyAddress = property.addressFull, agreement = RenewedAgreement))))
- .getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ (authenticate andThen getData).async { implicit request =>
+ Future.successful(Ok(view(selectedPropertyAddress = request.property.addressFull, agreement = RenewedAgreement)))
}
}
- def submit: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
- raldRepo.upsertRaldUserAnswers(
- raldUserAnswers = RaldUserAnswers(
- credId = CredId(request.credId.getOrElse("")),
- agreementType = RenewedAgreement,
- selectedProperty = request.propertyLinking.getOrElse(throw new NotFoundException("failed to find property")),
- whatTypeOfAgreement = None
- )
- )
- )
- Future.successful(Redirect(routes.WhatTypeOfLeaseRenewalController.show.url))
- }
+ def submit: Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(TellUsAboutYourRenewedAgreementPage, RenewedAgreement))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(TellUsAboutYourRenewedAgreementPage, NormalMode, updatedAnswers))
+ }
+ }
}
-}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/WhatIsYourRentBasedOnController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/WhatIsYourRentBasedOnController.scala
index c3d8e5fc..1760a375 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/WhatIsYourRentBasedOnController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/WhatIsYourRentBasedOnController.scala
@@ -20,15 +20,16 @@ import play.api.data.Form
import play.api.i18n.{I18nSupport, Messages}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.govukfrontend.views.Aliases.{Label, Text}
-import uk.gov.hmrc.http.NotFoundException
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.{Mode, RentBasedOn, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.components.*
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.forms.WhatIsYourRentBasedOnForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.WhatIsYourRentBasedOnForm.form
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.WhatIsYourRentBasedOnPage
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.views.html.WhatIsYourRentBasedOnView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.NGRCharacterCountComponent
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
@@ -39,10 +40,11 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class WhatIsYourRentBasedOnController @Inject()(view: WhatIsYourRentBasedOnView,
authenticate: AuthRetrievals,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
ngrCharacterCountComponent: NGRCharacterCountComponent,
- mcc: MessagesControllerComponents
+ mcc: MessagesControllerComponents,
+ getData: DataRetrievalAction,
+ navigator: Navigator,
+ sessionRepository: SessionRepository,
)(implicit appConfig: AppConfig, ec: ExecutionContext) extends FrontendController(mcc) with I18nSupport {
private def otherRadioButton(form: Form[WhatIsYourRentBasedOnForm])(implicit messages: Messages): NGRRadioButtons = NGRRadioButtons(
@@ -75,16 +77,18 @@ class WhatIsYourRentBasedOnController @Inject()(view: WhatIsYourRentBasedOnView,
NGRRadioButtons = ngrRadioButtons :+ otherRadioButton(form)
)
- def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
- Future.successful(Ok(view(form, buildRadios(form, ngrRadio(form)), property.addressFull)))
- ).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ def show(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(WhatIsYourRentBasedOnPage) match {
+ case None => form
+ case Some(value) => form.fill(WhatIsYourRentBasedOnForm(value.rentBased,value.otherDesc))
+ }
+ Future.successful(Ok(view(preparedForm, buildRadios(preparedForm, ngrRadio(preparedForm)), request.property.addressFull, mode)))
}
}
- def submit: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
+ def submit(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
form
.bindFromRequest()
.fold(
@@ -99,22 +103,13 @@ class WhatIsYourRentBasedOnController @Inject()(view: WhatIsYourRentBasedOnView,
formError
}
val formWithCorrectedErrors = formWithErrors.copy(errors = correctedFormErrors)
-
- request.propertyLinking.map(property =>
Future.successful(BadRequest(view(formWithCorrectedErrors,
- buildRadios(formWithErrors, ngrRadio(formWithCorrectedErrors)), property.addressFull))))
- .getOrElse(throw new NotFoundException("Couldn't find property in mongo")),
+ buildRadios(formWithErrors, ngrRadio(formWithCorrectedErrors)), request.property.addressFull, mode))),
rentBasedOnForm =>
- raldRepo.insertRentBased(
- CredId(request.credId.getOrElse("")),
- rentBasedOnForm.radioValue,
- if (rentBasedOnForm.radioValue.equals("Other")) rentBasedOnForm.rentBasedOnOther else None
- )
- rentBasedOnForm.radioValue match
- case "PercentageTurnover" =>
- Future.successful(Redirect(routes.HowMuchIsTotalAnnualRentController.show.url))
- case _ =>
- Future.successful(Redirect(routes.AgreedRentChangeController.show.url))
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(WhatIsYourRentBasedOnPage, RentBasedOn(rentBasedOnForm.radioValue,rentBasedOnForm.rentBasedOnOther)))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(WhatIsYourRentBasedOnPage, mode, updatedAnswers))
)
}
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/WhatTypeOfAgreementController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/WhatTypeOfAgreementController.scala
index 503f2287..66c867b5 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/WhatTypeOfAgreementController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/WhatTypeOfAgreementController.scala
@@ -18,15 +18,16 @@ package uk.gov.hmrc.ngrraldfrontend.controllers
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
-import uk.gov.hmrc.http.NotFoundException
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.{Mode, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.components.*
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.forms.WhatTypeOfAgreementForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.WhatTypeOfAgreementForm.form
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.WhatTypeOfAgreementPage
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
import uk.gov.hmrc.ngrraldfrontend.views.html.WhatTypeOfAgreementView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
@@ -36,47 +37,48 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class WhatTypeOfAgreementController @Inject()(view: WhatTypeOfAgreementView,
authenticate: AuthRetrievals,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
- mcc: MessagesControllerComponents)
+ mcc: MessagesControllerComponents,
+ getData: DataRetrievalAction,
+ navigator: Navigator,
+ sessionRepository: SessionRepository)
(implicit appConfig: AppConfig, ec: ExecutionContext)
extends FrontendController(mcc) with I18nSupport {
- def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
+ def show(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(WhatTypeOfAgreementPage) match {
+ case None => form
+ case Some(value) => form.fill(WhatTypeOfAgreementForm(value))
+ }
Future.successful(Ok(
view(
- selectedPropertyAddress = property.addressFull,
- form = form,
- ngrRadio = buildRadios(form, WhatTypeOfAgreementForm.ngrRadio(form))
+ selectedPropertyAddress = request.property.addressFull,
+ form = preparedForm,
+ ngrRadio = buildRadios(preparedForm, WhatTypeOfAgreementForm.ngrRadio(preparedForm)),
+ mode
)
- ))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ ))
}
}
- def submit: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
+ def submit(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
form
.bindFromRequest()
.fold(
formWithErrors =>
- request.propertyLinking.map(property =>
Future.successful(BadRequest(view(
- selectedPropertyAddress = property.addressFull,
+ selectedPropertyAddress = request.property.addressFull,
formWithErrors,
- buildRadios(formWithErrors, WhatTypeOfAgreementForm.ngrRadio(formWithErrors))
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo")),
+ buildRadios(formWithErrors, WhatTypeOfAgreementForm.ngrRadio(formWithErrors)),
+ mode
+ ))),
whatTypeOfAgreementForm =>
- raldRepo.insertTypeOfAgreement(
- credId = CredId(request.credId.getOrElse("")),
- whatTypeOfAgreement = whatTypeOfAgreementForm.radioValue
- )
- whatTypeOfAgreementForm.radioValue match
- case "Verbal" =>
- Future.successful(Redirect(routes.AgreementVerbalController.show.url))
- case _ =>
- Future.successful(Redirect(routes.AgreementController.show.url))
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId))
+ .set(WhatTypeOfAgreementPage, whatTypeOfAgreementForm.radioValue))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(WhatTypeOfAgreementPage,mode,updatedAnswers))
)
}
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/WhatTypeOfLeaseRenewalController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/WhatTypeOfLeaseRenewalController.scala
index 1cc6707b..a87a0f76 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/WhatTypeOfLeaseRenewalController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/WhatTypeOfLeaseRenewalController.scala
@@ -18,14 +18,16 @@ package uk.gov.hmrc.ngrraldfrontend.controllers
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
-import uk.gov.hmrc.http.NotFoundException
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.{Mode, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.forms.WhatTypeOfLeaseRenewalForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.WhatTypeOfLeaseRenewalForm.{RenewedAgreement, SurrenderAndRenewal, form}
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.WhatTypeOfLeaseRenewalPage
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
+import uk.gov.hmrc.ngrraldfrontend.utils.Constants
import uk.gov.hmrc.ngrraldfrontend.utils.Constants.{renewedAgreement, surrenderAndRenewal}
import uk.gov.hmrc.ngrraldfrontend.views.html.WhatTypeOfLeaseRenewalView
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
@@ -36,43 +38,56 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class WhatTypeOfLeaseRenewalController @Inject()(whatTypeOfLeaseRenewalView: WhatTypeOfLeaseRenewalView,
authenticate: AuthRetrievals,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
+ getData: DataRetrievalAction,
+ sessionRepository: SessionRepository,
+ navigator: Navigator,
mcc: MessagesControllerComponents)(implicit appConfig: AppConfig, ec: ExecutionContext)
extends FrontendController(mcc) with I18nSupport {
- def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
- Future.successful(Ok(whatTypeOfLeaseRenewalView(
- form = form,
- radios = buildRadios(form, WhatTypeOfLeaseRenewalForm.ngrRadio),
- propertyAddress = property.addressFull,
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ def show(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+
+ val preparedForm = request.userAnswers
+ .getOrElse(UserAnswers(request.credId))
+ .get(WhatTypeOfLeaseRenewalPage) match {
+ case None => WhatTypeOfLeaseRenewalForm.form
+ case Some(value) =>
+ val selectedOption = value match {
+ case Constants.renewedAgreement => WhatTypeOfLeaseRenewalForm.RenewedAgreement
+ case Constants.surrenderAndRenewal => WhatTypeOfLeaseRenewalForm.SurrenderAndRenewal
+ }
+ WhatTypeOfLeaseRenewalForm.form.fill(selectedOption)
+
+ }
+ Future.successful(Ok(whatTypeOfLeaseRenewalView(
+ form = preparedForm,
+ radios = buildRadios(preparedForm, WhatTypeOfLeaseRenewalForm.ngrRadio),
+ propertyAddress = request.property.addressFull,
+ mode = mode
+ )))
}
}
- def submit: Action[AnyContent] =
- (authenticate andThen hasLinkedProperties).async { implicit request =>
+ def submit(mode: Mode): Action[AnyContent] =
+ (authenticate andThen getData).async { implicit request =>
form.bindFromRequest().fold(
formWithErrors => {
- request.propertyLinking.map(property =>
Future.successful(BadRequest(whatTypeOfLeaseRenewalView(
form = formWithErrors,
radios = buildRadios(formWithErrors, WhatTypeOfLeaseRenewalForm.ngrRadio),
- propertyAddress = property.addressFull
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ propertyAddress = request.property.addressFull,
+ mode
+ )))
},
radioValue =>
val typeOfLeaseRenewal = radioValue match
case RenewedAgreement => renewedAgreement
case SurrenderAndRenewal => surrenderAndRenewal
- raldRepo.insertTypeOfRenewal(
- credId = CredId(request.credId.getOrElse("")),
- whatTypeOfRenewal = typeOfLeaseRenewal
- )
- Future.successful(Redirect(routes.LandlordController.show.url))
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(WhatTypeOfLeaseRenewalPage, typeOfLeaseRenewal))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(WhatTypeOfLeaseRenewalPage, mode, updatedAnswers))
)
}
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/WhatYourRentIncludesController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/WhatYourRentIncludesController.scala
index 760712dd..188da127 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/WhatYourRentIncludesController.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/WhatYourRentIncludesController.scala
@@ -18,17 +18,18 @@ package uk.gov.hmrc.ngrraldfrontend.controllers
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
-import uk.gov.hmrc.http.NotFoundException
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.{Mode, UserAnswers, WhatYourRentIncludes}
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.forms.WhatYourRentIncludesForm
import uk.gov.hmrc.ngrraldfrontend.models.forms.WhatYourRentIncludesForm.form
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
import uk.gov.hmrc.ngrraldfrontend.views.html.WhatYourRentIncludesView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.InputText
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
+import uk.gov.hmrc.ngrraldfrontend.pages.WhatYourRentIncludesPage
import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}
@@ -36,30 +37,67 @@ import scala.concurrent.{ExecutionContext, Future}
@Singleton
class WhatYourRentIncludesController @Inject()(whatYourRentIncludesView: WhatYourRentIncludesView,
authenticate: AuthRetrievals,
- inputText: InputText,
- hasLinkedProperties: PropertyLinkingAction,
- raldRepo: RaldRepo,
+ inputText: InputText,
+ getData: DataRetrievalAction,
+ sessionRepository: SessionRepository,
+ navigator: Navigator,
mcc: MessagesControllerComponents)(implicit appConfig: AppConfig, ec: ExecutionContext)
extends FrontendController(mcc) with I18nSupport {
- def show: Action[AnyContent] = {
- (authenticate andThen hasLinkedProperties).async { implicit request =>
- request.propertyLinking.map(property =>
+ def show(mode: Mode): Action[AnyContent] = {
+ (authenticate andThen getData).async { implicit request =>
+ val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(WhatYourRentIncludesPage) match {
+ case Some(value) => form.fill(WhatYourRentIncludesForm(
+ livingAccommodationRadio = if (value.livingAccommodation) {
+ "livingAccommodationYes"
+ } else {
+ "livingAccommodationNo"
+ },
+ rentPartAddressRadio = if (value.rentPartAddress) {
+ "rentPartAddressYes"
+ } else {
+ "rentPartAddressNo"
+ },
+ rentEmptyShellRadio = if (value.rentEmptyShell) {
+ "rentEmptyShellYes"
+ } else {
+ "rentEmptyShellNo"
+ },
+ rentIncBusinessRatesRadio = if (value.rentIncBusinessRates) {
+ "rentIncBusinessRatesYes"
+ } else {
+ "rentIncBusinessRatesNo"
+ },
+ rentIncWaterChargesRadio = if (value.rentIncWaterCharges) {
+ "rentIncWaterChargesYes"
+ } else {
+ "rentIncWaterChargesNo"
+ },
+ rentIncServiceRadio = if (value.rentIncService) {
+ "rentIncServiceYes"
+ } else {
+ "rentIncServiceNo"
+ },
+ bedroomNumbers = value.bedroomNumbers.map(_.toString)
+ ))
+ case None => form
+ }
Future.successful(Ok(whatYourRentIncludesView(
- form = form,
- radios1 = buildRadios(form, WhatYourRentIncludesForm.ngrRadio1(form, inputText)),
- radios2 = buildRadios(form, WhatYourRentIncludesForm.ngrRadio2),
- radios3 = buildRadios(form, WhatYourRentIncludesForm.ngrRadio3),
- radios4 = buildRadios(form, WhatYourRentIncludesForm.ngrRadio4),
- radios5 = buildRadios(form, WhatYourRentIncludesForm.ngrRadio5),
- radios6 = buildRadios(form, WhatYourRentIncludesForm.ngrRadio6),
- propertyAddress = property.addressFull,
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ form = preparedForm,
+ radios1 = buildRadios(preparedForm, WhatYourRentIncludesForm.ngrRadio1(preparedForm, inputText)),
+ radios2 = buildRadios(preparedForm, WhatYourRentIncludesForm.ngrRadio2),
+ radios3 = buildRadios(preparedForm, WhatYourRentIncludesForm.ngrRadio3),
+ radios4 = buildRadios(preparedForm, WhatYourRentIncludesForm.ngrRadio4),
+ radios5 = buildRadios(preparedForm, WhatYourRentIncludesForm.ngrRadio5),
+ radios6 = buildRadios(preparedForm, WhatYourRentIncludesForm.ngrRadio6),
+ propertyAddress = request.property.addressFull,
+ mode = mode
+ )))
}
}
- def submit: Action[AnyContent] =
- (authenticate andThen hasLinkedProperties).async { implicit request =>
+ def submit(mode: Mode): Action[AnyContent] =
+ (authenticate andThen getData).async { implicit request =>
form.bindFromRequest().fold(
formWithErrors => {
val correctedFormErrors = formWithErrors.errors.map { formError =>
@@ -69,7 +107,6 @@ class WhatYourRentIncludesController @Inject()(whatYourRentIncludesView: WhatYou
case _ => formError
}
val formWithCorrectedErrors = formWithErrors.copy(errors = correctedFormErrors)
- request.propertyLinking.map(property =>
Future.successful(BadRequest(whatYourRentIncludesView(
form = formWithCorrectedErrors,
radios1 = buildRadios(formWithErrors, WhatYourRentIncludesForm.ngrRadio1(formWithCorrectedErrors, inputText)),
@@ -78,21 +115,45 @@ class WhatYourRentIncludesController @Inject()(whatYourRentIncludesView: WhatYou
radios4 = buildRadios(formWithErrors, WhatYourRentIncludesForm.ngrRadio4),
radios5 = buildRadios(formWithErrors, WhatYourRentIncludesForm.ngrRadio5),
radios6 = buildRadios(formWithErrors, WhatYourRentIncludesForm.ngrRadio6),
- propertyAddress = property.addressFull
- )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ propertyAddress = request.property.addressFull,
+ mode = mode
+ )))
},
whatYourRentIncludesForm =>
- raldRepo.insertWhatYourRentIncludes(
- credId = CredId(request.credId.getOrElse("")),
- whatYourRentIncludesForm.livingAccommodationRadio,
- whatYourRentIncludesForm.rentPartAddressRadio,
- whatYourRentIncludesForm.rentEmptyShellRadio,
- whatYourRentIncludesForm.rentIncBusinessRatesRadio,
- whatYourRentIncludesForm.rentIncWaterChargesRadio,
- whatYourRentIncludesForm.rentIncServiceRadio,
- whatYourRentIncludesForm.bedroomNumbers
+ val answers: WhatYourRentIncludes = WhatYourRentIncludes(
+ livingAccommodation = whatYourRentIncludesForm.livingAccommodationRadio match {
+ case "livingAccommodationYes" => true
+ case _ => false
+ },
+ rentPartAddress = whatYourRentIncludesForm.rentPartAddressRadio match {
+ case "Yes" => true
+ case _ => false
+ },
+ rentEmptyShell = whatYourRentIncludesForm.rentEmptyShellRadio match {
+ case "Yes" => true
+ case _ => false
+ },
+ rentIncBusinessRates = whatYourRentIncludesForm.rentIncBusinessRatesRadio match {
+ case "Yes" => true
+ case _ => false
+ },
+ rentIncWaterCharges = whatYourRentIncludesForm.rentIncWaterChargesRadio match {
+ case "Yes" => true
+ case _ => false
+ },
+ rentIncService = whatYourRentIncludesForm.rentIncServiceRadio match {
+ case "Yes" => true
+ case _ => false
+ },
+ bedroomNumbers = whatYourRentIncludesForm.bedroomNumbers match {
+ case Some(value) if(whatYourRentIncludesForm.livingAccommodationRadio == "livingAccommodationYes") => Some(value.toInt)
+ case _ => None
+ }
)
- Future.successful(Redirect(routes.DoesYourRentIncludeParkingController.show.url))
+ for {
+ updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(WhatYourRentIncludesPage, answers))
+ _ <- sessionRepository.set(updatedAnswers)
+ } yield Redirect(navigator.nextPage(WhatYourRentIncludesPage, mode, updatedAnswers))
)
}
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/Agreement.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/Agreement.scala
index 54a7d0c6..a625cbff 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/models/Agreement.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/models/Agreement.scala
@@ -21,7 +21,7 @@ import play.api.libs.json.{Json, OFormat}
case class Agreement(
agreementStart : String,
isOpenEnded: Boolean,
- openEndedDate:Option[String],
+ openEndedDate:Option[String] = None,
haveBreakClause: Boolean,
breakClauseInfo:Option[String]
)
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/Mode.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/Mode.scala
new file mode 100644
index 00000000..c7db3281
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/models/Mode.scala
@@ -0,0 +1,41 @@
+/*
+ * 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.{JsString, Writes}
+import play.api.mvc.JavascriptLiteral
+
+sealed trait Mode
+
+case object CheckMode extends Mode
+
+case object NormalMode extends Mode
+
+object Mode {
+
+ implicit val jsLiteral: JavascriptLiteral[Mode] = new JavascriptLiteral[Mode] {
+ override def to(value: Mode): String = value match {
+ case NormalMode => "NormalMode"
+ case CheckMode => "CheckMode"
+ }
+ }
+
+ implicit val writes: Writes[Mode] = Writes {
+ case NormalMode => JsString("NormalMode")
+ case CheckMode => JsString("CheckMode")
+ }
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/NGRDate.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/NGRDate.scala
index 2d473af1..b0dd36ca 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/models/NGRDate.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/models/NGRDate.scala
@@ -44,6 +44,12 @@ object NGRDate {
date.format(outputFormatter)
}
+ def fromString(dateString: String): NGRDate = {
+ val date = LocalDate.parse(dateString)
+ NGRDate(date.getDayOfMonth.toString, date.getMonthValue.toString, date.getYear.toString)
+ }
+
+
def unapply(ngrDate: NGRDate): Option[(String, String, String)] =
Some(ngrDate.day, ngrDate.month, ngrDate.year)
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/NGRMonthYear.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/NGRMonthYear.scala
index 4cae8fd2..9c1b6e15 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/models/NGRMonthYear.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/models/NGRMonthYear.scala
@@ -40,6 +40,11 @@ object NGRMonthYear {
date.format(outputFormatter)
}
+ def fromString(dateString: String): NGRMonthYear = {
+ val parts = dateString.split("-").map(_.toInt)
+ NGRMonthYear(parts(1).toString, parts(0).toString)
+ }
+
def unapply(ngrMonthYear: NGRMonthYear): Option[(String, String)] =
Some(ngrMonthYear.month, ngrMonthYear.year)
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/RentBasedOn.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/RentBasedOn.scala
index 27aaf7c0..b57188a3 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/models/RentBasedOn.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/models/RentBasedOn.scala
@@ -18,7 +18,7 @@ package uk.gov.hmrc.ngrraldfrontend.models
import play.api.libs.json.{Json, OFormat}
-final case class RentBasedOn(rentBased: String, otherDesc: Option[String])
+final case class RentBasedOn(rentBased: String, otherDesc: Option[String] = None)
object RentBasedOn {
implicit val format: OFormat[RentBasedOn] = Json.format[RentBasedOn]
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/TypeOfAgreement.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/TypeOfAgreement.scala
new file mode 100644
index 00000000..95276871
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/models/TypeOfAgreement.scala
@@ -0,0 +1,28 @@
+/*
+ * 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.{Format, Json}
+
+case class TypeOfAgreement (value: String)
+
+
+object TypeOfAgreement {
+
+ implicit val format:Format[TypeOfAgreement] = Json.format[TypeOfAgreement]
+
+}
\ No newline at end of file
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/UserAnswers.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/UserAnswers.scala
new file mode 100644
index 00000000..505219a7
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/models/UserAnswers.scala
@@ -0,0 +1,77 @@
+/*
+ * 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.*
+import uk.gov.hmrc.mongo.play.json.formats.MongoJavatimeFormats
+import uk.gov.hmrc.ngrraldfrontend.queries.{Gettable, Settable}
+
+import java.time.Instant
+import scala.util.{Failure, Success, Try}
+
+final case class UserAnswers(
+ credId: String,
+ data: JsObject = Json.obj(),
+ lastUpdated: Instant = Instant.now
+ ) {
+
+ def get[A](page: Gettable[A])(implicit rds: Reads[A]): Option[A] =
+ Reads.optionNoError(Reads.at(page.path)).reads(data).getOrElse(None)
+
+ def set[A](page: Settable[A], value: A)(implicit writes: Writes[A]): Try[UserAnswers] = {
+
+ val updatedData = data.setObject(page.path, Json.toJson(value)) match {
+ case JsSuccess(jsValue, _) =>
+ Success(jsValue)
+ case JsError(errors) =>
+ Failure(JsResultException(errors))
+ }
+
+ updatedData.flatMap {
+ d =>
+ val updatedAnswers = copy (data = d)
+ page.cleanup(Some(value), updatedAnswers)
+ }
+ }
+}
+
+object UserAnswers {
+
+ val reads: Reads[UserAnswers] = {
+
+ import play.api.libs.functional.syntax.*
+
+ (
+ (__ \ "credId").read[String] and
+ (__ \ "data").read[JsObject] and
+ (__ \ "lastUpdated").read(MongoJavatimeFormats.instantFormat)
+ ) (UserAnswers.apply)
+ }
+
+ val writes: OWrites[UserAnswers] = {
+
+ import play.api.libs.functional.syntax.*
+
+ (
+ (__ \ "credId").write[String] and
+ (__ \ "data").write[JsObject] and
+ (__ \ "lastUpdated").write(MongoJavatimeFormats.instantFormat)
+ ) (ua => (ua.credId, ua.data, ua.lastUpdated))
+ }
+
+ implicit val format: OFormat[UserAnswers] = OFormat(reads, writes)
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/RentPeriodsForm.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/RentPeriodsForm.scala
index 4984346b..d3b9bc97 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/RentPeriodsForm.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/RentPeriodsForm.scala
@@ -57,8 +57,8 @@ object RentPeriodsForm extends Mappings {
)
}
- private val yes: NGRRadioButtons = NGRRadioButtons(radioContent = "rentPeriods.yes", radioValue = No)
- private val no: NGRRadioButtons = NGRRadioButtons(radioContent = "rentPeriods.no", radioValue = Yes)
+ private val yes: NGRRadioButtons = NGRRadioButtons(radioContent = "rentPeriods.yes", radioValue = Yes)
+ private val no: NGRRadioButtons = NGRRadioButtons(radioContent = "rentPeriods.no", radioValue = No)
def ngrRadio(form: Form[RentPeriodsForm])(implicit messages: Messages): NGRRadio =
NGRRadio(ngrTitle = Some(Legend(content = Text(messages("rentPeriods.radio.heading")), classes = "govuk-fieldset__legend--m", isPageHeading = true)), radioGroupName = NGRRadioName("rent-periods-radio"), NGRRadioButtons = Seq(yes, no))
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/package.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/package.scala
new file mode 100644
index 00000000..a0ca4fde
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/models/package.scala
@@ -0,0 +1,163 @@
+/*
+ * 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
+
+/*
+ * 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 play.api.libs.json.*
+
+package object models {
+
+ implicit class RichJsObject(jsObject: JsObject) {
+
+ def setObject(path: JsPath, value: JsValue): JsResult[JsObject] =
+ jsObject.set(path, value).flatMap(_.validate[JsObject])
+
+ def removeObject(path: JsPath): JsResult[JsObject] =
+ jsObject.remove(path).flatMap(_.validate[JsObject])
+ }
+
+ implicit class RichJsValue(jsValue: JsValue) {
+
+ def set(path: JsPath, value: JsValue): JsResult[JsValue] =
+ (path.path, jsValue) match {
+
+ case (Nil, _) =>
+ JsError("path cannot be empty")
+
+ case ((_: RecursiveSearch) :: _, _) =>
+ JsError("recursive search not supported")
+
+ case ((n: IdxPathNode) :: Nil, _) =>
+ setIndexNode(n, jsValue, value)
+
+ case ((n: KeyPathNode) :: Nil, _) =>
+ setKeyNode(n, jsValue, value)
+
+ case (first :: second :: rest, oldValue) =>
+ Reads.optionNoError(Reads.at[JsValue](JsPath(first :: Nil)))
+ .reads(oldValue).flatMap {
+ opt =>
+
+ opt.map(JsSuccess(_)).getOrElse {
+ second match {
+ case _: KeyPathNode =>
+ JsSuccess(Json.obj())
+ case _: IdxPathNode =>
+ JsSuccess(Json.arr())
+ case _: RecursiveSearch =>
+ JsError("recursive search is not supported")
+ }
+ }.flatMap {
+ _.set(JsPath(second :: rest), value).flatMap {
+ newValue =>
+ oldValue.set(JsPath(first :: Nil), newValue)
+ }
+ }
+ }
+ }
+
+ private def setIndexNode(node: IdxPathNode, oldValue: JsValue, newValue: JsValue): JsResult[JsValue] = {
+
+ val index: Int = node.idx
+
+ oldValue match {
+ case oldValue: JsArray if index >= 0 && index <= oldValue.value.length =>
+ if (index == oldValue.value.length) {
+ JsSuccess(oldValue.append(newValue))
+ } else {
+ JsSuccess(JsArray(oldValue.value.updated(index, newValue)))
+ }
+ case oldValue: JsArray =>
+ JsError(s"array index out of bounds: $index, $oldValue")
+ case _ =>
+ JsError(s"cannot set an index on $oldValue")
+ }
+ }
+
+ private def removeIndexNode(node: IdxPathNode, valueToRemoveFrom: JsArray): JsResult[JsValue] = {
+ val index: Int = node.idx
+
+ valueToRemoveFrom match {
+ case valueToRemoveFrom: JsArray if index >= 0 && index < valueToRemoveFrom.value.length =>
+ val updatedJsArray = valueToRemoveFrom.value.slice(0, index) ++ valueToRemoveFrom.value.slice(index + 1, valueToRemoveFrom.value.size)
+ JsSuccess(JsArray(updatedJsArray))
+ case valueToRemoveFrom: JsArray => JsError(s"array index out of bounds: $index, $valueToRemoveFrom")
+ }
+ }
+
+ private def setKeyNode(node: KeyPathNode, oldValue: JsValue, newValue: JsValue): JsResult[JsValue] = {
+
+ val key = node.key
+
+ oldValue match {
+ case oldValue: JsObject =>
+ JsSuccess(oldValue + (key -> newValue))
+ case _ =>
+ JsError(s"cannot set a key on $oldValue")
+ }
+ }
+
+ def remove(path: JsPath): JsResult[JsValue] = {
+
+ (path.path, jsValue) match {
+ case (Nil, _) => JsError("path cannot be empty")
+ case ((n: KeyPathNode) :: Nil, value: JsObject) if value.keys.contains(n.key) => JsSuccess(value - n.key)
+ case ((n: KeyPathNode) :: Nil, value: JsObject) if !value.keys.contains(n.key) => JsError("cannot find value at path")
+ case ((n: IdxPathNode) :: Nil, value: JsArray) => removeIndexNode(n, value)
+ case ((_: KeyPathNode) :: Nil, _) => JsError(s"cannot remove a key on $jsValue")
+ case (first :: second :: rest, oldValue) =>
+
+ Reads.optionNoError(Reads.at[JsValue](JsPath(first :: Nil)))
+ .reads(oldValue).flatMap {
+ (opt: Option[JsValue]) =>
+
+ opt.map(JsSuccess(_)).getOrElse {
+ second match {
+ case _: KeyPathNode =>
+ JsSuccess(Json.obj())
+ case _: IdxPathNode =>
+ JsSuccess(Json.arr())
+ case _: RecursiveSearch =>
+ JsError("recursive search is not supported")
+ }
+ }.flatMap {
+ _.remove(JsPath(second :: rest)).flatMap {
+ newValue =>
+ oldValue.set(JsPath(first :: Nil), newValue)
+ }
+ }
+ }
+ case _ => throw new RuntimeException("bad match")
+ }
+ }
+ }
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/requests/DataRequest.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/requests/DataRequest.scala
new file mode 100644
index 00000000..5c8049af
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/models/requests/DataRequest.scala
@@ -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.
+ */
+
+package uk.gov.hmrc.ngrraldfrontend.models.requests
+
+import play.api.mvc.{Request, WrappedRequest}
+import uk.gov.hmrc.ngrraldfrontend.models.UserAnswers
+import uk.gov.hmrc.ngrraldfrontend.models.vmvProperty.VMVProperty
+
+case class OptionalDataRequest[A] (request: Request[A], credId: String, userAnswers: Option[UserAnswers], property: VMVProperty) extends WrappedRequest[A](request)
+
+case class DataRequest[A] (request: Request[A], credId: String, userAnswers: UserAnswers) extends WrappedRequest[A](request)
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/requests/IdentifierRequest.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/requests/IdentifierRequest.scala
new file mode 100644
index 00000000..2846698b
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/models/requests/IdentifierRequest.scala
@@ -0,0 +1,21 @@
+/*
+ * 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.requests
+
+import play.api.mvc.{Request, WrappedRequest}
+
+case class IdentifierRequest[A] (request: Request[A], userId: String, credId: String) extends WrappedRequest[A](request)
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/navigation/Navigator.scala b/app/uk/gov/hmrc/ngrraldfrontend/navigation/Navigator.scala
new file mode 100644
index 00000000..1028e075
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/navigation/Navigator.scala
@@ -0,0 +1,158 @@
+/*
+ * 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.navigation
+
+import play.api.mvc.Call
+import controllers.routes
+import uk.gov.hmrc.http.NotFoundException
+import uk.gov.hmrc.ngrraldfrontend.models.{CheckMode, Mode, NormalMode, ProvideDetailsOfFirstSecondRentPeriod, UserAnswers, WhatYourRentIncludes}
+import uk.gov.hmrc.ngrraldfrontend.pages._
+
+import javax.inject.{Inject, Singleton}
+
+@Singleton
+class Navigator @Inject()() {
+
+ private val normalRoutes: Page => UserAnswers => Call = {
+ case TellUsAboutRentPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.LandlordController.show(NormalMode)
+ case TellUsAboutYourRenewedAgreementPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.WhatTypeOfLeaseRenewalController.show(NormalMode)
+ case TellUsAboutYourNewAgreementPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.LandlordController.show(NormalMode)
+ case WhatTypeOfLeaseRenewalPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.LandlordController.show(NormalMode)
+ case LandlordPage => answers => (
+ answers.get(TellUsAboutRentPage),
+ answers.get(TellUsAboutYourRenewedAgreementPage),
+ answers.get(TellUsAboutYourNewAgreementPage)
+ ) match {
+ case (Some(_),None, None) => uk.gov.hmrc.ngrraldfrontend.controllers.routes.WhatIsYourRentBasedOnController.show(NormalMode)
+ case (None, Some(_), None) => uk.gov.hmrc.ngrraldfrontend.controllers.routes.WhatTypeOfAgreementController.show(NormalMode)
+ case (None, None, Some(_)) => uk.gov.hmrc.ngrraldfrontend.controllers.routes.WhatTypeOfAgreementController.show(NormalMode)
+ case (Some(_), Some(_), Some(_)) => throw new RuntimeException("User should not have all three options")
+ case (None, None, None) => throw new NotFoundException("Failed to find values")
+ }
+ case WhatTypeOfAgreementPage => answers =>
+ answers.get(WhatTypeOfAgreementPage) match {
+ case Some(value) => value match {
+ case "Verbal" => uk.gov.hmrc.ngrraldfrontend.controllers.routes.AgreementVerbalController.show(NormalMode)
+ case _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.AgreementController.show(NormalMode)
+ }
+ case None => throw new NotFoundException("Failed to find value from What type of agreement page")
+ }
+ case AgreementPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.WhatIsYourRentBasedOnController.show(NormalMode)
+ case AgreementVerbalPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.HowMuchIsTotalAnnualRentController.show(NormalMode)
+ case WhatIsYourRentBasedOnPage => answers =>
+ answers.get(WhatIsYourRentBasedOnPage) match {
+ case Some(value) => value.rentBased match {
+ case "PercentageTurnover" => answers.get(TellUsAboutRentPage) match {
+ case Some(_) => uk.gov.hmrc.ngrraldfrontend.controllers.routes.WhatYourRentIncludesController.show(NormalMode)
+ case None => uk.gov.hmrc.ngrraldfrontend.controllers.routes.HowMuchIsTotalAnnualRentController.show(NormalMode)
+ }
+ case _ => answers.get(TellUsAboutRentPage) match {
+ case Some(value) => uk.gov.hmrc.ngrraldfrontend.controllers.routes.WhatYourRentIncludesController.show(NormalMode)
+ case None => uk.gov.hmrc.ngrraldfrontend.controllers.routes.AgreedRentChangeController.show(NormalMode)
+ }
+ }
+ case None => throw new NotFoundException("Not found answers")
+ }
+ case AgreedRentChangePage => answers =>
+ answers.get(AgreedRentChangePage) match {
+ case Some(value) => value match {
+ case "Yes" => uk.gov.hmrc.ngrraldfrontend.controllers.routes.ProvideDetailsOfFirstSecondRentPeriodController.show(NormalMode)
+ case _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.HowMuchIsTotalAnnualRentController.show(NormalMode)
+ }
+ case None => throw new NotFoundException("Failed to find answers")
+ }
+ case HowMuchIsTotalAnnualRentPage => answers => (answers.get(TellUsAboutYourRenewedAgreementPage),
+ answers.get(TellUsAboutYourNewAgreementPage)) match {
+ case (Some(_),None) => uk.gov.hmrc.ngrraldfrontend.controllers.routes.DidYouAgreeRentWithLandlordController.show(NormalMode)
+ case (None,Some(_)) => uk.gov.hmrc.ngrraldfrontend.controllers.routes.CheckRentFreePeriodController.show(NormalMode)
+ }
+ case DidYouAgreeRentWithLandlordPage => answers =>
+ answers.get(DidYouAgreeRentWithLandlordPage) match {
+ case Some(value) =>
+ value match {
+ case "YesTheLandlord" => answers.get(AgreedRentChangePage) match {
+ case Some(value) => value match {
+ case "Yes" => uk.gov.hmrc.ngrraldfrontend.controllers.routes.CheckRentFreePeriodController.show(NormalMode)
+ case _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentDatesAgreeController.show(NormalMode)
+ }
+ case None => uk.gov.hmrc.ngrraldfrontend.controllers.routes.CheckRentFreePeriodController.show(NormalMode)
+ }
+ case _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentInterimController.show(NormalMode)
+ }
+ case None => throw new NotFoundException("Failed to find answers")
+ }
+ case ProvideDetailsOfFirstSecondRentPeriodPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentPeriodsController.show(NormalMode)
+ case RentPeriodsPage => answers =>
+ answers.get(RentPeriodsPage) match {
+ case Some(value) => value match {
+ case "Yes" => uk.gov.hmrc.ngrraldfrontend.controllers.routes.ProvideDetailsOfFirstSecondRentPeriodController.show(NormalMode)
+ case _ => answers.get(TellUsAboutYourNewAgreementPage) match {
+ case Some(_) => uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentDatesAgreeController.show(NormalMode)
+ case None => uk.gov.hmrc.ngrraldfrontend.controllers.routes.DidYouAgreeRentWithLandlordController.show(NormalMode)
+ }
+ }
+ case None => throw new NotFoundException("Failed to find answers")
+ }
+ case CheckRentFreePeriodPage => answers =>
+ answers.get(CheckRentFreePeriodPage) match {
+ case Some(value) => value match {
+ case "Yes" => uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentFreePeriodController.show(NormalMode)
+ case _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentDatesAgreeStartController.show(NormalMode)
+ }
+ case None => ???
+ }
+ case RentInterimPage => answers =>
+ answers.get(RentInterimPage) match {
+ case Some(value) => value match {
+ case "Yes" => uk.gov.hmrc.ngrraldfrontend.controllers.routes.InterimRentSetByTheCourtController.show(NormalMode)
+ case _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.CheckRentFreePeriodController.show(NormalMode)
+ }
+ //TODO ADD A TECHNICAL DIFFICULTIES PAGE
+ case None => ???
+ }
+ case RentDatesAgreePage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.WhatYourRentIncludesController.show(NormalMode)
+ case WhatYourRentIncludesPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.DoesYourRentIncludeParkingController.show(NormalMode)
+ case RentDatesAgreeStartPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.WhatYourRentIncludesController.show(NormalMode)
+ case DoesYourRentIncludeParkingPage => answers =>
+ answers.get(DoesYourRentIncludeParkingPage) match {
+ case Some(value) => value match {
+ case "Yes" => uk.gov.hmrc.ngrraldfrontend.controllers.routes.HowManyParkingSpacesOrGaragesIncludedInRentController.show(NormalMode)
+ case _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.CheckRentFreePeriodController.show(NormalMode)
+ }
+ case None => throw new NotFoundException("Failed to find answers")
+ }
+ case HowManyParkingSpacesOrGaragesIncludedInRentPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.CheckRentFreePeriodController.show(NormalMode)
+ case InterimSetByTheCourtPage => answers =>
+ answers.get(ProvideDetailsOfFirstSecondRentPeriodPage) match {
+ case Some(_) => uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentDatesAgreeController.show(NormalMode)
+ case None => uk.gov.hmrc.ngrraldfrontend.controllers.routes.CheckRentFreePeriodController.show(NormalMode)
+ }
+ case RentFreePeriodPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentDatesAgreeStartController.show(NormalMode)
+ }
+
+ //TODO change to check your answers page
+ private val checkRouteMap: Page => UserAnswers => Call = {
+ case _ => _ => ???
+ }
+
+ def nextPage(page: Page, mode: Mode, userAnswers: UserAnswers): Call = mode match {
+ case NormalMode =>
+ normalRoutes(page)(userAnswers)
+ case CheckMode =>
+ checkRouteMap(page)(userAnswers)
+ }
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/AgreedRentChangePage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/AgreedRentChangePage.scala
new file mode 100644
index 00000000..7c301682
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/AgreedRentChangePage.scala
@@ -0,0 +1,26 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+
+case object AgreedRentChangePage extends QuestionPage[String] {
+
+ override def toString: String = "agreedRentChange"
+
+ override def path: JsPath = JsPath \ toString
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/AgreementPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/AgreementPage.scala
new file mode 100644
index 00000000..c9f8f034
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/AgreementPage.scala
@@ -0,0 +1,29 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+import uk.gov.hmrc.ngrraldfrontend.models.Agreement
+
+case object AgreementPage extends QuestionPage[Agreement] {
+
+ override def path: JsPath = JsPath \ toString
+
+ override def toString: String = "agreement"
+
+
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/AgreementVerbalPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/AgreementVerbalPage.scala
new file mode 100644
index 00000000..ce4e0566
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/AgreementVerbalPage.scala
@@ -0,0 +1,28 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+import uk.gov.hmrc.ngrraldfrontend.models.AgreementVerbal
+
+case object AgreementVerbalPage extends QuestionPage [AgreementVerbal]{
+
+ override def path: JsPath = JsPath \ toString
+
+ override def toString: String = "agreementVerbal"
+
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/CheckRentFreePeriodPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/CheckRentFreePeriodPage.scala
new file mode 100644
index 00000000..22a013e9
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/CheckRentFreePeriodPage.scala
@@ -0,0 +1,27 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+
+case object CheckRentFreePeriodPage extends QuestionPage[String]{
+
+ override def path: JsPath = JsPath \ toString
+
+ override def toString: String = "checkRentFreePeriod"
+
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/DidYouAgreeRentWithLandlordPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/DidYouAgreeRentWithLandlordPage.scala
new file mode 100644
index 00000000..ab7bf29c
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/DidYouAgreeRentWithLandlordPage.scala
@@ -0,0 +1,27 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+
+case object DidYouAgreeRentWithLandlordPage extends QuestionPage[String] {
+
+ override def toString: String = "didYouAgreeRentWithLandlordPage"
+
+ override def path: JsPath = JsPath \ toString
+
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/DoesYourRentIncludeParkingPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/DoesYourRentIncludeParkingPage.scala
new file mode 100644
index 00000000..ec7d396e
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/DoesYourRentIncludeParkingPage.scala
@@ -0,0 +1,27 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+
+case object DoesYourRentIncludeParkingPage extends QuestionPage[String] {
+
+ override def toString: String = "doesYourRentIncludeParking"
+
+ override def path: JsPath = JsPath \ toString
+
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/HowManyParkingSpacesOrGaragesIncludedInRentPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/HowManyParkingSpacesOrGaragesIncludedInRentPage.scala
new file mode 100644
index 00000000..3d964028
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/HowManyParkingSpacesOrGaragesIncludedInRentPage.scala
@@ -0,0 +1,28 @@
+/*
+ * 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.pages
+
+import uk.gov.hmrc.ngrraldfrontend.models.HowManyParkingSpacesOrGarages
+import play.api.libs.json.JsPath
+
+case object HowManyParkingSpacesOrGaragesIncludedInRentPage extends QuestionPage[HowManyParkingSpacesOrGarages] {
+
+ override def toString: String = "howManyParkingSpacesOrGaragesIncludedInRent"
+
+ override def path: JsPath = JsPath \ toString
+
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/HowMuchIsTotalAnnualRentPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/HowMuchIsTotalAnnualRentPage.scala
new file mode 100644
index 00000000..076b956c
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/HowMuchIsTotalAnnualRentPage.scala
@@ -0,0 +1,27 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+
+case object HowMuchIsTotalAnnualRentPage extends QuestionPage[BigDecimal]{
+
+ override def toString: String = "howMuchIsTotalAnnualRentPage"
+
+ override def path: JsPath = JsPath \ toString
+
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/InterimSetByTheCourtPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/InterimSetByTheCourtPage.scala
new file mode 100644
index 00000000..559ab403
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/InterimSetByTheCourtPage.scala
@@ -0,0 +1,29 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+import uk.gov.hmrc.ngrraldfrontend.models.InterimRentSetByTheCourt
+
+
+case object InterimSetByTheCourtPage extends QuestionPage[InterimRentSetByTheCourt] {
+
+ override def toString: String = "interimSetByTheCourt"
+
+ override def path: JsPath = JsPath \ toString
+
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/LandlordPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/LandlordPage.scala
new file mode 100644
index 00000000..0b4a1aee
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/LandlordPage.scala
@@ -0,0 +1,28 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+import uk.gov.hmrc.ngrraldfrontend.models.Landlord
+
+case object LandlordPage extends QuestionPage [Landlord]{
+
+ override def path: JsPath = JsPath \ toString
+
+ override def toString: String = "landlord"
+
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/Page.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/Page.scala
new file mode 100644
index 00000000..5b9779b3
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/Page.scala
@@ -0,0 +1,27 @@
+/*
+ * 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.pages
+
+import scala.language.implicitConversions
+
+trait Page
+
+object Page {
+
+ implicit def toString(page: Page): String =
+ page.toString
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/ProvideDetailsOfFirstSecondRentPeriodPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/ProvideDetailsOfFirstSecondRentPeriodPage.scala
new file mode 100644
index 00000000..7d68e253
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/ProvideDetailsOfFirstSecondRentPeriodPage.scala
@@ -0,0 +1,28 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+import uk.gov.hmrc.ngrraldfrontend.models.ProvideDetailsOfFirstSecondRentPeriod
+
+case object ProvideDetailsOfFirstSecondRentPeriodPage extends QuestionPage[ProvideDetailsOfFirstSecondRentPeriod] {
+
+ override def path: JsPath = JsPath \ toString
+
+ override def toString: String = "provideDetailsOfFirstSecondRentPeriod"
+
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/QuestionPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/QuestionPage.scala
new file mode 100644
index 00000000..3e42806d
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/QuestionPage.scala
@@ -0,0 +1,21 @@
+/*
+ * 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.pages
+
+import uk.gov.hmrc.ngrraldfrontend.queries.{Gettable, Settable}
+
+trait QuestionPage[A] extends Page with Gettable[A] with Settable[A]
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/RentDatesAgreePage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/RentDatesAgreePage.scala
new file mode 100644
index 00000000..59dd6aa5
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/RentDatesAgreePage.scala
@@ -0,0 +1,27 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+
+case object RentDatesAgreePage extends QuestionPage[String] {
+
+ override def path: JsPath = JsPath \ toString
+
+ override def toString: String = "rentDatesAgree"
+
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/RentDatesAgreeStartPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/RentDatesAgreeStartPage.scala
new file mode 100644
index 00000000..c56816fe
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/RentDatesAgreeStartPage.scala
@@ -0,0 +1,28 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+import uk.gov.hmrc.ngrraldfrontend.models.RentDatesAgreeStart
+
+case object RentDatesAgreeStartPage extends QuestionPage[RentDatesAgreeStart] {
+
+ override def toString: String = "rentDatesAgreeStart"
+
+ override def path: JsPath = JsPath \ toString
+
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/RentFreePeriodPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/RentFreePeriodPage.scala
new file mode 100644
index 00000000..fa1c466f
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/RentFreePeriodPage.scala
@@ -0,0 +1,28 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+import uk.gov.hmrc.ngrraldfrontend.models.RentFreePeriod
+
+case object RentFreePeriodPage extends QuestionPage[RentFreePeriod] {
+
+ override def toString: String = "rentFreePeriod"
+
+ override def path: JsPath = JsPath \ toString
+
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/RentInterimPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/RentInterimPage.scala
new file mode 100644
index 00000000..c7c34645
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/RentInterimPage.scala
@@ -0,0 +1,27 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+
+case object RentInterimPage extends QuestionPage[String] {
+
+ override def path: JsPath = JsPath \ toString
+
+ override def toString: String = "rentInterim"
+
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/RentPeriodsPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/RentPeriodsPage.scala
new file mode 100644
index 00000000..b881c1f8
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/RentPeriodsPage.scala
@@ -0,0 +1,27 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+
+case object RentPeriodsPage extends QuestionPage[String] {
+
+ override def path: JsPath = JsPath \ toString
+
+ override def toString: String = "rentPeriods"
+
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/TellUsAboutRentPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/TellUsAboutRentPage.scala
new file mode 100644
index 00000000..a197d130
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/TellUsAboutRentPage.scala
@@ -0,0 +1,27 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+import uk.gov.hmrc.ngrraldfrontend.models.AgreementType
+import uk.gov.hmrc.ngrraldfrontend.queries.{Gettable, Settable}
+
+case object TellUsAboutRentPage extends QuestionPage[AgreementType]{
+
+ override def path: JsPath = JsPath \ toString
+ override def toString: String = "tellUsAboutRent"
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/TellUsAboutYourNewAgreementPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/TellUsAboutYourNewAgreementPage.scala
new file mode 100644
index 00000000..6d988b6e
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/TellUsAboutYourNewAgreementPage.scala
@@ -0,0 +1,27 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+import uk.gov.hmrc.ngrraldfrontend.models.AgreementType
+
+case object TellUsAboutYourNewAgreementPage extends QuestionPage[AgreementType] {
+
+ override def path: JsPath = JsPath \ toString
+ override def toString: String = "tellUsAboutYourNewAgreement"
+
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/TellUsAboutYourRenewedAgreementPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/TellUsAboutYourRenewedAgreementPage.scala
new file mode 100644
index 00000000..4f85faef
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/TellUsAboutYourRenewedAgreementPage.scala
@@ -0,0 +1,27 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+import uk.gov.hmrc.ngrraldfrontend.models.AgreementType
+
+case object TellUsAboutYourRenewedAgreementPage extends QuestionPage[AgreementType]{
+
+ override def path: JsPath = JsPath \ toString
+ override def toString: String = "tellUsAboutRenewedAgreement"
+
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/WhatIsYourRentBasedOnPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/WhatIsYourRentBasedOnPage.scala
new file mode 100644
index 00000000..89501e51
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/WhatIsYourRentBasedOnPage.scala
@@ -0,0 +1,28 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+import uk.gov.hmrc.ngrraldfrontend.models.RentBasedOn
+
+case object WhatIsYourRentBasedOnPage extends QuestionPage[RentBasedOn]{
+
+ override def path: JsPath = JsPath \ toString
+
+ override def toString: String = "whatIsYourRentBasedOn"
+
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/WhatTypeOfAgreementPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/WhatTypeOfAgreementPage.scala
new file mode 100644
index 00000000..f23dfcec
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/WhatTypeOfAgreementPage.scala
@@ -0,0 +1,28 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+import uk.gov.hmrc.ngrraldfrontend.models.{AgreementType, TypeOfAgreement}
+
+case object WhatTypeOfAgreementPage extends QuestionPage[String] {
+
+ override def path: JsPath = JsPath \ toString
+
+ override def toString: String = "whatTypeOfAgreement"
+
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/WhatTypeOfLeaseRenewalPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/WhatTypeOfLeaseRenewalPage.scala
new file mode 100644
index 00000000..8c8f09d2
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/WhatTypeOfLeaseRenewalPage.scala
@@ -0,0 +1,26 @@
+/*
+ * 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.pages
+
+import play.api.libs.json.JsPath
+
+case object WhatTypeOfLeaseRenewalPage extends QuestionPage[String] {
+
+ override def path: JsPath = JsPath \ toString
+
+ override def toString: String = "whatTypeOfLeaseRenewal"
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/WhatYourRentIncludesPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/WhatYourRentIncludesPage.scala
new file mode 100644
index 00000000..e7ccfbd6
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/WhatYourRentIncludesPage.scala
@@ -0,0 +1,28 @@
+/*
+ * 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.pages
+
+import uk.gov.hmrc.ngrraldfrontend.models.WhatYourRentIncludes
+import play.api.libs.json.JsPath
+
+case object WhatYourRentIncludesPage extends QuestionPage[WhatYourRentIncludes] {
+
+ override def toString: String = "whatYourRentIncludes"
+
+ override def path: JsPath = JsPath \ toString
+
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/queries/Query.scala b/app/uk/gov/hmrc/ngrraldfrontend/queries/Query.scala
new file mode 100644
index 00000000..dfe9fb7b
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/queries/Query.scala
@@ -0,0 +1,35 @@
+/*
+ * 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.queries
+
+import play.api.libs.json.JsPath
+import uk.gov.hmrc.ngrraldfrontend.models.UserAnswers
+
+import scala.util.{Success, Try}
+
+sealed trait Query {
+
+ def path: JsPath
+}
+
+trait Gettable[A] extends Query
+
+trait Settable[A] extends Query {
+
+ def cleanup(value: Option[A], userAnswers: UserAnswers): Try[UserAnswers] =
+ Success(userAnswers)
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepo.scala b/app/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepo.scala
deleted file mode 100644
index 067ef319..00000000
--- a/app/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepo.scala
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- * 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.repo
-
-import com.google.inject.Singleton
-import org.mongodb.scala.bson.conversions.Bson
-import org.mongodb.scala.model.*
-import org.mongodb.scala.model.Filters.equal
-import org.mongodb.scala.model.Indexes.{ascending, descending}
-import org.mongodb.scala.model.Updates.combine
-import play.api.Logging
-import uk.gov.hmrc.mongo.MongoComponent
-import uk.gov.hmrc.mongo.play.json.PlayMongoRepository
-import uk.gov.hmrc.ngrraldfrontend.config.FrontendAppConfig
-import uk.gov.hmrc.ngrraldfrontend.models.RaldUserAnswers
-import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-
-import java.time.Instant
-import java.util.concurrent.TimeUnit
-import javax.inject.Inject
-import scala.concurrent.{ExecutionContext, Future}
-import scala.util.{Failure, Success}
-
-@Singleton
-case class RaldRepo @Inject()(mongo: MongoComponent,
- config: FrontendAppConfig
- )(implicit ec: ExecutionContext)
- extends PlayMongoRepository[RaldUserAnswers](
- collectionName = "rald",
- mongoComponent = mongo,
- domainFormat = RaldUserAnswers.format,
- indexes = Seq(
- IndexModel(
- descending("createdAt"),
- IndexOptions()
- .unique(false)
- .name("createdAt")
- .expireAfter(config.timeToLive.toLong, TimeUnit.HOURS)
- ),
- IndexModel(
- ascending("credId.value"),
- IndexOptions()
- .background(false)
- .name("credId.value")
- .unique(true)
- .partialFilterExpression(Filters.gte("credId.value", ""))
- )
- )
- ) with Logging {
-
- override lazy val requiresTtlIndex: Boolean = false
-
- private def filterByCredId(credId: CredId): Bson = equal("credId.value", credId.value)
-
- def upsertRaldUserAnswers(raldUserAnswers: RaldUserAnswers): Future[Boolean] = {
- val errorMsg = s"Rald user answers has not been inserted"
-
- collection.replaceOne(
- filter = equal("credId.value", raldUserAnswers.credId.value),
- replacement = raldUserAnswers,
- options = ReplaceOptions().upsert(true)
- ).toFuture().transformWith {
- case Success(result) =>
- logger.info(s"Rald user answers has been upsert for credId: ${raldUserAnswers.credId.value}")
- Future.successful(result.wasAcknowledged())
- case Failure(exception) =>
- logger.error(errorMsg)
- Future.failed(new IllegalStateException(s"$errorMsg: ${exception.getMessage} ${exception.getCause}"))
- }
- }
-
- private def findAndUpdateByCredId(credId: CredId, updates: Bson*): Future[Option[RaldUserAnswers]] = {
- collection.findOneAndUpdate(filterByCredId(credId),
- combine(updates :+ Updates.set("createdAt", Instant.now()): _*),
- FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER))
- .toFutureOption()
- }
-
- def insertTypeOfAgreement(credId: CredId, whatTypeOfAgreement: String): Future[Option[RaldUserAnswers]] = {
- findAndUpdateByCredId(credId, Updates.set("whatTypeOfAgreement", whatTypeOfAgreement))
- }
-
- def insertLandlord(credId: CredId, landlordName: String, landLordType:String, landlordOther:Option[String]): Future[Option[RaldUserAnswers]] = {
- val name = Seq(Updates.set("landlord.landlordName", landlordName))
- val landlord = Updates.set("landlord.landLordType", landLordType)
-
- val radio = landlordOther match {
- case Some(otherDesc) =>
- name :+ landlord :+ Updates.set("landlord.landlordOtherDesc", otherDesc)
- case None =>
- name :+ landlord
- }
- findAndUpdateByCredId(credId = credId, radio: _*)
- }
-
- def insertAgreement(credId: CredId, agreementStart: String, openEndedRadio: String, openEndedDate: Option[String], breakClauseRadio: String, breakClauseInfo:Option[String]): Future[Option[RaldUserAnswers]] = {
- val startDate = Updates.set("agreement.agreementStart", agreementStart)
- val openEnded = Updates.set("agreement.isOpenEnded", openEndedRadio match{
- case answer if(answer == "YesOpenEnded") => true
- case _ => false
- })
- val breakClause = Updates.set("agreement.haveBreakClause", breakClauseRadio match {
- case openEndedRadio if(openEndedRadio == "YesBreakClause") => true
- case _ => false
- })
- val openEndedDateAnswer = Updates.set("agreement.openEndedDate", openEndedDate.orNull)
- val breakClauseInfoAnswer = Updates.set("agreement.breakClauseInfo", breakClauseInfo.orNull)
-
- val answers = Seq(startDate , openEnded , openEndedDateAnswer , breakClause , breakClauseInfoAnswer)
- findAndUpdateByCredId(credId = credId, answers: _*)
- }
-
- def insertProvideDetailsOfFirstSecondRentPeriod(
- credId: CredId,
- firstDateStart: String,
- firstDateEnd: String,
- firstRentPeriodRadio: String,
- firstRentPeriodAmount: Option[String],
- secondDateStart: String,
- secondDateEnd: String,
- secondHowMuchIsRent: BigDecimal
- ): Future[Option[RaldUserAnswers]] = {
-
- val updates = Seq(
- Updates.set("provideDetailsOfFirstSecondRentPeriod.firstDateStart", firstDateStart),
- Updates.set("provideDetailsOfFirstSecondRentPeriod.firstDateEnd", firstDateEnd),
- Updates.set("provideDetailsOfFirstSecondRentPeriod.firstRentPeriodRadio", firstRentPeriodRadio match {
- case "yesPayedRent" => true
- case _ => false
- }),
- firstRentPeriodRadio match
- case "yesPayedRent" =>
- Updates.set("provideDetailsOfFirstSecondRentPeriod.firstRentPeriodAmount", firstRentPeriodAmount.get)
- case _ =>
- Updates.unset("provideDetailsOfFirstSecondRentPeriod.firstRentPeriodAmount"),
- Updates.set("provideDetailsOfFirstSecondRentPeriod.secondDateStart", secondDateStart),
- Updates.set("provideDetailsOfFirstSecondRentPeriod.secondDateEnd", secondDateEnd),
- Updates.set("provideDetailsOfFirstSecondRentPeriod.secondHowMuchIsRent", secondHowMuchIsRent.toString)
- )
-
- findAndUpdateByCredId(credId, updates: _*)
- }
-
- 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.orNull))
- findAndUpdateByCredId(credId, updates: _*)
- }
-
- def insertTypeOfRenewal(credId: CredId, whatTypeOfRenewal: String): Future[Option[RaldUserAnswers]] = {
- findAndUpdateByCredId(credId, Updates.set("whatTypeOfRenewal", whatTypeOfRenewal))
- }
-
- def insertAgreedRentChange(credId: CredId, agreedRentChange: String): Future[Option[RaldUserAnswers]] = {
- findAndUpdateByCredId(credId, Updates.set("agreedRentChange", agreedRentChange))
- }
-
- def insertHasRentFreePeriod(credId: CredId, hasRentFreePeriod: String): Future[Option[RaldUserAnswers]] = {
- hasRentFreePeriod match {
- case "Yes" => findAndUpdateByCredId(credId, Updates.set("hasRentFreePeriod", true))
- case _ => findAndUpdateByCredId(credId, Updates.set("hasRentFreePeriod", false))
- }
-
- }
-
- def insertAnnualRent(credId: CredId, rentAmount: BigDecimal): Future[Option[RaldUserAnswers]] = {
- findAndUpdateByCredId(credId, Updates.set("rentAmount", rentAmount.toString()))
- }
-
- 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.orNull))
- findAndUpdateByCredId(credId, updates: _*)
- }
-
- def insertDidYouAgreeRentWithLandlord(credId: CredId, radioValue: String): Future[Option[RaldUserAnswers]] = {
- findAndUpdateByCredId(credId, Updates.set("didYouAgreeRentWithLandlord", if(radioValue == "YesTheLandlord") true else false))
- }
-
- def insertRentDates(credId: CredId, rentDates: String): Future[Option[RaldUserAnswers]] = {
- findAndUpdateByCredId(credId, Updates.set("agreedRentDate", rentDates))
- }
-
- def insertRentPeriod(credId: CredId, hasAnotherRentPeriod: String): Future[Option[RaldUserAnswers]] = {
- hasAnotherRentPeriod match {
- case "Yes" => findAndUpdateByCredId(credId, Updates.set("hasAnotherRentPeriod", true))
- case _ => findAndUpdateByCredId(credId, Updates.set("hasAnotherRentPeriod", false))
- }
- }
-
- def insertWhatYourRentIncludes(
- credId: CredId,
- livingAccommodationRadio: String,
- rentPartAddressRadio: String,
- rentEmptyShellRadio: String,
- rentIncBusinessRatesRadio: String,
- rentIncWaterChargesRadio: String,
- rentIncServiceRadio:String,
- bedroomNumbers: Option[String]
- ): Future[Option[RaldUserAnswers]] = {
-
- def radioConvert(value: String): Boolean = {
- value match {
- case value if value.contains("Yes") => true
- case _ => false
- }
- }
-
- val isIncludedLivingAccommodation: Boolean = radioConvert(livingAccommodationRadio)
- val updates = Seq(
- Updates.set("whatYourRentIncludes.livingAccommodation", isIncludedLivingAccommodation),
- Updates.set("whatYourRentIncludes.rentPartAddress", radioConvert(rentPartAddressRadio)),
- Updates.set("whatYourRentIncludes.rentEmptyShell", radioConvert(rentEmptyShellRadio)),
- Updates.set("whatYourRentIncludes.rentIncBusinessRates", radioConvert(rentIncBusinessRatesRadio)),
- Updates.set("whatYourRentIncludes.rentIncWaterCharges", radioConvert(rentIncWaterChargesRadio)),
- Updates.set("whatYourRentIncludes.rentIncService", radioConvert(rentIncServiceRadio)),
- isIncludedLivingAccommodation match
- case true =>
- Updates.set("whatYourRentIncludes.bedroomNumbers", bedroomNumbers.map(Integer.parseInt(_)).getOrElse(0))
- case false =>
- Updates.unset("whatYourRentIncludes.bedroomNumbers")
- )
-
- findAndUpdateByCredId(credId, updates: _*)
- }
-
- def insertRentAgreeStartDates(credId: CredId, agreedDates: String, startPayingDate: String): Future[Option[RaldUserAnswers]] = {
- val updates: Seq[Bson] = Seq(Updates.set("rentDatesAgreeStart.agreedDate", agreedDates),
- Updates.set("rentDatesAgreeStart.startPayingDate", startPayingDate))
- findAndUpdateByCredId(credId, updates: _*)
- }
-
- def insertHowManyParkingSpacesOrGaragesIncludedInRent(credId: CredId, uncoveredSpaces: Int, coveredSpaces: Int, garages:Int): Future[Option[RaldUserAnswers]] = {
- val updates = Seq(
- Updates.set("howManyParkingSpacesOrGaragesIncludedInRent.uncoveredSpaces", uncoveredSpaces.toString()),
- Updates.set("howManyParkingSpacesOrGaragesIncludedInRent.coveredSpaces", coveredSpaces.toString()),
- Updates.set("howManyParkingSpacesOrGaragesIncludedInRent.garages", garages.toString())
- )
- findAndUpdateByCredId(credId, updates: _*)
- }
-
- def insertInterimRentSetByTheCourt(credId: CredId, amount: BigDecimal, date: String) = {
- val updates = Seq(
- Updates.set("interimRentSetByTheCourt.amount", amount.toString()),
- Updates.set("interimRentSetByTheCourt.date", date),
- )
- findAndUpdateByCredId(credId, updates: _*)
- }
- def insertRentFreePeriod(credId: CredId, rentFreePeriodMonths: Int, reasons: String): Future[Option[RaldUserAnswers]] = {
- val updates: Seq[Bson] = Seq(Updates.set("rentFreePeriod.months", rentFreePeriodMonths),
- Updates.set("rentFreePeriod.reasons", reasons))
- findAndUpdateByCredId(credId, updates: _*)
- }
-
-
- def findByCredId(credId: CredId): Future[Option[RaldUserAnswers]] = {
- collection.find(
- equal("credId.value", credId.value)
- ).headOption()
- }
-
- def insertDoesYourRentIncludeParking(credId: CredId, radioValue: String): Future[Option[RaldUserAnswers]] = {
- radioValue match {
- case "Yes" => findAndUpdateByCredId(credId, Updates.set("doesYourRentIncludeParking", true))
- case _ => findAndUpdateByCredId(credId, Updates.set("doesYourRentIncludeParking", false))
- }
- }
-}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/repo/SessionRepository.scala b/app/uk/gov/hmrc/ngrraldfrontend/repo/SessionRepository.scala
new file mode 100644
index 00000000..fbff1c03
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/repo/SessionRepository.scala
@@ -0,0 +1,97 @@
+/*
+ * 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.repo
+
+import org.mongodb.scala.bson.conversions.Bson
+import org.mongodb.scala.model.*
+import play.api.libs.json.Format
+import uk.gov.hmrc.mdc.Mdc
+import uk.gov.hmrc.mongo.MongoComponent
+import uk.gov.hmrc.mongo.play.json.PlayMongoRepository
+import uk.gov.hmrc.mongo.play.json.formats.MongoJavatimeFormats
+import uk.gov.hmrc.ngrraldfrontend.config.FrontendAppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.UserAnswers
+
+import java.time.{Clock, Instant}
+import java.util.concurrent.TimeUnit
+import javax.inject.{Inject, Singleton}
+import scala.concurrent.{ExecutionContext, Future}
+
+@Singleton
+class SessionRepository @Inject()(
+ mongoComponent: MongoComponent,
+ appConfig: FrontendAppConfig,
+ clock: Clock
+ )(implicit ec: ExecutionContext)
+ extends PlayMongoRepository[UserAnswers](
+ collectionName = "user-answers",
+ mongoComponent = mongoComponent,
+ domainFormat = UserAnswers.format,
+ indexes = Seq(
+ IndexModel(
+ Indexes.ascending("lastUpdated"),
+ IndexOptions()
+ .name("lastUpdatedIdx")
+ .expireAfter(appConfig.cacheTtl, TimeUnit.SECONDS)
+ )
+ )
+ ) {
+
+ implicit val instantFormat: Format[Instant] = MongoJavatimeFormats.instantFormat
+
+ private def byId(id: String): Bson = Filters.equal("_id", id)
+
+ def keepAlive(id: String): Future[Boolean] = Mdc.preservingMdc {
+ collection
+ .updateOne(
+ filter = byId(id),
+ update = Updates.set("lastUpdated", Instant.now(clock)),
+ )
+ .toFuture()
+ .map(_ => true)
+ }
+
+ def get(id: String): Future[Option[UserAnswers]] = Mdc.preservingMdc {
+ keepAlive(id).flatMap {
+ _ =>
+ collection
+ .find(byId(id))
+ .headOption()
+ }
+ }
+
+ def set(answers: UserAnswers): Future[Boolean] = Mdc.preservingMdc {
+
+ val updatedAnswers = answers.copy(lastUpdated = Instant.now(clock))
+
+ collection
+ .replaceOne(
+ filter = byId(updatedAnswers.credId),
+ replacement = updatedAnswers,
+ options = ReplaceOptions().upsert(true)
+ )
+ .toFuture()
+ .map(_ => true)
+ }
+
+ def clear(credId: String): Future[Boolean] = Mdc.preservingMdc {
+ collection
+ .deleteOne(byId(credId))
+ .toFuture()
+ .map(_ => true)
+ }
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/AgreedRentChangeView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/AgreedRentChangeView.scala.html
index 1909eb81..d059daad 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/views/AgreedRentChangeView.scala.html
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/AgreedRentChangeView.scala.html
@@ -29,10 +29,10 @@
saveAndContinueButton: saveAndContinueButton
)
-@(form:Form[AgreedRentChangeForm], radios: Radios, propertyAddress: String)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
+@(form:Form[AgreedRentChangeForm], radios: Radios, propertyAddress: String, mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
@layout(pageTitle = Some(messages("agreedRentChange.title")), showBackLink = true, fullWidth = false) {
- @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.AgreedRentChangeController.submit, Symbol("autoComplete") -> "off") {
+ @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.AgreedRentChangeController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/AgreementVerbalView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/AgreementVerbalView.scala.html
index 57597e4f..3d6b2fe1 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/views/AgreementVerbalView.scala.html
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/AgreementVerbalView.scala.html
@@ -30,11 +30,11 @@
saveAndContinueButton: saveAndContinueButton
)
-@(form: Form[AgreementVerbalForm], ngrRadio: Radios, selectedPropertyAddress: String)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
+@(form: Form[AgreementVerbalForm], ngrRadio: Radios, selectedPropertyAddress: String, mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
@layout(pageTitle = Some(messages("agreementVerbal.title")), showBackLink = true, fullWidth = false) {
- @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.AgreementVerbalController.submit, Symbol("autoComplete") -> "off") {
+ @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.AgreementVerbalController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/AgreementView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/AgreementView.scala.html
index e07611db..960a7851 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/views/AgreementView.scala.html
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/AgreementView.scala.html
@@ -30,11 +30,11 @@
saveAndContinueButton: saveAndContinueButton
)
-@(selectedPropertyAddress: String, form: Form[AgreementForm], dateInput: DateInput, openEndedRadio: Radios, breakClauseRadio: Radios)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
+@(selectedPropertyAddress: String, form: Form[AgreementForm], dateInput: DateInput, openEndedRadio: Radios, breakClauseRadio: Radios, mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
@layout(pageTitle = Some(messages("agreement.title")), showBackLink = true, fullWidth = false) {
- @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.AgreementController.submit, Symbol("autoComplete") -> "off") {
+ @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.AgreementController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/CheckRentFreePeriodView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/CheckRentFreePeriodView.scala.html
index 1d794416..cc38147e 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/views/CheckRentFreePeriodView.scala.html
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/CheckRentFreePeriodView.scala.html
@@ -19,6 +19,7 @@
@import uk.gov.hmrc.ngrraldfrontend.views.html.components._
@import uk.gov.hmrc.ngrraldfrontend.viewmodels.govuk.all._
@import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+@import uk.gov.hmrc.ngrraldfrontend.models.components.NavigationBarContent
@import uk.gov.hmrc.ngrraldfrontend.models.forms.CheckRentFreePeriodForm
@@ -29,10 +30,10 @@
govukErrorSummary: GovukErrorSummary,
saveAndContinueButton: saveAndContinueButton)
-@(form:Form[CheckRentFreePeriodForm], radios: Radios, propertyAddress: String)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
+@(form:Form[CheckRentFreePeriodForm], radios: Radios, propertyAddress: String,mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
@layout(pageTitle = Some(messages("checkRentPeriod.title")), showBackLink = true, fullWidth = false) {
- @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.CheckRentFreePeriodController.submit, Symbol("autoComplete") -> "off") {
+ @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.CheckRentFreePeriodController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/DidYouAgreeRentWithLandlordView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/DidYouAgreeRentWithLandlordView.scala.html
index 2d433e87..9bf27e71 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/views/DidYouAgreeRentWithLandlordView.scala.html
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/DidYouAgreeRentWithLandlordView.scala.html
@@ -28,11 +28,11 @@
formHelper: FormWithCSRF
)
-@(selectedPropertyAddress: String, form: Form[DidYouAgreeRentWithLandlordForm], ngrRadio: Radios)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
+@(selectedPropertyAddress: String, form: Form[DidYouAgreeRentWithLandlordForm], ngrRadio: Radios, mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
@layout(pageTitle = Some(messages("didYouAgreeRentWithLandlord.title")), showBackLink = true, fullWidth = false) {
- @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.DidYouAgreeRentWithLandlordController.submit, Symbol("autoComplete") -> "off") {
+ @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.DidYouAgreeRentWithLandlordController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/DoesYourRentIncludeParkingView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/DoesYourRentIncludeParkingView.scala.html
index ebb2c7fe..e8f4f253 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/views/DoesYourRentIncludeParkingView.scala.html
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/DoesYourRentIncludeParkingView.scala.html
@@ -29,10 +29,10 @@
saveAndContinueButton: saveAndContinueButton
)
-@(selectedPropertyAddress: String, form: Form[DoesYourRentIncludeParkingForm], ngrRadio: Radios)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
+@(selectedPropertyAddress: String, form: Form[DoesYourRentIncludeParkingForm], ngrRadio: Radios, mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
@layout(pageTitle = Some(messages("doesYourRentIncludeParking.title")), showBackLink = true, fullWidth = false) {
- @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.DoesYourRentIncludeParkingController.submit, Symbol("autoComplete") -> "off") {
+ @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.DoesYourRentIncludeParkingController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/HowManyParkingSpacesOrGaragesIncludedInRentView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/HowManyParkingSpacesOrGaragesIncludedInRentView.scala.html
index cd69f249..b26026e0 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/views/HowManyParkingSpacesOrGaragesIncludedInRentView.scala.html
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/HowManyParkingSpacesOrGaragesIncludedInRentView.scala.html
@@ -28,10 +28,10 @@
saveAndContinueButton: saveAndContinueButton
)
-@(form:Form[HowManyParkingSpacesOrGaragesIncludedInRentForm], propertyAddress: String, uncoveredSpaces: Html, coveredSpaces: Html, garages: Html)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
+@(form:Form[HowManyParkingSpacesOrGaragesIncludedInRentForm], propertyAddress: String, uncoveredSpaces: Html, coveredSpaces: Html, garages: Html, mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
@layout(pageTitle = Some(messages("howManyParkingSpacesOrGaragesIncludedInRent.title")), showBackLink = true, fullWidth = false) {
- @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.HowManyParkingSpacesOrGaragesIncludedInRentController.submit, Symbol("autoComplete") -> "off") {
+ @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.HowManyParkingSpacesOrGaragesIncludedInRentController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/HowMuchIsTotalAnnualRentView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/HowMuchIsTotalAnnualRentView.scala.html
index 3cd6266b..bded5c5c 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/views/HowMuchIsTotalAnnualRentView.scala.html
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/HowMuchIsTotalAnnualRentView.scala.html
@@ -29,10 +29,10 @@
saveAndContinueButton: saveAndContinueButton
)
-@(form:Form[HowMuchIsTotalAnnualRentForm], propertyAddress: String)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
+@(form:Form[HowMuchIsTotalAnnualRentForm], propertyAddress: String, mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
@layout(pageTitle = Some(messages("typeOfLeaseRenewal.title")), showBackLink = true, fullWidth = false) {
-@formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.HowMuchIsTotalAnnualRentController.submit, Symbol("autoComplete") -> "off") {
+@formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.HowMuchIsTotalAnnualRentController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/InterimRentSetByTheCourtView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/InterimRentSetByTheCourtView.scala.html
index 3dbd14fd..b1f631d2 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/views/InterimRentSetByTheCourtView.scala.html
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/InterimRentSetByTheCourtView.scala.html
@@ -29,10 +29,10 @@
saveAndContinueButton: saveAndContinueButton
)
-@(form:Form[InterimRentSetByTheCourtForm], propertyAddress: String, interimAmount: Html)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
+@(form:Form[InterimRentSetByTheCourtForm], propertyAddress: String, interimAmount: Html, mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
@layout(pageTitle = Some(messages("interimRentSetByTheCourt.title")), showBackLink = true, fullWidth = false) {
- @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.InterimRentSetByTheCourtController.submit, Symbol("autoComplete") -> "off") {
+ @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.InterimRentSetByTheCourtController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/LandlordView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/LandlordView.scala.html
index 9ae52be0..24d71f14 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/views/LandlordView.scala.html
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/LandlordView.scala.html
@@ -16,6 +16,9 @@
@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._
@@ -30,11 +33,11 @@
saveAndContinueButton: saveAndContinueButton
)
-@(selectedPropertyAddress: String, form: Form[LandlordForm], ngrRadio: Radios)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
+@(selectedPropertyAddress: String, form: Form[LandlordForm], ngrRadio: Radios, mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
@layout(pageTitle = Some(messages("landlord.title")), showBackLink = true, fullWidth = false) {
- @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.LandlordController.submit, Symbol("autoComplete") -> "off") {
+ @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.LandlordController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/ProvideDetailsOfFirstSecondRentPeriodView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/ProvideDetailsOfFirstSecondRentPeriodView.scala.html
index fca6ef14..bac31b80 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/views/ProvideDetailsOfFirstSecondRentPeriodView.scala.html
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/ProvideDetailsOfFirstSecondRentPeriodView.scala.html
@@ -38,12 +38,13 @@
firstDateEndInput:DateInput,
openEndedRadio: Radios,
secondDateStartInput: DateInput,
- secondDateEndInput: DateInput
+ secondDateEndInput: DateInput,
+ mode: Mode
)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
@layout(pageTitle = Some(messages("provideDetailsOfFirstSecondRentPeriod.title")), showBackLink = true, fullWidth = false) {
- @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.ProvideDetailsOfFirstSecondRentPeriodController.submit, Symbol("autoComplete") -> "off") {
+ @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form, Some("provideDetailsOfFirstSecondRentPeriod"),
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/RentDatesAgreeStartView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/RentDatesAgreeStartView.scala.html
index 9fafed57..d94a7035 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/views/RentDatesAgreeStartView.scala.html
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/RentDatesAgreeStartView.scala.html
@@ -29,11 +29,11 @@
saveAndContinueButton: saveAndContinueButton
)
-@(form: Form[RentDatesAgreeStartForm], selectedPropertyAddress: String)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
+@(form: Form[RentDatesAgreeStartForm], selectedPropertyAddress: String, mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
@layout(pageTitle = Some(messages("rentDatesAgreeStart.title")), showBackLink = true, fullWidth = false) {
- @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentDatesAgreeStartController.submit, Symbol("autoComplete") -> "off") {
+ @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentDatesAgreeStartController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form, Some("rentDatesAgreeStart"), Some(Seq("agreedDate", "startPayingDate"))))
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/RentDatesAgreeView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/RentDatesAgreeView.scala.html
index 153592e4..9344bc7c 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/views/RentDatesAgreeView.scala.html
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/RentDatesAgreeView.scala.html
@@ -32,10 +32,11 @@
@(
form:Form[RentDatesAgreeForm],
dateInput: DateInput,
- propertyAddress: String)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
+ propertyAddress: String,
+ mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
@layout(pageTitle = Some(messages("rentDatesAgree.title")), showBackLink = true, fullWidth = false) {
- @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentDatesAgreeController.submit, Symbol("autoComplete") -> "off") {
+ @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentDatesAgreeController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form, Some("rentDatesAgree"), Some(Seq("date"))))
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/RentFreePeriodView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/RentFreePeriodView.scala.html
index 81e8543e..1ce52011 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/views/RentFreePeriodView.scala.html
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/RentFreePeriodView.scala.html
@@ -31,11 +31,11 @@
saveAndContinueButton: saveAndContinueButton
)
-@(form: Form[RentFreePeriodForm], selectedPropertyAddress: String)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
+@(form: Form[RentFreePeriodForm], selectedPropertyAddress: String, mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
@layout(pageTitle = Some(messages("rentFreePeriod.title")), showBackLink = true, fullWidth = false) {
- @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentFreePeriodController.submit, Symbol("autoComplete") -> "off") {
+ @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentFreePeriodController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/RentInterimView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/RentInterimView.scala.html
index 26d8f310..4f5991ea 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/views/RentInterimView.scala.html
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/RentInterimView.scala.html
@@ -29,10 +29,10 @@
saveAndContinueButton: saveAndContinueButton
)
-@(form:Form[RentInterimForm], radios: Radios, propertyAddress: String)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
+@(form:Form[RentInterimForm], radios: Radios, propertyAddress: String, mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
@layout(pageTitle = Some(messages("rentInterim.title")), showBackLink = true, fullWidth = false) {
- @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentInterimController.submit, Symbol("autoComplete") -> "off") {
+ @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentInterimController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/RentPeriodView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/RentPeriodView.scala.html
index 56dfc69c..06da1748 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/views/RentPeriodView.scala.html
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/RentPeriodView.scala.html
@@ -29,11 +29,11 @@
govukTable : GovukTable
)
-@(selectedPropertyAddress: String, form: Form[RentPeriodsForm], firstTable: Table, secondTable: Table, ngrRadio: Radios)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
+@(selectedPropertyAddress: String, form: Form[RentPeriodsForm], firstTable: Table, secondTable: Table, ngrRadio: Radios, mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
@layout(pageTitle = Some(messages("rentPeriods.title")), showBackLink = true, fullWidth = false) {
- @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentPeriodsController.submit, Symbol("autoComplete") -> "off") {
+ @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentPeriodsController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/WhatIsYourRentBasedOnView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/WhatIsYourRentBasedOnView.scala.html
index 71383245..7050d061 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/views/WhatIsYourRentBasedOnView.scala.html
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/WhatIsYourRentBasedOnView.scala.html
@@ -29,11 +29,11 @@
saveAndContinueButton: saveAndContinueButton
)
-@(form: Form[WhatIsYourRentBasedOnForm], ngrRadio: Radios, selectedPropertyAddress: String)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
+@(form: Form[WhatIsYourRentBasedOnForm], ngrRadio: Radios, selectedPropertyAddress: String, mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
@layout(pageTitle = Some(messages("whatIsYourRentBasedOn.title")), showBackLink = true, fullWidth = false) {
- @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.WhatIsYourRentBasedOnController.submit, Symbol("autoComplete") -> "off") {
+ @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.WhatIsYourRentBasedOnController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/WhatTypeOfAgreementView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/WhatTypeOfAgreementView.scala.html
index 231f912f..25797662 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/views/WhatTypeOfAgreementView.scala.html
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/WhatTypeOfAgreementView.scala.html
@@ -28,11 +28,11 @@
formHelper: FormWithCSRF
)
-@(selectedPropertyAddress: String, form: Form[WhatTypeOfAgreementForm], ngrRadio: Radios)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
+@(selectedPropertyAddress: String, form: Form[WhatTypeOfAgreementForm], ngrRadio: Radios, mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
@layout(pageTitle = Some(messages("tellUsAboutYourNewAgreement.title")), showBackLink = true, fullWidth = true) {
- @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.WhatTypeOfAgreementController.submit, Symbol("autoComplete") -> "off") {
+ @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.WhatTypeOfAgreementController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/WhatTypeOfLeaseRenewalView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/WhatTypeOfLeaseRenewalView.scala.html
index f595d009..73bc4e82 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/views/WhatTypeOfLeaseRenewalView.scala.html
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/WhatTypeOfLeaseRenewalView.scala.html
@@ -29,10 +29,10 @@
saveAndContinueButton: saveAndContinueButton
)
-@(form:Form[WhatTypeOfLeaseRenewalForm], radios: Radios, propertyAddress: String)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
+@(form:Form[WhatTypeOfLeaseRenewalForm], radios: Radios, propertyAddress: String, mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
@layout(pageTitle = Some(messages("typeOfLeaseRenewal.title")), showBackLink = true, fullWidth = true) {
- @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.WhatTypeOfLeaseRenewalController.submit, Symbol("autoComplete") -> "off") {
+ @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.WhatTypeOfLeaseRenewalController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/WhatYourRentIncludesView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/WhatYourRentIncludesView.scala.html
index e1717097..99bbb5f4 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/views/WhatYourRentIncludesView.scala.html
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/WhatYourRentIncludesView.scala.html
@@ -30,10 +30,10 @@
saveAndContinueButton: saveAndContinueButton
)
-@(form:Form[WhatYourRentIncludesForm], radios1: Radios, radios2: Radios, radios3: Radios, radios4: Radios, radios5: Radios, radios6: Radios, propertyAddress: String)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
+@(form:Form[WhatYourRentIncludesForm], radios1: Radios, radios2: Radios, radios3: Radios, radios4: Radios, radios5: Radios, radios6: Radios, propertyAddress: String, mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
@layout(pageTitle = Some(messages("whatYourRentIncludes.title")), showBackLink = true, fullWidth = true) {
- @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.WhatYourRentIncludesController.submit, Symbol("autoComplete") -> "off") {
+ @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.WhatYourRentIncludesController.submit(mode), Symbol("autoComplete") -> "off") {
@if(form.errors.nonEmpty) {
@govukErrorSummary(ErrorSummaryViewModel(form))
}
diff --git a/build.sbt b/build.sbt
index 996456e5..0a46c539 100644
--- a/build.sbt
+++ b/build.sbt
@@ -1,5 +1,8 @@
+import play.sbt.routes.RoutesKeys
import uk.gov.hmrc.DefaultBuildSettings
+import scala.collection.immutable.Seq
+
ThisBuild / majorVersion := 0
ThisBuild / scalaVersion := "3.3.5"
@@ -15,6 +18,15 @@ lazy val microservice = Project("ngr-rald-frontend", file("."))
Compile / scalacOptions -= "utf8",
PlayKeys.playDefaultPort := 1505,
)
+ .settings(
+ RoutesKeys.routesImport ++= Seq(
+ "uk.gov.hmrc.ngrraldfrontend.models._",
+ "uk.gov.hmrc.play.bootstrap.binders.RedirectUrl"
+ ),
+ TwirlKeys.templateImports ++= Seq(
+ "uk.gov.hmrc.ngrraldfrontend.models.Mode"
+ ),
+ )
.settings(CodeCoverageSettings.settings: _*)
.disablePlugins(JUnitXmlReportPlugin)
diff --git a/conf/app.routes b/conf/app.routes
index cb0243cd..0463d15d 100644
--- a/conf/app.routes
+++ b/conf/app.routes
@@ -1,50 +1,132 @@
# microservice specific routes
+-> /hmrc-frontend hmrcfrontend.Routes
+GET /assets/*file controllers.Assets.versioned(path = "/public", file: Asset)
--> /hmrc-frontend hmrcfrontend.Routes
-GET /assets/*file controllers.Assets.versioned(path = "/public", file: Asset)
-GET /tell-us-about-your-new-agreement uk.gov.hmrc.ngrraldfrontend.controllers.TellUsAboutYourNewAgreementController.show
-POST /tell-us-about-your-new-agreement uk.gov.hmrc.ngrraldfrontend.controllers.TellUsAboutYourNewAgreementController.submit
-GET /tell-us-about-your-renewed-agreement uk.gov.hmrc.ngrraldfrontend.controllers.TellUsAboutYourRenewedAgreementController.show
-POST /tell-us-about-your-renewed-agreement uk.gov.hmrc.ngrraldfrontend.controllers.TellUsAboutYourRenewedAgreementController.submit
-GET /tell-us-about-rent-review uk.gov.hmrc.ngrraldfrontend.controllers.TellUsAboutRentController.show
-POST /tell-us-about-rent-review uk.gov.hmrc.ngrraldfrontend.controllers.TellUsAboutRentController.submit
-GET /what-type-of-lease-renewal-is-it uk.gov.hmrc.ngrraldfrontend.controllers.WhatTypeOfLeaseRenewalController.show
-POST /what-type-of-lease-renewal-is-it uk.gov.hmrc.ngrraldfrontend.controllers.WhatTypeOfLeaseRenewalController.submit
-GET /what-type-of-agreement-do-you-have uk.gov.hmrc.ngrraldfrontend.controllers.WhatTypeOfAgreementController.show
-POST /what-type-of-agreement-do-you-have uk.gov.hmrc.ngrraldfrontend.controllers.WhatTypeOfAgreementController.submit
-GET /landlord uk.gov.hmrc.ngrraldfrontend.controllers.LandlordController.show
-POST /landlord uk.gov.hmrc.ngrraldfrontend.controllers.LandlordController.submit
-GET /what-is-your-rent-based-on uk.gov.hmrc.ngrraldfrontend.controllers.WhatIsYourRentBasedOnController.show
-POST /what-is-your-rent-based-on uk.gov.hmrc.ngrraldfrontend.controllers.WhatIsYourRentBasedOnController.submit
-GET /how-much-is-total-annual-rent uk.gov.hmrc.ngrraldfrontend.controllers.HowMuchIsTotalAnnualRentController.show
-POST /how-much-is-total-annual-rent uk.gov.hmrc.ngrraldfrontend.controllers.HowMuchIsTotalAnnualRentController.submit
-GET /have-you-agreed-rent-changes-with-landlord uk.gov.hmrc.ngrraldfrontend.controllers.AgreedRentChangeController.show
-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
-GET /did-you-agree-rent-with-landlord uk.gov.hmrc.ngrraldfrontend.controllers.DidYouAgreeRentWithLandlordController.show
-POST /did-you-agree-rent-with-landlord uk.gov.hmrc.ngrraldfrontend.controllers.DidYouAgreeRentWithLandlordController.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
-GET /rent-periods uk.gov.hmrc.ngrraldfrontend.controllers.RentPeriodsController.show
-POST /rent-periods uk.gov.hmrc.ngrraldfrontend.controllers.RentPeriodsController.submit
-GET /did-the-court-set-an-interim-rent uk.gov.hmrc.ngrraldfrontend.controllers.RentInterimController.show
-POST /did-the-court-set-an-interim-rent uk.gov.hmrc.ngrraldfrontend.controllers.RentInterimController.submit
-GET /rent-dates-agree uk.gov.hmrc.ngrraldfrontend.controllers.RentDatesAgreeController.show
-POST /rent-dates-agree uk.gov.hmrc.ngrraldfrontend.controllers.RentDatesAgreeController.submit
-GET /rent-dates-agree-start uk.gov.hmrc.ngrraldfrontend.controllers.RentDatesAgreeStartController.show
-POST /rent-dates-agree-start uk.gov.hmrc.ngrraldfrontend.controllers.RentDatesAgreeStartController.submit
-GET /what-rent-includes uk.gov.hmrc.ngrraldfrontend.controllers.WhatYourRentIncludesController.show
-POST /what-rent-includes uk.gov.hmrc.ngrraldfrontend.controllers.WhatYourRentIncludesController.submit
-GET /does-rent-include-parking-spaces-or-garages uk.gov.hmrc.ngrraldfrontend.controllers.DoesYourRentIncludeParkingController.show
-POST /does-rent-include-parking-spaces-or-garages uk.gov.hmrc.ngrraldfrontend.controllers.DoesYourRentIncludeParkingController.submit
-GET /how-many-parking-spaces-or-garages-included-in-rent uk.gov.hmrc.ngrraldfrontend.controllers.HowManyParkingSpacesOrGaragesIncludedInRentController.show
-POST /how-many-parking-spaces-or-garages-included-in-rent uk.gov.hmrc.ngrraldfrontend.controllers.HowManyParkingSpacesOrGaragesIncludedInRentController.submit
-GET /interim-rent-set-by-court uk.gov.hmrc.ngrraldfrontend.controllers.InterimRentSetByTheCourtController.show
-POST /interim-rent-set-by-court uk.gov.hmrc.ngrraldfrontend.controllers.InterimRentSetByTheCourtController.submit
-GET /rent-free-period uk.gov.hmrc.ngrraldfrontend.controllers.RentFreePeriodController.show
-POST /rent-free-period uk.gov.hmrc.ngrraldfrontend.controllers.RentFreePeriodController.submit
\ No newline at end of file
+#Interstitial Pages
+GET /tell-us-about-your-new-agreement uk.gov.hmrc.ngrraldfrontend.controllers.TellUsAboutYourNewAgreementController.show
+POST /tell-us-about-your-new-agreement uk.gov.hmrc.ngrraldfrontend.controllers.TellUsAboutYourNewAgreementController.submit
+GET /tell-us-about-your-renewed-agreement uk.gov.hmrc.ngrraldfrontend.controllers.TellUsAboutYourRenewedAgreementController.show
+POST /tell-us-about-your-renewed-agreement uk.gov.hmrc.ngrraldfrontend.controllers.TellUsAboutYourRenewedAgreementController.submit
+GET /tell-us-about-rent-review uk.gov.hmrc.ngrraldfrontend.controllers.TellUsAboutRentController.show
+POST /tell-us-about-rent-review uk.gov.hmrc.ngrraldfrontend.controllers.TellUsAboutRentController.submit
+
+#What type of lease renewal is it
+GET /what-type-of-lease-renewal-is-it uk.gov.hmrc.ngrraldfrontend.controllers.WhatTypeOfLeaseRenewalController.show(mode: Mode = NormalMode)
+POST /what-type-of-lease-renewal-is-it uk.gov.hmrc.ngrraldfrontend.controllers.WhatTypeOfLeaseRenewalController.submit(mode: Mode = NormalMode)
+GET /what-type-of-lease-renewal-is-it/change uk.gov.hmrc.ngrraldfrontend.controllers.WhatTypeOfLeaseRenewalController.show(mode: Mode = CheckMode)
+POST /what-type-of-lease-renewal-is-it/change uk.gov.hmrc.ngrraldfrontend.controllers.WhatTypeOfLeaseRenewalController.submit(mode: Mode = CheckMode)
+
+#What type of agreement do you have
+GET /what-type-of-agreement-do-you-have uk.gov.hmrc.ngrraldfrontend.controllers.WhatTypeOfAgreementController.show(mode: Mode = NormalMode)
+POST /what-type-of-agreement-do-you-have uk.gov.hmrc.ngrraldfrontend.controllers.WhatTypeOfAgreementController.submit(mode: Mode = NormalMode)
+GET /what-type-of-agreement-do-you-have/change uk.gov.hmrc.ngrraldfrontend.controllers.WhatTypeOfAgreementController.show(mode: Mode = CheckMode)
+POST /what-type-of-agreement-do-you-have/change uk.gov.hmrc.ngrraldfrontend.controllers.WhatTypeOfAgreementController.submit(mode: Mode = CheckMode)
+
+#Landlord
+GET /landlord uk.gov.hmrc.ngrraldfrontend.controllers.LandlordController.show(mode: Mode = NormalMode)
+POST /landlord uk.gov.hmrc.ngrraldfrontend.controllers.LandlordController.submit(mode: Mode = NormalMode)
+GET /landlord/change uk.gov.hmrc.ngrraldfrontend.controllers.LandlordController.show(mode: Mode = CheckMode)
+POST /landlord/change uk.gov.hmrc.ngrraldfrontend.controllers.LandlordController.submit(mode: Mode = CheckMode)
+
+#What is your rent based on
+GET /what-is-your-rent-based-on uk.gov.hmrc.ngrraldfrontend.controllers.WhatIsYourRentBasedOnController.show(mode: Mode = NormalMode)
+POST /what-is-your-rent-based-on uk.gov.hmrc.ngrraldfrontend.controllers.WhatIsYourRentBasedOnController.submit(mode: Mode = NormalMode)
+GET /what-is-your-rent-based-on/change uk.gov.hmrc.ngrraldfrontend.controllers.WhatIsYourRentBasedOnController.show(mode: Mode = CheckMode)
+POST /what-is-your-rent-based-on/change uk.gov.hmrc.ngrraldfrontend.controllers.WhatIsYourRentBasedOnController.submit(mode: Mode = CheckMode)
+
+#How much is total annual rent
+GET /how-much-is-total-annual-rent uk.gov.hmrc.ngrraldfrontend.controllers.HowMuchIsTotalAnnualRentController.show(mode: Mode = NormalMode)
+POST /how-much-is-total-annual-rent uk.gov.hmrc.ngrraldfrontend.controllers.HowMuchIsTotalAnnualRentController.submit(mode: Mode = NormalMode)
+GET /how-much-is-total-annual-rent/change uk.gov.hmrc.ngrraldfrontend.controllers.HowMuchIsTotalAnnualRentController.show(mode: Mode = CheckMode)
+POST /how-much-is-total-annual-rent/change uk.gov.hmrc.ngrraldfrontend.controllers.HowMuchIsTotalAnnualRentController.submit(mode: Mode = CheckMode)
+
+#Have you agreed rent changes with the landlord
+GET /have-you-agreed-rent-changes-with-landlord uk.gov.hmrc.ngrraldfrontend.controllers.AgreedRentChangeController.show(mode: Mode = NormalMode)
+POST /have-you-agreed-rent-changes-with-landlord uk.gov.hmrc.ngrraldfrontend.controllers.AgreedRentChangeController.submit(mode: Mode = NormalMode)
+GET /have-you-agreed-rent-changes-with-landlord/change uk.gov.hmrc.ngrraldfrontend.controllers.AgreedRentChangeController.show(mode: Mode = CheckMode)
+POST /have-you-agreed-rent-changes-with-landlord/change uk.gov.hmrc.ngrraldfrontend.controllers.AgreedRentChangeController.submit(mode: Mode = CheckMode)
+
+#Agreement verbal
+GET /agreement-verbal uk.gov.hmrc.ngrraldfrontend.controllers.AgreementVerbalController.show(mode: Mode = NormalMode)
+POST /agreement-verbal uk.gov.hmrc.ngrraldfrontend.controllers.AgreementVerbalController.submit(mode: Mode = NormalMode)
+GET /agreement-verbal/change uk.gov.hmrc.ngrraldfrontend.controllers.AgreementVerbalController.show(mode: Mode = CheckMode)
+POST /agreement-verbal/change uk.gov.hmrc.ngrraldfrontend.controllers.AgreementVerbalController.submit(mode: Mode = CheckMode)
+
+#Do you have a rent free period
+GET /do-you-have-a-rent-free-period uk.gov.hmrc.ngrraldfrontend.controllers.CheckRentFreePeriodController.show(mode: Mode = NormalMode)
+POST /do-you-have-a-rent-free-period uk.gov.hmrc.ngrraldfrontend.controllers.CheckRentFreePeriodController.submit(mode: Mode = NormalMode)
+GET /do-you-have-a-rent-free-period/change uk.gov.hmrc.ngrraldfrontend.controllers.CheckRentFreePeriodController.show(mode: Mode = CheckMode)
+POST /do-you-have-a-rent-free-period/change uk.gov.hmrc.ngrraldfrontend.controllers.CheckRentFreePeriodController.submit(mode: Mode = CheckMode)
+
+#Agreement
+GET /agreement uk.gov.hmrc.ngrraldfrontend.controllers.AgreementController.show(mode: Mode = NormalMode)
+POST /agreement uk.gov.hmrc.ngrraldfrontend.controllers.AgreementController.submit(mode: Mode = NormalMode)
+GET /agreement/change uk.gov.hmrc.ngrraldfrontend.controllers.AgreementController.show(mode: Mode = CheckMode)
+POST /agreement/change uk.gov.hmrc.ngrraldfrontend.controllers.AgreementController.submit(mode: Mode = CheckMode)
+
+#Did you agree rent with landlord
+GET /did-you-agree-rent-with-landlord uk.gov.hmrc.ngrraldfrontend.controllers.DidYouAgreeRentWithLandlordController.show(mode: Mode = NormalMode)
+POST /did-you-agree-rent-with-landlord uk.gov.hmrc.ngrraldfrontend.controllers.DidYouAgreeRentWithLandlordController.submit(mode: Mode = NormalMode)
+GET /did-you-agree-rent-with-landlord/change uk.gov.hmrc.ngrraldfrontend.controllers.DidYouAgreeRentWithLandlordController.show(mode: Mode = CheckMode)
+POST /did-you-agree-rent-with-landlord/change uk.gov.hmrc.ngrraldfrontend.controllers.DidYouAgreeRentWithLandlordController.submit(mode: Mode = CheckMode)
+
+#Provide details of first second rent period
+GET /provide-details-of-first-second-rent-period uk.gov.hmrc.ngrraldfrontend.controllers.ProvideDetailsOfFirstSecondRentPeriodController.show(mode: Mode = NormalMode)
+POST /provide-details-of-first-second-rent-period uk.gov.hmrc.ngrraldfrontend.controllers.ProvideDetailsOfFirstSecondRentPeriodController.submit(mode: Mode = NormalMode)
+GET /provide-details-of-first-second-rent-period/change uk.gov.hmrc.ngrraldfrontend.controllers.ProvideDetailsOfFirstSecondRentPeriodController.show(mode: Mode = CheckMode)
+POST /provide-details-of-first-second-rent-period/change uk.gov.hmrc.ngrraldfrontend.controllers.ProvideDetailsOfFirstSecondRentPeriodController.submit(mode: Mode = CheckMode)
+
+#Rent Periods
+GET /rent-periods uk.gov.hmrc.ngrraldfrontend.controllers.RentPeriodsController.show(mode: Mode = NormalMode)
+POST /rent-periods uk.gov.hmrc.ngrraldfrontend.controllers.RentPeriodsController.submit(mode: Mode = NormalMode)
+GET /rent-periods/change uk.gov.hmrc.ngrraldfrontend.controllers.RentPeriodsController.show(mode: Mode = CheckMode)
+POST /rent-periods/change uk.gov.hmrc.ngrraldfrontend.controllers.RentPeriodsController.submit(mode: Mode = CheckMode)
+
+#Did the court sent an interim rent
+GET /did-the-court-set-an-interim-rent uk.gov.hmrc.ngrraldfrontend.controllers.RentInterimController.show(mode: Mode = NormalMode)
+POST /did-the-court-set-an-interim-rent uk.gov.hmrc.ngrraldfrontend.controllers.RentInterimController.submit(mode: Mode = NormalMode)
+GET /did-the-court-set-an-interim-rent/change uk.gov.hmrc.ngrraldfrontend.controllers.RentInterimController.show(mode: Mode = CheckMode)
+POST /did-the-court-set-an-interim-rent/change uk.gov.hmrc.ngrraldfrontend.controllers.RentInterimController.submit(mode: Mode = CheckMode)
+
+#Rent dates agree
+GET /rent-dates-agree uk.gov.hmrc.ngrraldfrontend.controllers.RentDatesAgreeController.show(mode: Mode = NormalMode)
+POST /rent-dates-agree uk.gov.hmrc.ngrraldfrontend.controllers.RentDatesAgreeController.submit(mode: Mode = NormalMode)
+GET /rent-dates-agree/change uk.gov.hmrc.ngrraldfrontend.controllers.RentDatesAgreeController.show(mode: Mode = CheckMode)
+POST /rent-dates-agree/change uk.gov.hmrc.ngrraldfrontend.controllers.RentDatesAgreeController.submit(mode: Mode = CheckMode)
+
+#Rent dates agree start
+GET /rent-dates-agree-start uk.gov.hmrc.ngrraldfrontend.controllers.RentDatesAgreeStartController.show(mode: Mode = NormalMode)
+POST /rent-dates-agree-start uk.gov.hmrc.ngrraldfrontend.controllers.RentDatesAgreeStartController.submit(mode: Mode = NormalMode)
+GET /rent-dates-agree-start/change uk.gov.hmrc.ngrraldfrontend.controllers.RentDatesAgreeStartController.show(mode: Mode = CheckMode)
+POST /rent-dates-agree-start/change uk.gov.hmrc.ngrraldfrontend.controllers.RentDatesAgreeStartController.submit(mode: Mode = CheckMode)
+
+#What your rent includes
+GET /what-rent-includes uk.gov.hmrc.ngrraldfrontend.controllers.WhatYourRentIncludesController.show(mode: Mode = NormalMode)
+POST /what-rent-includes uk.gov.hmrc.ngrraldfrontend.controllers.WhatYourRentIncludesController.submit(mode: Mode = NormalMode)
+GET /what-rent-includes/change uk.gov.hmrc.ngrraldfrontend.controllers.WhatYourRentIncludesController.show(mode: Mode = CheckMode)
+POST /what-rent-includes/change uk.gov.hmrc.ngrraldfrontend.controllers.WhatYourRentIncludesController.submit(mode: Mode = CheckMode)
+
+#Does your rent include parking spaces or garages
+GET /does-rent-include-parking-spaces-or-garages uk.gov.hmrc.ngrraldfrontend.controllers.DoesYourRentIncludeParkingController.show(mode: Mode = NormalMode)
+POST /does-rent-include-parking-spaces-or-garages uk.gov.hmrc.ngrraldfrontend.controllers.DoesYourRentIncludeParkingController.submit(mode: Mode = NormalMode)
+GET /does-rent-include-parking-spaces-or-garages/change uk.gov.hmrc.ngrraldfrontend.controllers.DoesYourRentIncludeParkingController.show(mode: Mode = CheckMode)
+POST /does-rent-include-parking-spaces-or-garages/change uk.gov.hmrc.ngrraldfrontend.controllers.DoesYourRentIncludeParkingController.submit(mode: Mode = CheckMode)
+
+
+#How many parking spaces or garages included in rent
+GET /how-many-parking-spaces-or-garages-included-in-rent uk.gov.hmrc.ngrraldfrontend.controllers.HowManyParkingSpacesOrGaragesIncludedInRentController.show(mode: Mode = NormalMode)
+POST /how-many-parking-spaces-or-garages-included-in-rent uk.gov.hmrc.ngrraldfrontend.controllers.HowManyParkingSpacesOrGaragesIncludedInRentController.submit(mode: Mode = NormalMode)
+GET /how-many-parking-spaces-or-garages-included-in-rent/change uk.gov.hmrc.ngrraldfrontend.controllers.HowManyParkingSpacesOrGaragesIncludedInRentController.show(mode: Mode = CheckMode)
+POST /how-many-parking-spaces-or-garages-included-in-rent/change uk.gov.hmrc.ngrraldfrontend.controllers.HowManyParkingSpacesOrGaragesIncludedInRentController.submit(mode: Mode = CheckMode)
+
+#Interim rent set by the court
+GET /interim-rent-set-by-court uk.gov.hmrc.ngrraldfrontend.controllers.InterimRentSetByTheCourtController.show(mode: Mode = NormalMode)
+POST /interim-rent-set-by-court uk.gov.hmrc.ngrraldfrontend.controllers.InterimRentSetByTheCourtController.submit(mode: Mode = NormalMode)
+GET /interim-rent-set-by-court/change uk.gov.hmrc.ngrraldfrontend.controllers.InterimRentSetByTheCourtController.show(mode: Mode = CheckMode)
+POST /interim-rent-set-by-court/change uk.gov.hmrc.ngrraldfrontend.controllers.InterimRentSetByTheCourtController.submit(mode: Mode = CheckMode)
+
+#Rent Free Period
+GET /rent-free-period uk.gov.hmrc.ngrraldfrontend.controllers.RentFreePeriodController.show(mode: Mode = NormalMode)
+POST /rent-free-period uk.gov.hmrc.ngrraldfrontend.controllers.RentFreePeriodController.submit(mode: Mode = NormalMode)
+GET /rent-free-period/change uk.gov.hmrc.ngrraldfrontend.controllers.RentFreePeriodController.show(mode: Mode = CheckMode)
+POST /rent-free-period/change uk.gov.hmrc.ngrraldfrontend.controllers.RentFreePeriodController.submit(mode: Mode = CheckMode)
\ No newline at end of file
diff --git a/conf/application.conf b/conf/application.conf
index 78eb8716..bba72d9d 100644
--- a/conf/application.conf
+++ b/conf/application.conf
@@ -73,10 +73,10 @@ microservice {
}
}
-time-to-live.time = "3"
-
mongodb {
uri = "mongodb://localhost:27017/ngr-rald-frontend"
+ timeToLiveInSeconds = 900
+
}
play.i18n.langCookieHttpOnly: "true"
diff --git a/project/CodeCoverageSettings.scala b/project/CodeCoverageSettings.scala
index 035349cd..be74fbbc 100644
--- a/project/CodeCoverageSettings.scala
+++ b/project/CodeCoverageSettings.scala
@@ -11,7 +11,9 @@ object CodeCoverageSettings {
"prod.*",
".*Routes.*",
"testOnly.*",
- "testOnlyDoNotUseInAppConf.*"
+ "testOnlyDoNotUseInAppConf.*",
+ "uk.gov.hmrc.ngrraldfrontend.models.package"
+
)
val settings: Seq[Setting[_]] = Seq(
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/actions/DataRetrievalActionSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/actions/DataRetrievalActionSpec.scala
new file mode 100644
index 00000000..99e237c5
--- /dev/null
+++ b/test/uk/gov/hmrc/ngrraldfrontend/actions/DataRetrievalActionSpec.scala
@@ -0,0 +1,100 @@
+/*
+ * 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.actions
+
+import org.mockito.ArgumentMatchers.any
+import org.mockito.Mockito.when
+import play.api.test.FakeRequest
+import play.api.test.Helpers.await
+import uk.gov.hmrc.http.{HeaderCarrier, NotFoundException}
+import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.connectors.NGRConnector
+import uk.gov.hmrc.ngrraldfrontend.helpers.{ControllerSpecSupport, TestSupport}
+import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
+import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, PropertyLinkingUserAnswers, UserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.models.requests.{IdentifierRequest, OptionalDataRequest}
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
+import uk.gov.hmrc.ngrraldfrontend.models.vmvProperty.VMVProperty
+import play.api.test.Helpers.defaultAwaitTimeout
+import uk.gov.hmrc.ngrraldfrontend.mocks.MockHttpV2
+
+import scala.concurrent.{ExecutionContext, Future}
+
+class DataRetrievalActionSpec extends ControllerSpecSupport with MockHttpV2{
+
+ class StubNGRConnector(property: VMVProperty)(implicit ec: ExecutionContext) extends NGRConnector(mockHttpClientV2, mockConfig) {
+ override def getLinkedProperty(credId: CredId)(implicit hc: HeaderCarrier): Future[Option[VMVProperty]] =
+ Future.successful(Some(property))
+ }
+
+ class StubNGRConnectorReturnsNone(implicit ec: ExecutionContext) extends NGRConnector(mockHttpClientV2, mockConfig) {
+ override def getLinkedProperty(credId: CredId)(implicit hc: HeaderCarrier): Future[Option[VMVProperty]] =
+ Future.successful(None)
+ }
+
+ class Harness(sessionRepository: SessionRepository, ngrConnector: NGRConnector, appConfig: AppConfig)
+ extends DataRetrievalActionImpl(sessionRepository, ngrConnector, appConfig) {
+ def callTransform[A](request: AuthenticatedUserRequest[A]): Future[OptionalDataRequest[A]] = transform(request)
+ }
+
+ "Data Retrieval Action" when {
+
+ "there is no data in the cache" should {
+
+ "must set userAnswers to 'None' in the request" in {
+ when(mockSessionRepository.get(any())) thenReturn Future(None)
+
+ val stubConnector = new StubNGRConnector(property)
+ val action = new Harness(mockSessionRepository, stubConnector, mockConfig)
+ val result = action.callTransform(authenticatedFakeRequest).futureValue
+
+ result.userAnswers must not be defined
+ }
+
+ "when property is not found" should {
+
+ "throw NotFoundException" in {
+ when(mockSessionRepository.get(any())) thenReturn Future(Some(UserAnswers("id")))
+
+ val stubConnector = new StubNGRConnectorReturnsNone
+ val action = new Harness(mockSessionRepository, stubConnector, mockConfig)
+
+ val thrown = intercept[NotFoundException] {
+ await(action.callTransform(authenticatedFakeRequest))
+ }
+
+ thrown.getMessage mustBe "Property not found"
+ }
+ }
+
+
+ }
+
+ "when there is data in the cache" should {
+
+ "must build a userAnswers object and add it to the request" in {
+ when(mockSessionRepository.get(any())) thenReturn Future(Some(UserAnswers("id")))
+
+ val stubConnector = new StubNGRConnector(property)
+ val action = new Harness(mockSessionRepository, stubConnector, mockConfig)
+ val result = action.callTransform(authenticatedFakeRequest).futureValue
+
+ result.userAnswers mustBe defined
+ }
+ }
+ }
+}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/actions/FakeAuthenticatedRequest.scala b/test/uk/gov/hmrc/ngrraldfrontend/actions/FakeAuthenticatedRequest.scala
new file mode 100644
index 00000000..c6da9102
--- /dev/null
+++ b/test/uk/gov/hmrc/ngrraldfrontend/actions/FakeAuthenticatedRequest.scala
@@ -0,0 +1,43 @@
+/*
+ * 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.actions
+
+import play.api.mvc.{AnyContent, BodyParser, Request, Result}
+import uk.gov.hmrc.auth.core.{ConfidenceLevel, Nino}
+import uk.gov.hmrc.ngrraldfrontend.helpers.{TestData, TestSupport}
+import uk.gov.hmrc.ngrraldfrontend.models.AuthenticatedUserRequest
+
+import javax.inject.Inject
+import scala.concurrent.{ExecutionContext, Future}
+
+class FakeAuthenticatedRequest @Inject()(val parser: BodyParser[AnyContent])(implicit val executionContext: ExecutionContext)
+ extends AuthRetrievals with TestData {
+ override def invokeBlock[A](request: Request[A], block: AuthenticatedUserRequest[A] => Future[Result]): Future[Result] = {
+ val newRequest = AuthenticatedUserRequest(
+ request = request,
+ confidenceLevel = Some(ConfidenceLevel.L250),
+ authProvider = None,
+ email = Some("user@email.com"),
+ propertyLinking = Some(property),
+ credId = Some("1234"),
+ name = None,
+ affinityGroup = None,
+ nino = Nino(hasNino = true, Some("AA000003D"))
+ )
+ block(newRequest)
+ }
+}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/actions/FakeDataRetrievalAction.scala b/test/uk/gov/hmrc/ngrraldfrontend/actions/FakeDataRetrievalAction.scala
new file mode 100644
index 00000000..ae89c1cd
--- /dev/null
+++ b/test/uk/gov/hmrc/ngrraldfrontend/actions/FakeDataRetrievalAction.scala
@@ -0,0 +1,42 @@
+/*
+ * 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.actions
+
+import uk.gov.hmrc.http.NotFoundException
+import uk.gov.hmrc.ngrraldfrontend.helpers.TestData
+import uk.gov.hmrc.ngrraldfrontend.models.AuthenticatedUserRequest
+import uk.gov.hmrc.ngrraldfrontend.models.requests.{IdentifierRequest, OptionalDataRequest}
+import uk.gov.hmrc.ngrraldfrontend.models.UserAnswers
+import uk.gov.hmrc.ngrraldfrontend.models.vmvProperty.VMVProperty
+
+import scala.concurrent.{ExecutionContext, Future}
+
+class FakeDataRetrievalAction(answers: Option[UserAnswers], propertyOpt: Option[VMVProperty]) extends DataRetrievalAction with TestData {
+
+ override protected def executionContext: ExecutionContext =
+ scala.concurrent.ExecutionContext.Implicits.global
+
+ override protected def transform[A](request: AuthenticatedUserRequest[A]): Future[OptionalDataRequest[A]] = {
+ propertyOpt match {
+ case Some(value) => Future.successful(
+ OptionalDataRequest(request.request, request.credId.getOrElse(""), answers, property)
+ )
+ case None => throw new NotFoundException("Could not find answers in backend mongo")
+ }
+
+ }
+}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/actions/PropertyLinkingActionSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/actions/PropertyLinkingActionSpec.scala
deleted file mode 100644
index 66dc0b9f..00000000
--- a/test/uk/gov/hmrc/ngrraldfrontend/actions/PropertyLinkingActionSpec.scala
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * 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.actions
-
-import org.mockito.ArgumentMatchers.any
-import org.mockito.Mockito.{spy, when}
-import play.api.Application
-import play.api.http.Status.{OK, SEE_OTHER}
-import play.api.inject.guice.GuiceApplicationBuilder
-import play.api.mvc.Results.Ok
-import play.api.mvc.{AnyContent, Request, Result}
-import play.api.test.FakeRequest
-import play.api.test.Helpers.{defaultAwaitTimeout, status}
-import uk.gov.hmrc.auth.core.AuthConnector
-import uk.gov.hmrc.auth.core.retrieve.~
-import uk.gov.hmrc.ngrraldfrontend.helpers.{TestData, TestSupport}
-import uk.gov.hmrc.ngrraldfrontend.models.AgreementType.NewAgreement
-import uk.gov.hmrc.ngrraldfrontend.models.{PropertyLinkingUserAnswers, RaldUserAnswers}
-
-import scala.concurrent.Future
-
-class PropertyLinkingActionSpec extends TestSupport with TestData {
- val linkedProperty = PropertyLinkingUserAnswers(credId, property)
-
- override implicit lazy val app: Application = GuiceApplicationBuilder().build()
-
- private val mockAuthConnector: AuthConnector = mock[AuthConnector]
- val mockAuthAction = new AuthRetrievalsImpl(mockAuthConnector, mcc)
-
- private class Stubs {
- def successBlock(request: Request[AnyContent]): Future[Result] = Future.successful(Ok(""))
- }
-
- private val testRequest = FakeRequest("GET", "/paye/company-car")
-
- val propertyLinkingAction = new PropertyLinkingActionImpl(
- ngrConnector = mockNGRConnector,
- authenticate = mockAuthAction,
- raldRepo = mockRaldRepo,
- appConfig = mockConfig,
- mcc)
-
- private implicit class HelperOps[A](a: A) {
- def ~[B](b: B) = new~(a, b)
- }
-
- val retrievalResult: Future[mockAuthAction.RetrievalsType] =
- Future.successful(
- Some(testCredId) ~
- Some(testNino) ~
- testConfidenceLevel ~
- Some(testEmail) ~
- Some(testAffinityGroup) ~
- Some(testName)
- )
-
- "Property Linking Action" when {
- "a user navigating to /ngr-dashboard-frontend/select-your-property" must {
- "must be navigated to dashboard page if cannot find linked property but it's registered" in {
- when(
- mockAuthConnector
- .authorise[mockAuthAction.RetrievalsType](any(), any())(any(), any())
- )
- .thenReturn(retrievalResult)
-
- when(mockRaldRepo.findByCredId(any())).thenReturn(Future.successful(None))
- when(mockNGRConnector.getLinkedProperty(any())(any())).thenReturn(Future.successful(None))
-
- val stubs = spy(new Stubs)
-
- val authResult = mockAuthAction.invokeBlock(testRequest, stubs.successBlock)
- status(authResult) mustBe OK
-
- val result = propertyLinkingAction.invokeBlock(testRequest, stubs.successBlock)
- status(result) mustBe SEE_OTHER
- }
-
- "must return OK if found linked property in the backend and not the frontend and it's registered" in {
- when(
- mockAuthConnector
- .authorise[mockAuthAction.RetrievalsType](any(), any())(any(), any())
- )
- .thenReturn(retrievalResult)
-
- when(mockRaldRepo.findByCredId(any())).thenReturn(Future.successful(None))
- when(mockNGRConnector.getLinkedProperty(any())(any())).thenReturn(Future.successful(Some(property)))
-
- val stubs = spy(new Stubs)
-
- val authResult = mockAuthAction.invokeBlock(testRequest, stubs.successBlock)
- status(authResult) mustBe OK
-
- val result = propertyLinkingAction.invokeBlock(testRequest, stubs.successBlock)
- status(result) mustBe OK
- }
-
- "must return OK if found linked property and it's registered" in {
- when(
- mockAuthConnector
- .authorise[mockAuthAction.RetrievalsType](any(), any())(any(), any())
- )
- .thenReturn(retrievalResult)
-
- when(mockRaldRepo.findByCredId(any())).thenReturn(Future.successful(Some(RaldUserAnswers(credId, NewAgreement, property))))
-
- val stubs = spy(new Stubs)
-
- val authResult = mockAuthAction.invokeBlock(testRequest, stubs.successBlock)
- status(authResult) mustBe OK
-
- val result = propertyLinkingAction.invokeBlock(testRequest, stubs.successBlock)
- status(result) mustBe OK
- }
- }
- }
-}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/connectors/NGRConnectorSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/connectors/NGRConnectorSpec.scala
index c3ab899d..2bb37cb9 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/connectors/NGRConnectorSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/connectors/NGRConnectorSpec.scala
@@ -53,16 +53,13 @@ class NGRConnectorSpec extends MockHttpV2 with TestData {
"Successfully return a Property" in {
val propertyLinkingUserAnswers = PropertyLinkingUserAnswers(CredId("1234"), property)
setupMockHttpV2Get(s"${mockConfig.nextGenerationRatesHost}/next-generation-rates/get-property-linking-user-answers")(Some(propertyLinkingUserAnswers))
- when(mockRaldRepo.upsertRaldUserAnswers(any())).thenReturn(Future.successful(true))
val result: Future[Option[VMVProperty]] = ngrConnector.getLinkedProperty(credId)
result.futureValue mustBe Some(property)
}
"Property not found" in {
setupMockHttpV2Get(s"${mockConfig.nextGenerationRatesHost}/next-generation-rates/get-property-linking-user-answers")(None)
- val exception = intercept[NotFoundException] {
- await(ngrConnector.getLinkedProperty(credId))
- }
- exception.getMessage contains "failed to find propertyLinkingUserAnswers from backend mongo" mustBe true
+ val result = ngrConnector.getLinkedProperty(credId)
+ result.futureValue mustBe None
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/AgreedRentChangeControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/AgreedRentChangeControllerSpec.scala
index 958024cb..15ff0128 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/AgreedRentChangeControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/AgreedRentChangeControllerSpec.scala
@@ -16,72 +16,98 @@
package uk.gov.hmrc.ngrraldfrontend.controllers
+import org.jsoup.Jsoup
+import org.mockito.ArgumentMatchers.any
+import org.mockito.Mockito.when
import play.api.test.FakeRequest
import play.api.http.Status.{BAD_REQUEST, OK, SEE_OTHER}
import play.api.test.Helpers.{await, contentAsString, defaultAwaitTimeout, redirectLocation, status}
import uk.gov.hmrc.http.{HeaderNames, NotFoundException}
import uk.gov.hmrc.ngrraldfrontend.helpers.ControllerSpecSupport
+import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
+import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, NormalMode, UserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.models.forms.{AgreedRentChangeForm, WhatTypeOfLeaseRenewalForm}
+import uk.gov.hmrc.ngrraldfrontend.pages.AgreedRentChangePage
+import uk.gov.hmrc.ngrraldfrontend.views.html.{AgreedRentChangeView, WhatTypeOfLeaseRenewalView}
import uk.gov.hmrc.ngrraldfrontend.models.forms.AgreedRentChangeForm
import uk.gov.hmrc.ngrraldfrontend.views.html.AgreedRentChangeView
+import play.api.mvc.{AnyContentAsEmpty, AnyContentAsFormUrlEncoded}
+import uk.gov.hmrc.auth.core.{ConfidenceLevel, Nino}
+import uk.gov.hmrc.auth.core.ConfidenceLevel.L200
+import uk.gov.hmrc.ngrraldfrontend.models.vmvProperty.VMVProperty
+
+import scala.concurrent.Future
class AgreedRentChangeControllerSpec extends ControllerSpecSupport {
val pageTitle = "Have you agreed in advance with the landlord when and by how much rent goes up?"
val view: AgreedRentChangeView = inject[AgreedRentChangeView]
- val controller: AgreedRentChangeController = new AgreedRentChangeController(view, mockAuthJourney, mockPropertyLinkingAction, mockRaldRepo, mcc)(mockConfig)
+ val controllerNoProperty = new AgreedRentChangeController(view, fakeAuth, fakeData(None), mockSessionRepository, mockNavigator, mcc)(mockConfig)
+ val controllerProperty: Option[UserAnswers] => AgreedRentChangeController = answers => new AgreedRentChangeController(view, fakeAuth, fakeDataProperty(Some(property), answers), mockSessionRepository, mockNavigator, mcc)(mockConfig)
+ val agreedRentChangeAnswers: Option[UserAnswers] = UserAnswers("id").set(AgreedRentChangePage, "Yes").toOption
- "TypeOfLeaseRenewalController" must {
- "method show" must {
+ "AgreedRentChangeController" must {
+ "method show" should {
"Return OK and the correct view" in {
- val result = controller.show()(authenticatedFakeRequest())
+ val result = controllerProperty(None).show(NormalMode)(authenticatedFakeRequest)
status(result) mustBe OK
val content = contentAsString(result)
content must include(pageTitle)
}
+ "return OK and the correct view with prefilled answers" in {
+ val result = controllerProperty(agreedRentChangeAnswers).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[type=radio][name=agreed-rent-change-radio][value=Yes]").hasAttr("checked") mustBe true
+ document.select("input[type=radio][name=agreed-rent-change-radio][value=No]").hasAttr("checked") mustBe false
+ }
"Return NotFoundException when property is not found in the mongo" in {
- mockRequestWithoutProperty()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(NormalMode)(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
"method submit" must {
- "Return OK and the correct view after submitting Yes" in {
- val fakePostRequest = FakeRequest(routes.AgreedRentChangeController.submit)
+ "Return SEE and the correct view after submitting Yes" in {
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit(NormalMode))
.withFormUrlEncodedBody((AgreedRentChangeForm.agreedRentChangeRadio, "Yes"))
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
- val result = controller.submit()(authenticatedFakeRequest(fakePostRequest))
+ val result = controllerProperty(None).submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.ProvideDetailsOfFirstSecondRentPeriodController.show.url)
+ redirectLocation(result) mustBe Some(routes.ProvideDetailsOfFirstSecondRentPeriodController.show(NormalMode).url)
}
"Return OK and the correct view after submitting No" in {
- val fakePostRequest = FakeRequest(routes.AgreedRentChangeController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val fakePostRequest = FakeRequest(routes.AgreedRentChangeController.submit(NormalMode))
.withFormUrlEncodedBody((AgreedRentChangeForm.agreedRentChangeRadio, "No"))
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
- val result = controller.submit()(authenticatedFakeRequest(fakePostRequest))
+ val result = controllerProperty(None).submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.HowMuchIsTotalAnnualRentController.show.url)
+ redirectLocation(result) mustBe Some(routes.HowMuchIsTotalAnnualRentController.show(NormalMode).url)
}
"Return BAD_REQUEST for missing input and the correct view" in {
- mockRequest()
- val fakePostRequest = FakeRequest(routes.AgreedRentChangeController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit(NormalMode))
.withFormUrlEncodedBody((AgreedRentChangeForm.agreedRentChangeRadio, ""))
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
- val result = controller.submit()(authenticatedFakeRequest(fakePostRequest))
+ val result = controllerProperty(None).submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
status(result) mustBe BAD_REQUEST
}
"Return Exception if no address is in the mongo" in {
- mockRequestWithoutProperty()
- val fakePostRequest = FakeRequest(routes.AgreedRentChangeController.submit)
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
+ val fakePostRequest = FakeRequest(routes.AgreedRentChangeController.submit(NormalMode))
.withFormUrlEncodedBody((AgreedRentChangeForm.agreedRentChangeRadio, ""))
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
val exception = intercept[NotFoundException] {
- await(controller.submit()(authenticatedFakeRequest(fakePostRequest)))
+ await(controllerNoProperty.submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest)))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/AgreementControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/AgreementControllerSpec.scala
index 8b881aad..fb11f3d8 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/AgreementControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/AgreementControllerSpec.scala
@@ -25,10 +25,12 @@ 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.{AuthenticatedUserRequest, NormalMode, RaldUserAnswers, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
+import uk.gov.hmrc.ngrraldfrontend.pages.{AgreedRentChangePage, AgreementPage}
import uk.gov.hmrc.ngrraldfrontend.views.html.AgreementView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.{DateTextFields, NGRCharacterCountComponent}
+import org.jsoup.Jsoup
import scala.concurrent.Future
@@ -37,33 +39,60 @@ class AgreementControllerSpec extends ControllerSpecSupport {
val view: AgreementView = inject[AgreementView]
val mockNGRCharacterCountComponent: NGRCharacterCountComponent = inject[NGRCharacterCountComponent]
val mockDateTextFieldsComponent: DateTextFields = inject[DateTextFields]
- val controller: AgreementController = new AgreementController(view, mockAuthJourney,mockDateTextFieldsComponent, mockPropertyLinkingAction, mockRaldRepo, mockNGRCharacterCountComponent, mcc)(mockConfig, ec)
+ val controllerNoProperty: AgreementController = new AgreementController(view, fakeAuth, mockDateTextFieldsComponent, mockNGRCharacterCountComponent, mcc, fakeData(None),mockNavigator, mockSessionRepository)(mockConfig, ec)
+ val controllerProperty: Option[UserAnswers] => AgreementController = answers => new AgreementController(view, fakeAuth, mockDateTextFieldsComponent, mockNGRCharacterCountComponent, mcc, fakeDataProperty(Some(property),answers),mockNavigator, mockSessionRepository)(mockConfig, ec)
val over250Characters = "Bug Me Not PVT LTD, RODLEY LANE, RODLEY, LEEDS, BH1 1HU What is your rent based on?Open market value This is the rent a landlord could rent the property for if, it was available to anyoneA percentage of open market value This is a percentage of the rent a landlord could rent the property for if, it was available to anyoneTurnover top-up The rent is a fixed base rent with an additional payment based on a percentage of your turnoverA percentage of expected turnover The rent paid is based on a percentage of turnoverTotal Occupancy Cost leases (TOCs)The rent is the total cost of leasing the property. It includes base rent, business rates, insurance and utilities. It also includes common area maintenance and tenant improvements Indexation The rent is reviewed according to an index (such as Retail Price Index)Other The rent was agreed another way Can you tell us how your rent was agreed?"
+ val agreementAnswers: Option[UserAnswers] = UserAnswers("id").set(AgreementPage, agreementModel).toOption
+ val agreementAnswersMin: Option[UserAnswers] = UserAnswers("id").set(AgreementPage, agreementModelMin).toOption
"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())
+ val result = controllerProperty(None).show(NormalMode)(authenticatedFakeRequest)
status(result) mustBe OK
val content = contentAsString(result)
content must include(pageTitle)
}
+ "return OK and the correct view with prepopulated answers" in {
+ val result = controllerProperty(agreementAnswers).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[name=agreementStartDate.day]").attr("value") mustBe "1"
+ document.select("input[name=agreementStartDate.month]").attr("value") mustBe "1"
+ document.select("input[name=agreementStartDate.year]").attr("value") mustBe "2025"
+ document.select("input[type=radio][name=agreement-radio-openEnded][value=YesOpenEnded]").hasAttr("checked") mustBe true
+ document.select("input[name=agreementEndDate.day]").attr("value") mustBe "2"
+ document.select("input[name=agreementEndDate.month]").attr("value") mustBe "2"
+ document.select("input[name=agreementEndDate.year]").attr("value") mustBe "2025"
+ document.select("input[type=radio][name=agreement-breakClause-radio][value=YesBreakClause]").hasAttr("checked") mustBe true
+ document.select("textarea[name=about-break-clause]").text() mustBe "he has a break clause"
+ }
+ "return OK and the correct view with minimum prepopulated answers" in {
+ val result = controllerProperty(agreementAnswersMin).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[name=agreementStartDate.day]").attr("value") mustBe "1"
+ document.select("input[name=agreementStartDate.month]").attr("value") mustBe "1"
+ document.select("input[name=agreementStartDate.year]").attr("value") mustBe "2025"
+ document.select("input[type=radio][name=agreement-radio-openEnded][value=NoOpenEnded]").hasAttr("checked") mustBe true
+ document.select("input[type=radio][name=agreement-breakClause-radio][value=NoBreakClause]").hasAttr("checked") mustBe true
+ }
"Return NotFoundException when property is not found in the mongo" in {
- mockRequestWithoutProperty()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(NormalMode)(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
"method submit" must {
"Return OK and the correct view after submitting with start date, yes radio button selected for open ended " +
"and no radio button selected for break clause" 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.LandlordController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "12",
"agreementStartDate.month" -> "12",
@@ -76,15 +105,12 @@ class AgreementControllerSpec extends ControllerSpecSupport {
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)
+ redirectLocation(result) mustBe Some(routes.WhatIsYourRentBasedOnController.show(NormalMode).url)
}
"Return OK and the correct view after submitting with start date, no radio button selected for open ended" +
"with an end date added in the conditional field and no radio button selected for break clause" 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.LandlordController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "12",
"agreementStartDate.month" -> "12",
@@ -100,14 +126,12 @@ class AgreementControllerSpec extends ControllerSpecSupport {
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)
+ redirectLocation(result) mustBe Some(routes.WhatIsYourRentBasedOnController.show(NormalMode).url)
}
"Return OK and the correct view after submitting with start date, no radio button selected for open ended" +
"with an end date added in the conditional field and yes radio button selected for break clause with" +
"reason in the conditional text box" 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.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "12",
"agreementStartDate.month" -> "12",
@@ -124,11 +148,10 @@ class AgreementControllerSpec extends ControllerSpecSupport {
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)
+ redirectLocation(result) mustBe Some(routes.WhatIsYourRentBasedOnController.show(NormalMode).url)
}
"Return Form with Errors when no day is input for the start date" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "",
"agreementStartDate.month" -> "12",
@@ -145,8 +168,7 @@ class AgreementControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when no month is input for the start date" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "12",
"agreementStartDate.month" -> "",
@@ -163,8 +185,7 @@ class AgreementControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when no year is input for the start date" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "12",
"agreementStartDate.month" -> "12",
@@ -181,8 +202,7 @@ class AgreementControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when no day and month is input for the start date" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "",
"agreementStartDate.month" -> "",
@@ -199,8 +219,7 @@ class AgreementControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when no month and year is input for the start date" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "12",
"agreementStartDate.month" -> "",
@@ -217,8 +236,7 @@ class AgreementControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when no day and year is input for the start date" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "",
"agreementStartDate.month" -> "12",
@@ -235,8 +253,7 @@ class AgreementControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when no date is input for the start date" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "",
"agreementStartDate.month" -> "",
@@ -253,8 +270,7 @@ class AgreementControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when date is not numbers for the start date" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "one",
"agreementStartDate.month" -> "one",
@@ -271,8 +287,7 @@ class AgreementControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when no open ended radio is selected" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "12",
"agreementStartDate.month" -> "12",
@@ -289,8 +304,7 @@ class AgreementControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when open ended radio is selected and no date is input" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "12",
"agreementStartDate.month" -> "12",
@@ -311,8 +325,7 @@ class AgreementControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when open ended radio is selected and incorrect date format is input" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "12",
"agreementStartDate.month" -> "12",
@@ -333,8 +346,7 @@ class AgreementControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when open ended radio is selected and no day is input" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "12",
"agreementStartDate.month" -> "12",
@@ -355,8 +367,7 @@ class AgreementControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when open ended radio is selected and no month is input" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "12",
"agreementStartDate.month" -> "12",
@@ -377,8 +388,7 @@ class AgreementControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when open ended radio is selected and no year is input" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "12",
"agreementStartDate.month" -> "12",
@@ -399,8 +409,7 @@ class AgreementControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when open ended radio is selected and no month and year is input" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "12",
"agreementStartDate.month" -> "12",
@@ -421,8 +430,7 @@ class AgreementControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when open ended radio is selected and no day and year is input" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "12",
"agreementStartDate.month" -> "12",
@@ -443,8 +451,7 @@ class AgreementControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when open ended radio is selected and no day and month is input" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "12",
"agreementStartDate.month" -> "12",
@@ -465,8 +472,7 @@ class AgreementControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when break clause radio is not selected" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "12",
"agreementStartDate.month" -> "12",
@@ -486,8 +492,7 @@ class AgreementControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when break clause radio is selected as yes and no reason is input" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "12",
"agreementStartDate.month" -> "12",
@@ -508,8 +513,7 @@ class AgreementControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when break clause radio is selected as yes and reason input is too long" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "12",
"agreementStartDate.month" -> "12",
@@ -530,13 +534,12 @@ class AgreementControllerSpec extends ControllerSpecSupport {
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)
+ await(controllerNoProperty.submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementController.submit(NormalMode))
.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
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/AgreementVerbalControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/AgreementVerbalControllerSpec.scala
index cfb30cb3..1d893e7f 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/AgreementVerbalControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/AgreementVerbalControllerSpec.scala
@@ -16,6 +16,7 @@
package uk.gov.hmrc.ngrraldfrontend.controllers
+import org.jsoup.Jsoup
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.when
import play.api.http.Status.{BAD_REQUEST, OK, SEE_OTHER}
@@ -26,7 +27,8 @@ 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.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, RaldUserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, NormalMode, RaldUserAnswers, UserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.pages.AgreementVerbalPage
import uk.gov.hmrc.ngrraldfrontend.views.html.AgreementVerbalView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.DateTextFields
@@ -37,30 +39,55 @@ class AgreementVerbalControllerSpec extends ControllerSpecSupport {
val pageTitle = "Agreement"
val view: AgreementVerbalView = inject[AgreementVerbalView]
val mockDateTextFields: DateTextFields = inject[DateTextFields]
- val controller: AgreementVerbalController = new AgreementVerbalController(view, mockAuthJourney, mockPropertyLinkingAction, mockRaldRepo, mockDateTextFields, mcc)(mockConfig, ec)
+ val controllerNoProperty: AgreementVerbalController = new AgreementVerbalController(view, fakeAuth, mockDateTextFields, mcc, fakeData(None), mockSessionRepository, mockNavigator)(mockConfig, ec)
+ val controllerProperty: Option[UserAnswers] => AgreementVerbalController = answers => new AgreementVerbalController(view, fakeAuth, mockDateTextFields, mcc, fakeDataProperty(Some(property), answers), mockSessionRepository, mockNavigator)(mockConfig, ec)
+ val agreementVerbalMinAnswers: Option[UserAnswers] = UserAnswers("id").set(AgreementVerbalPage, agreementVerbalModelMin).toOption
+ val agreementVerbalAnswers: Option[UserAnswers] = UserAnswers("id").set(AgreementVerbalPage, agreementVerbalModel).toOption
"Agreement Verbal 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())
+ val result = controllerProperty(None).show(NormalMode)(authenticatedFakeRequest)
status(result) mustBe OK
val content = contentAsString(result)
content must include(pageTitle)
}
+ "return OK and the correct view with prepopulated answers but no end date" in {
+ val result = controllerProperty(agreementVerbalMinAnswers).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[name=agreementStartDate.day]").attr("value") mustBe "1"
+ document.select("input[name=agreementStartDate.month]").attr("value") mustBe "1"
+ document.select("input[name=agreementStartDate.year]").attr("value") mustBe "2025"
+ document.select("input[type=radio][name=agreement-verbal-radio][value=Yes]").hasAttr("checked") mustBe true
+ }
+ "return OK and the correct view with prepopulated answers with an end date" in {
+ val result = controllerProperty(agreementVerbalAnswers).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[name=agreementStartDate.day]").attr("value") mustBe "1"
+ document.select("input[name=agreementStartDate.month]").attr("value") mustBe "1"
+ document.select("input[name=agreementStartDate.year]").attr("value") mustBe "2025"
+ document.select("input[type=radio][name=agreement-verbal-radio][value=No]").hasAttr("checked") mustBe true
+ document.select("input[name=agreementEndDate.day]").attr("value") mustBe "2"
+ document.select("input[name=agreementEndDate.month]").attr("value") mustBe "2"
+ document.select("input[name=agreementEndDate.year]").attr("value") mustBe "2025"
+ }
"Return NotFoundException when property is not found in the mongo" in {
- mockRequestWithoutProperty()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(NormalMode)(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
"method submit" must {
"Return SEE_OTHER and redirect HowMuchIsTotalAnnualRent view when radio button selected yes" in {
- when(mockRaldRepo.findByCredId(any())) thenReturn (Future.successful(Some(RaldUserAnswers(credId = CredId(null), NewAgreement, selectedProperty = property))))
- val result = controller.submit(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "30",
"agreementStartDate.month" -> "4",
@@ -70,11 +97,11 @@ class AgreementVerbalControllerSpec extends ControllerSpecSupport {
.withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some(""))))
headers(result) mustBe TreeMap("Location" -> "/ngr-rald-frontend/how-much-is-total-annual-rent")
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.HowMuchIsTotalAnnualRentController.show.url)
+ redirectLocation(result) mustBe Some(routes.HowMuchIsTotalAnnualRentController.show(NormalMode).url)
}
"Return SEE_OTHER and redirect HowMuchIsTotalAnnualRent view when radio button selected no" in {
- when(mockRaldRepo.findByCredId(any())) thenReturn (Future.successful(Some(RaldUserAnswers(credId = CredId(null), NewAgreement, selectedProperty = property))))
- val result = controller.submit(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "30",
"agreementStartDate.month" -> "4",
@@ -87,11 +114,10 @@ class AgreementVerbalControllerSpec extends ControllerSpecSupport {
.withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some(""))))
headers(result) mustBe TreeMap("Location" -> "/ngr-rald-frontend/how-much-is-total-annual-rent")
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.HowMuchIsTotalAnnualRentController.show.url)
+ redirectLocation(result) mustBe Some(routes.HowMuchIsTotalAnnualRentController.show(NormalMode).url)
}
"Return Form with Errors when no radio button is selected" in {
- mockRequest()
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "30",
"agreementStartDate.month" -> "4",
@@ -106,7 +132,7 @@ class AgreementVerbalControllerSpec extends ControllerSpecSupport {
content must include("Select Yes if your agreement is open-ended")
}
"Return Form with Errors when radio button No is selected but no end date is given" in {
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "30",
"agreementStartDate.month" -> "4",
@@ -123,7 +149,7 @@ class AgreementVerbalControllerSpec extends ControllerSpecSupport {
content must include("Select yes if your agreement is open-ended")
}
"Return Form with Errors when radio button No is selected but end date is invalid" in {
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "30",
"agreementStartDate.month" -> "4",
@@ -140,7 +166,7 @@ class AgreementVerbalControllerSpec extends ControllerSpecSupport {
content must include("Date your agreement ends must be a real date")
}
"Return Form with Errors when start date is missing day" in {
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "",
"agreementStartDate.month" -> "4",
@@ -154,7 +180,7 @@ class AgreementVerbalControllerSpec extends ControllerSpecSupport {
content must include("Date your agreement started must include a day")
}
"Return Form with Errors when start date is missing month" in {
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "30",
"agreementStartDate.month" -> "",
@@ -168,7 +194,7 @@ class AgreementVerbalControllerSpec extends ControllerSpecSupport {
content must include("Date your agreement started must include a month")
}
"Return Form with Errors when start date is missing year" in {
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "30",
"agreementStartDate.month" -> "4",
@@ -182,7 +208,7 @@ class AgreementVerbalControllerSpec extends ControllerSpecSupport {
content must include("Date your agreement started must include a year")
}
"Return Form with Errors when end date is missing day" in {
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "30",
"agreementStartDate.month" -> "4",
@@ -199,7 +225,7 @@ class AgreementVerbalControllerSpec extends ControllerSpecSupport {
content must include("Date your agreement ends must include a day")
}
"Return Form with Errors when end date is missing month" in {
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "30",
"agreementStartDate.month" -> "4",
@@ -216,7 +242,7 @@ class AgreementVerbalControllerSpec extends ControllerSpecSupport {
content must include("Date your agreement ends must include a month")
}
"Return Form with Errors when end date is missing year" in {
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "30",
"agreementStartDate.month" -> "4",
@@ -233,9 +259,9 @@ class AgreementVerbalControllerSpec extends ControllerSpecSupport {
content must include("Date your agreement ends must include a year")
}
"Return Exception if no address is in the mongo" in {
- mockRequestWithoutProperty()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit)
+ await(controllerNoProperty.submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.AgreementVerbalController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreementStartDate.day" -> "30",
"agreementStartDate.month" -> "4",
@@ -244,7 +270,7 @@ class AgreementVerbalControllerSpec extends ControllerSpecSupport {
)
.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
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/CheckRentFreePeriodControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/CheckRentFreePeriodControllerSpec.scala
index cdadc950..df044890 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/CheckRentFreePeriodControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/CheckRentFreePeriodControllerSpec.scala
@@ -16,72 +16,91 @@
package uk.gov.hmrc.ngrraldfrontend.controllers
+import org.jsoup.Jsoup
import play.api.http.Status.{BAD_REQUEST, OK, SEE_OTHER}
import play.api.test.FakeRequest
import play.api.test.Helpers.{await, contentAsString, defaultAwaitTimeout, redirectLocation, status}
+import org.mockito.Mockito.when
+import org.mockito.ArgumentMatchers.any
import uk.gov.hmrc.http.{HeaderNames, NotFoundException}
import uk.gov.hmrc.ngrraldfrontend.helpers.ControllerSpecSupport
+import uk.gov.hmrc.ngrraldfrontend.models.{NormalMode, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.forms.CheckRentFreePeriodForm
+import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
+import uk.gov.hmrc.ngrraldfrontend.pages.CheckRentFreePeriodPage
import uk.gov.hmrc.ngrraldfrontend.views.html.CheckRentFreePeriodView
+import scala.concurrent.Future
+
class CheckRentFreePeriodControllerSpec extends ControllerSpecSupport{
val pageTitle = "Do you have a rent-free period at the start of your agreement?"
val view: CheckRentFreePeriodView = inject[CheckRentFreePeriodView]
- val controller: CheckRentFreePeriodController = new CheckRentFreePeriodController(view,mockAuthJourney, mockPropertyLinkingAction, mockRaldRepo, mcc)(mockConfig)
-
+ val controllerNoProperty : CheckRentFreePeriodController = new CheckRentFreePeriodController(view,fakeAuth, fakeData(None), mockNavigator, mockSessionRepository, mcc)(mockConfig)
+ val controllerProperty : Option[UserAnswers] => CheckRentFreePeriodController = answers => new CheckRentFreePeriodController(view,fakeAuth, fakeDataProperty(Some(property), answers), mockNavigator, mockSessionRepository, mcc)(mockConfig)
+ val checkRentFreePeriodAnswers: Option[UserAnswers] = UserAnswers("id").set(CheckRentFreePeriodPage, "Yes").toOption
+
"CheckRentFreePeriodController" when {
"calling show method" should {
"Return OK and the correct view" in {
- val result = controller.show()(authenticatedFakeRequest())
+ val result = controllerProperty(None).show(NormalMode)(authenticatedFakeRequest)
status(result) mustBe OK
val content = contentAsString(result)
content must include(pageTitle)
}
+ "return OK and the correct view with prepopulated data" in {
+ val result = controllerProperty(checkRentFreePeriodAnswers).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[type=radio][name=check-rent-period-radio][value=Yes]").hasAttr("checked") mustBe true
+ document.select("input[type=radio][name=check-rent-period-radio][value=No]").hasAttr("checked") mustBe false
+ }
"Return Not Found Exception where no property is found in mongo" in {
- mockRequestWithoutProperty()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(NormalMode)(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
"method submit" must {
- "Return OK and redirect to RentFreePeriod view when user selects yes" in {
- val fakePostRequest = FakeRequest(routes.CheckRentFreePeriodController.submit)
+ "Return OK and the correct view and the answer is Yes" in {
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val fakePostRequest = FakeRequest(routes.CheckRentFreePeriodController.submit(NormalMode))
.withFormUrlEncodedBody((CheckRentFreePeriodForm.checkRentPeriodRadio, "Yes"))
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
- val result = controller.submit()(authenticatedFakeRequest(fakePostRequest))
+ val result = controllerProperty(None).submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.RentFreePeriodController.show.url)
+ redirectLocation(result) mustBe Some(routes.RentFreePeriodController.show(NormalMode).url)
}
- "Return OK and redirect to RentDatesAgreeStart view when user selects no" in {
- val fakePostRequest = FakeRequest(routes.CheckRentFreePeriodController.submit)
+ "Return OK and the correct view and the answer is No" in {
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val fakePostRequest = FakeRequest(routes.CheckRentFreePeriodController.submit(NormalMode))
.withFormUrlEncodedBody((CheckRentFreePeriodForm.checkRentPeriodRadio, "No"))
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
- val result = controller.submit()(authenticatedFakeRequest(fakePostRequest))
+ val result = controllerProperty(None).submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.RentDatesAgreeStartController.show.url)
+ redirectLocation(result) mustBe Some(routes.RentDatesAgreeStartController.show(NormalMode).url)
}
"Return BAD_REQUEST for missing input and the correct view" in {
- mockRequest()
- val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit)
+ val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit(NormalMode))
.withFormUrlEncodedBody((CheckRentFreePeriodForm.checkRentPeriodRadio, ""))
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
- val result = controller.submit()(authenticatedFakeRequest(fakePostRequest))
+ val result = controllerProperty(None).submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
status(result) mustBe BAD_REQUEST
}
"Return Exception if no address is in the mongo" in {
- mockRequestWithoutProperty()
- val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit)
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
+ val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit(NormalMode))
.withFormUrlEncodedBody((CheckRentFreePeriodForm.checkRentPeriodRadio, ""))
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
val exception = intercept[NotFoundException] {
- await(controller.submit()(authenticatedFakeRequest(fakePostRequest)))
+ await(controllerNoProperty.submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest)))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouAgreeRentWithLandlordControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouAgreeRentWithLandlordControllerSpec.scala
index 818751c0..0c59d8b9 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouAgreeRentWithLandlordControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouAgreeRentWithLandlordControllerSpec.scala
@@ -16,6 +16,7 @@
package uk.gov.hmrc.ngrraldfrontend.controllers
+import org.jsoup.Jsoup
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.when
import org.scalatest.matchers.should.Matchers.shouldBe
@@ -26,8 +27,9 @@ 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.{AuthenticatedUserRequest, NormalMode, RaldUserAnswers, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
+import uk.gov.hmrc.ngrraldfrontend.pages.DidYouAgreeRentWithLandlordPage
import uk.gov.hmrc.ngrraldfrontend.views.html.DidYouAgreeRentWithLandlordView
import scala.concurrent.Future
@@ -35,54 +37,60 @@ import scala.concurrent.Future
class DidYouAgreeRentWithLandlordControllerSpec extends ControllerSpecSupport {
val pageTitle = "Did you agree the rent with your landlord or their agent?"
val view: DidYouAgreeRentWithLandlordView = inject[DidYouAgreeRentWithLandlordView]
- val controller: DidYouAgreeRentWithLandlordController = new DidYouAgreeRentWithLandlordController(view, mockAuthJourney, mockPropertyLinkingAction, mockRaldRepo, mcc)(mockConfig, ec)
+ val controllerNoProperty: DidYouAgreeRentWithLandlordController = new DidYouAgreeRentWithLandlordController(view, fakeAuth, fakeData(None), mockSessionRepository, mockNavigator, mcc)(mockConfig, ec)
+ val controllerProperty: Option[UserAnswers] => DidYouAgreeRentWithLandlordController = answers => new DidYouAgreeRentWithLandlordController(view, fakeAuth, fakeDataProperty(Some(property), answers), mockSessionRepository, mockNavigator, mcc)(mockConfig, ec)
+ val didYouAgreeWithTheLandlordAnswers: Option[UserAnswers] = UserAnswers("id").set(DidYouAgreeRentWithLandlordPage, "YesTheLandlord").toOption
"Did you agree rent with landlord 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())
+ val result = controllerProperty(None).show(NormalMode)(authenticatedFakeRequest)
status(result) mustBe OK
val content = contentAsString(result)
content must include(pageTitle)
}
+ "Return OK and the correct view with prepopulated answers" in {
+ val result = controllerProperty(didYouAgreeWithTheLandlordAnswers).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[type=radio][name=did-you-agree-rent-with-landlord-radio][value=YesTheLandlord]").hasAttr("checked") mustBe true
+ document.select("input[type=radio][name=did-you-agree-rent-with-landlord-radio][value=NoACourtSet]").hasAttr("checked") mustBe false
+ }
"Return NotFoundException when property is not found in the mongo" in {
- mockRequestWithoutProperty()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(NormalMode)(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
"method submit" must {
- "Return OK and the correct view after submitting with written radio button" 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.DidYouAgreeRentWithLandlordController.submit)
+ "Return OK and the correct view after submitting with YesTheLandlord radio button" in {
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.DidYouAgreeRentWithLandlordController.submit(NormalMode))
.withFormUrlEncodedBody(("did-you-agree-rent-with-landlord-radio", "YesTheLandlord"))
.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") shouldBe Some("/ngr-rald-frontend/do-you-have-a-rent-free-period")
})
status(result) mustBe SEE_OTHER
- redirectLocation(result) shouldBe Some(routes.CheckRentFreePeriodController.show.url)
+ redirectLocation(result) shouldBe Some(routes.CheckRentFreePeriodController.show(NormalMode).url)
}
- "Return OK and the correct view after submitting with verbal radio button" 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.WhatTypeOfAgreementController.submit)
+ "Return OK and the correct view after submitting with NoACourtSet radio button" in {
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.DidYouAgreeRentWithLandlordController.submit(NormalMode))
.withFormUrlEncodedBody(("did-you-agree-rent-with-landlord-radio", "NoACourtSet"))
.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") shouldBe Some("/ngr-rald-frontend/do-you-have-a-rent-free-period")
+ result.header.headers.get("Location") shouldBe Some("/ngr-rald-frontend/did-the-court-set-an-interim-rent")
})
status(result) mustBe SEE_OTHER
- redirectLocation(result) shouldBe Some(routes.CheckRentFreePeriodController.show.url)
+ redirectLocation(result) shouldBe Some(routes.RentInterimController.show(NormalMode).url)
}
"Return Form with Errors when no radio button is selected" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.WhatTypeOfAgreementController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.DidYouAgreeRentWithLandlordController.submit(NormalMode))
.withFormUrlEncodedBody(("did-you-agree-rent-with-landlord-radio", ""))
.withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some(""))))
result.map(result => {
@@ -93,13 +101,13 @@ class DidYouAgreeRentWithLandlordControllerSpec extends ControllerSpecSupport {
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.WhatTypeOfAgreementController.submit)
+ await(controllerNoProperty.submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.DidYouAgreeRentWithLandlordController.submit(NormalMode))
.withFormUrlEncodedBody(("did-you-agree-rent-with-landlord-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
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/DoesYourRentIncludeParkingControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/DoesYourRentIncludeParkingControllerSpec.scala
index 6499a0b9..1397ed74 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/DoesYourRentIncludeParkingControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/DoesYourRentIncludeParkingControllerSpec.scala
@@ -16,6 +16,7 @@
package uk.gov.hmrc.ngrraldfrontend.controllers
+import org.jsoup.Jsoup
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.when
import play.api.http.Status.{BAD_REQUEST, OK, SEE_OTHER}
@@ -26,7 +27,8 @@ 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.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, RaldUserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, NormalMode, RaldUserAnswers, UserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.pages.DoesYourRentIncludeParkingPage
import uk.gov.hmrc.ngrraldfrontend.views.html.DoesYourRentIncludeParkingView
import scala.concurrent.Future
@@ -34,31 +36,40 @@ import scala.concurrent.Future
class DoesYourRentIncludeParkingControllerSpec extends ControllerSpecSupport {
val pageTitle = "Does your rent include parking spaces or garages?"
val view: DoesYourRentIncludeParkingView = inject[DoesYourRentIncludeParkingView]
- val controller: DoesYourRentIncludeParkingController = new DoesYourRentIncludeParkingController(view, mockAuthJourney, mockPropertyLinkingAction, mockRaldRepo, mcc)(mockConfig, ec)
+ val controllerNoProperty: DoesYourRentIncludeParkingController = new DoesYourRentIncludeParkingController(view, fakeAuth, fakeData(None), mockSessionRepository, mockNavigator, mcc)(mockConfig, ec)
+ val controllerProperty: Option[UserAnswers] => DoesYourRentIncludeParkingController = answers => new DoesYourRentIncludeParkingController(view, fakeAuth, fakeDataProperty(Some(property),answers), mockSessionRepository, mockNavigator, mcc)(mockConfig, ec)
+ val doesYourRentIncludeParkingAnswers: Option[UserAnswers] = UserAnswers("id").set(DoesYourRentIncludeParkingPage, "Yes").toOption
- " Does Your Rent IncludeParking Controller" must {
+
+ "Does Your Rent IncludeParking 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())
+ val result = controllerProperty(None).show(NormalMode)(authenticatedFakeRequest)
status(result) mustBe OK
val content = contentAsString(result)
content must include(pageTitle)
}
+ "Return OK and the correct view with prepopulated answers" in {
+ val result = controllerProperty(doesYourRentIncludeParkingAnswers).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ println(document)
+ document.select("input[type=radio][name=doesYourRentIncludeParking-radio-value][value=Yes]").hasAttr("checked") mustBe true
+ }
"Return NotFoundException when property is not found in the mongo" in {
- mockRequestWithoutProperty()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(NormalMode)(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
"method submit" must {
"Return OK and the correct view after submitting yes" 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.DoesYourRentIncludeParkingController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.DoesYourRentIncludeParkingController.submit(NormalMode))
.withFormUrlEncodedBody(
"doesYourRentIncludeParking-radio-value" -> "Yes",
)
@@ -67,12 +78,11 @@ class DoesYourRentIncludeParkingControllerSpec extends ControllerSpecSupport {
result.header.headers.get("Location") mustBe Some("/how-many-parking-spaces-or-garages-included-in-rent")
})
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.HowManyParkingSpacesOrGaragesIncludedInRentController.show.url)
+ redirectLocation(result) mustBe Some(routes.HowManyParkingSpacesOrGaragesIncludedInRentController.show(NormalMode).url)
}
"Return OK and the correct view after submitting no" 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.DoesYourRentIncludeParkingController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.DoesYourRentIncludeParkingController.submit(NormalMode))
.withFormUrlEncodedBody(
"doesYourRentIncludeParking-radio-value" -> "No",
)
@@ -81,11 +91,10 @@ class DoesYourRentIncludeParkingControllerSpec extends ControllerSpecSupport {
result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/do-you-have-a-rent-free-period")
})
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.CheckRentFreePeriodController.show.url)
+ redirectLocation(result) mustBe Some(routes.CheckRentFreePeriodController.show(NormalMode).url)
}
"Return Form with Errors when no radio selection is input" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.DoesYourRentIncludeParkingController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.DoesYourRentIncludeParkingController.submit(NormalMode))
.withFormUrlEncodedBody(
"doesYourRentIncludeParking-radio-value" -> "",
)
@@ -99,13 +108,13 @@ class DoesYourRentIncludeParkingControllerSpec extends ControllerSpecSupport {
}
"Return Exception if no address is in the mongo" in {
- mockRequestWithoutProperty()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ await(controllerNoProperty.submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit(NormalMode))
.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
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/HowManyParkingSpacesOrGaragesIncludedInRentControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/HowManyParkingSpacesOrGaragesIncludedInRentControllerSpec.scala
index c7d4725f..cb2494f2 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/HowManyParkingSpacesOrGaragesIncludedInRentControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/HowManyParkingSpacesOrGaragesIncludedInRentControllerSpec.scala
@@ -16,79 +16,107 @@
package uk.gov.hmrc.ngrraldfrontend.controllers
+import org.jsoup.Jsoup
+import org.mockito.ArgumentMatchers.any
+import org.mockito.Mockito.when
import play.api.http.Status.{BAD_REQUEST, OK, SEE_OTHER}
import play.api.test.FakeRequest
import play.api.test.Helpers.{await, contentAsString, defaultAwaitTimeout, redirectLocation, status}
import uk.gov.hmrc.http.{HeaderNames, NotFoundException}
import uk.gov.hmrc.ngrraldfrontend.helpers.ControllerSpecSupport
+import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
+import uk.gov.hmrc.ngrraldfrontend.models.{HowManyParkingSpacesOrGarages, NormalMode, UserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.pages.HowManyParkingSpacesOrGaragesIncludedInRentPage
import uk.gov.hmrc.ngrraldfrontend.views.html.HowManyParkingSpacesOrGaragesIncludedInRentView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.InputText
+import scala.concurrent.Future
+
class HowManyParkingSpacesOrGaragesIncludedInRentControllerSpec extends ControllerSpecSupport {
val pageTitle = "How many parking spaces or garages are included in your rent?"
val view: HowManyParkingSpacesOrGaragesIncludedInRentView = inject[HowManyParkingSpacesOrGaragesIncludedInRentView]
- val controller: HowManyParkingSpacesOrGaragesIncludedInRentController = new HowManyParkingSpacesOrGaragesIncludedInRentController(
+ val controllerNoProperty: HowManyParkingSpacesOrGaragesIncludedInRentController = new HowManyParkingSpacesOrGaragesIncludedInRentController(
+ howManyParkingSpacesOrGaragesIncludedInRentView = view,
+ authenticate = fakeAuth,
+ inputText = mockInputText,
+ getData = fakeData(None),
+ sessionRepository = mockSessionRepository,
+ navigator = mockNavigator,
+ mcc = mcc)(mockConfig)
+
+ val controllerProperty: Option[UserAnswers] => HowManyParkingSpacesOrGaragesIncludedInRentController = answers => new HowManyParkingSpacesOrGaragesIncludedInRentController(
howManyParkingSpacesOrGaragesIncludedInRentView = view,
- authenticate = mockAuthJourney,
+ authenticate = fakeAuth,
inputText = mockInputText,
- hasLinkedProperties = mockPropertyLinkingAction,
- raldRepo = mockRaldRepo,
+ getData = fakeDataProperty(Some(property), answers),
+ sessionRepository = mockSessionRepository,
+ navigator = mockNavigator,
mcc = mcc)(mockConfig)
- " HowManyParkingSpacesOrGaragesIncludedInRentController" must {
+ val howManyParkingGaragesAnswers: Option[UserAnswers] = UserAnswers("id").set(HowManyParkingSpacesOrGaragesIncludedInRentPage, HowManyParkingSpacesOrGarages("1","2","3")).toOption
+
+ "HowManyParkingSpacesOrGaragesIncludedInRentController" must {
"method show" must {
"Return OK and the correct view" in {
- val result = controller.show()(authenticatedFakeRequest())
+ val result = controllerProperty(None).show(NormalMode)(authenticatedFakeRequest)
status(result) mustBe OK
val content = contentAsString(result)
content must include(pageTitle)
}
+ "return OK and the correct view with prepopulated answers" in {
+ val result = controllerProperty(howManyParkingGaragesAnswers).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[name=uncoveredSpaces]").attr("value") mustBe "1"
+ document.select("input[name=coveredSpaces]").attr("value") mustBe "2"
+ document.select("input[name=garages]").attr("value") mustBe "3"
+ }
"Return NotFoundException when property is not found in the mongo" in {
- mockRequestWithoutProperty()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(NormalMode)(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
"method submit" must {
"Return OK and the correct view" in {
- val fakePostRequest = FakeRequest(routes.HowManyParkingSpacesOrGaragesIncludedInRentController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val fakePostRequest = FakeRequest(routes.HowManyParkingSpacesOrGaragesIncludedInRentController.submit(NormalMode))
.withFormUrlEncodedBody(
"uncoveredSpaces" -> "1",
"coveredSpaces" -> "0",
"garages" -> "0"
).withHeaders(HeaderNames.authorisation -> "Bearer 1")
- val result = controller.submit()(authenticatedFakeRequest(fakePostRequest))
+ val result = controllerProperty(None).submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.CheckRentFreePeriodController.show.url)
+ redirectLocation(result) mustBe Some(routes.CheckRentFreePeriodController.show(NormalMode).url)
}
"Return BAD_REQUEST for inputting 0 in all fields and the correct view" in {
- mockRequest()
- val fakePostRequest = FakeRequest(routes.HowManyParkingSpacesOrGaragesIncludedInRentController.submit)
+ val fakePostRequest = FakeRequest(routes.HowManyParkingSpacesOrGaragesIncludedInRentController.submit(NormalMode))
.withFormUrlEncodedBody(
"uncoveredSpaces" -> "0",
"coveredSpaces" -> "0",
"garages" -> "0"
).withHeaders(HeaderNames.authorisation -> "Bearer 1")
- val result = controller.submit()(authenticatedFakeRequest(fakePostRequest))
+ val result = controllerProperty(None).submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
status(result) mustBe BAD_REQUEST
}
"Return Exception if no address is in the mongo" in {
- mockRequestWithoutProperty()
- val fakePostRequest = FakeRequest(routes.HowManyParkingSpacesOrGaragesIncludedInRentController.submit)
+ val fakePostRequest = FakeRequest(routes.HowManyParkingSpacesOrGaragesIncludedInRentController.submit(NormalMode))
.withFormUrlEncodedBody(
"uncoveredSpaces" -> "0",
"coveredSpaces" -> "0",
"garages" -> "0"
).withHeaders(HeaderNames.authorisation -> "Bearer 1")
val exception = intercept[NotFoundException] {
- await(controller.submit()(authenticatedFakeRequest(fakePostRequest)))
+ await(controllerNoProperty.submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest)))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/HowMuchIsTotalAnnualRentControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/HowMuchIsTotalAnnualRentControllerSpec.scala
index a5970e9f..f0470e17 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/HowMuchIsTotalAnnualRentControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/HowMuchIsTotalAnnualRentControllerSpec.scala
@@ -16,63 +16,97 @@
package uk.gov.hmrc.ngrraldfrontend.controllers
+import org.jsoup.Jsoup
+import org.mockito.ArgumentMatchers.any
+import org.mockito.Mockito.when
import play.api.http.Status.{BAD_REQUEST, OK, SEE_OTHER}
import play.api.test.FakeRequest
import play.api.test.Helpers.{await, contentAsString, defaultAwaitTimeout, redirectLocation, status}
import uk.gov.hmrc.http.{HeaderNames, NotFoundException}
import uk.gov.hmrc.ngrraldfrontend.helpers.ControllerSpecSupport
+import uk.gov.hmrc.ngrraldfrontend.models.AgreementType.{NewAgreement, RenewedAgreement}
+import uk.gov.hmrc.ngrraldfrontend.models.{NormalMode, UserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
+import uk.gov.hmrc.ngrraldfrontend.pages.{HowMuchIsTotalAnnualRentPage, TellUsAboutYourNewAgreementPage, TellUsAboutYourRenewedAgreementPage}
import uk.gov.hmrc.ngrraldfrontend.views.html.HowMuchIsTotalAnnualRentView
+import scala.concurrent.Future
+
+
class HowMuchIsTotalAnnualRentControllerSpec extends ControllerSpecSupport {
val pageTitle = "How much is your total annual rent?"
val view: HowMuchIsTotalAnnualRentView = inject[HowMuchIsTotalAnnualRentView]
- val controller: HowMuchIsTotalAnnualRentController = new HowMuchIsTotalAnnualRentController(view, mockAuthJourney, mockPropertyLinkingAction, mockRaldRepo, mcc)(mockConfig)
+ val controllerNoProperty: HowMuchIsTotalAnnualRentController = new HowMuchIsTotalAnnualRentController(view, fakeAuth, fakeData(None), mockSessionRepository, mockNavigator, mcc)(mockConfig)
+ val controllerProperty: HowMuchIsTotalAnnualRentController = new HowMuchIsTotalAnnualRentController(view, fakeAuth, fakeDataProperty(Some(property),None), mockSessionRepository, mockNavigator, mcc)(mockConfig)
+ lazy val renewedAgreementAnswers: Option[UserAnswers] = UserAnswers("id").set(TellUsAboutYourRenewedAgreementPage, RenewedAgreement).toOption
+ lazy val newAgreementAnswers: Option[UserAnswers] = UserAnswers("id").set(TellUsAboutYourNewAgreementPage, NewAgreement).toOption
+ lazy val howMuchIsTotalAnnualRentAnswers: Option[UserAnswers] = UserAnswers("id").set(HowMuchIsTotalAnnualRentPage, BigDecimal(1234.67)).toOption
+ lazy val filledController: Option[UserAnswers] => HowMuchIsTotalAnnualRentController = answers => HowMuchIsTotalAnnualRentController(
+ view, fakeAuth, fakeDataProperty(Some(property), answers), mockSessionRepository, mockNavigator, mcc
+ )
"TypeOfLeaseRenewalController" must {
"method show" must {
"Return OK and the correct view" in {
- val result = controller.show()(authenticatedFakeRequest())
+ val result = controllerProperty.show(NormalMode)(authenticatedFakeRequest)
status(result) mustBe OK
val content = contentAsString(result)
content must include(pageTitle)
}
+ "Return OK and the correct with prepopulated answers" in {
+ val result = filledController(howMuchIsTotalAnnualRentAnswers).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[name=how–much–is–total–annual–rent-value]").attr("value") mustBe "1234.67"
+ }
"Return NotFoundException when property is not found in the mongo" in {
- mockRequestWithoutProperty()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(NormalMode)(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
"method submit" must {
- "Return OK and the correct view" in {
- val fakePostRequest = FakeRequest(routes.HowMuchIsTotalAnnualRentController.submit)
+ "Return OK and the correct view if its a renewedAgreement" in {
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val fakePostRequest = FakeRequest(routes.HowMuchIsTotalAnnualRentController.submit(NormalMode))
+ .withFormUrlEncodedBody(("how–much–is–total–annual–rent-value", "10000"))
+ .withHeaders(HeaderNames.authorisation -> "Bearer 1")
+
+ val result = filledController(renewedAgreementAnswers).submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
+ status(result) mustBe SEE_OTHER
+ redirectLocation(result) mustBe Some(routes.DidYouAgreeRentWithLandlordController.show(NormalMode).url)
+ }
+ "Return OK and the correct view if its a newAgreement" in {
+
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val fakePostRequest = FakeRequest(routes.HowMuchIsTotalAnnualRentController.submit(NormalMode))
.withFormUrlEncodedBody(("how–much–is–total–annual–rent-value", "10000"))
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
- val result = controller.submit()(authenticatedFakeRequest(fakePostRequest))
+ val result = filledController(newAgreementAnswers).submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.CheckRentFreePeriodController.show.url)
+ redirectLocation(result) mustBe Some(routes.CheckRentFreePeriodController.show(NormalMode).url)
}
"Return BAD_REQUEST for missing input and the correct view" in {
- mockRequest()
- val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit)
+ val fakePostRequest = FakeRequest(routes.HowMuchIsTotalAnnualRentController.submit(NormalMode))
.withFormUrlEncodedBody(("how–much–is–total–annual–rent-value", ""))
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
- val result = controller.submit()(authenticatedFakeRequest(fakePostRequest))
+ val result = controllerProperty.submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
status(result) mustBe BAD_REQUEST
}
"Return Exception if no address is in the mongo" in {
- mockRequestWithoutProperty()
- val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit)
+ val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit(NormalMode))
.withFormUrlEncodedBody(("how–much–is–total–annual–rent-value", ""))
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
val exception = intercept[NotFoundException] {
- await(controller.submit()(authenticatedFakeRequest(fakePostRequest)))
+ await(controllerNoProperty.submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest)))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/InterimRentSetByTheCourtControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/InterimRentSetByTheCourtControllerSpec.scala
index 284a8f3c..7123446e 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/InterimRentSetByTheCourtControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/InterimRentSetByTheCourtControllerSpec.scala
@@ -35,45 +35,76 @@ package uk.gov.hmrc.ngrraldfrontend.controllers
*/
+import org.jsoup.Jsoup
import play.api.http.Status.{BAD_REQUEST, OK, SEE_OTHER}
import play.api.test.FakeRequest
import play.api.test.Helpers.{await, contentAsString, defaultAwaitTimeout, redirectLocation, status}
import uk.gov.hmrc.http.{HeaderNames, NotFoundException}
import uk.gov.hmrc.ngrraldfrontend.helpers.ControllerSpecSupport
+import uk.gov.hmrc.ngrraldfrontend.models.{InterimRentSetByTheCourt, NormalMode, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.views.html.InterimRentSetByTheCourtView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.InputText
+import org.mockito.ArgumentMatchers.any
+import org.mockito.Mockito.when
+import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
+import uk.gov.hmrc.ngrraldfrontend.pages.{AgreedRentChangePage, InterimSetByTheCourtPage}
+
+import scala.concurrent.Future
+
class InterimRentSetByTheCourtControllerSpec extends ControllerSpecSupport {
val pageTitle = "Interim rent set by the court"
val view: InterimRentSetByTheCourtView = inject[InterimRentSetByTheCourtView]
- val controller: InterimRentSetByTheCourtController = new InterimRentSetByTheCourtController(
+ val controllerNoProperty: InterimRentSetByTheCourtController = new InterimRentSetByTheCourtController(
+ interimRentSetByTheCourtView = view,
+ authenticate = fakeAuth,
+ inputText = mockInputText,
+ getData = fakeData(None),
+ sessionRepository = mockSessionRepository,
+ navigator = mockNavigator,
+ mcc = mcc)(mockConfig)
+ val controllerProperty: Option[UserAnswers] => InterimRentSetByTheCourtController = answers => new InterimRentSetByTheCourtController(
interimRentSetByTheCourtView = view,
- authenticate = mockAuthJourney,
- hasLinkedProperties = mockPropertyLinkingAction,
+ authenticate = fakeAuth,
inputText = mockInputText,
- raldRepo = mockRaldRepo,
+ getData = fakeDataProperty(Some(property),answers),
+ sessionRepository = mockSessionRepository,
+ navigator = mockNavigator,
mcc = mcc)(mockConfig)
+ val interimSetByTheCourtAnswers: Option[UserAnswers] = UserAnswers("id").set(InterimSetByTheCourtPage, interimRentSetByTheCourtModel).toOption
+
"InterimRentSetByTheCourtController" must {
"method show" must {
"Return OK and the correct view" in {
- val result = controller.show()(authenticatedFakeRequest())
+ val result = controllerProperty(None).show(NormalMode)(authenticatedFakeRequest)
status(result) mustBe OK
val content = contentAsString(result)
content must include(pageTitle)
}
+ "Return OK and the correct view with prepopulated answers" in {
+ val result = controllerProperty(interimSetByTheCourtAnswers).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[name=interimAmount]").attr("value") mustBe "10000"
+ document.select("input[name=date.month]").attr("value") mustBe "1"
+ document.select("input[name=date.year]").attr("value") mustBe "1990"
+
+ }
"Return NotFoundException when property is not found in the mongo" in {
- mockRequestWithoutProperty()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(NormalMode)(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
"method submit" must {
"Return OK and the correct view" in {
- val fakePostRequest = FakeRequest(routes.InterimRentSetByTheCourtController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val fakePostRequest = FakeRequest(routes.InterimRentSetByTheCourtController.submit(NormalMode))
.withFormUrlEncodedBody(
"interimAmount" -> "10000",
"date.month" -> "1",
@@ -81,13 +112,12 @@ class InterimRentSetByTheCourtControllerSpec extends ControllerSpecSupport {
)
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
- val result = controller.submit()(authenticatedFakeRequest(fakePostRequest))
+ val result = controllerProperty(None).submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.CheckRentFreePeriodController.show.url)
+ redirectLocation(result) mustBe Some(routes.CheckRentFreePeriodController.show(NormalMode).url)
}
"Return BAD_REQUEST for missing how much input and the correct view" in {
- mockRequest()
- val fakePostRequest = FakeRequest(routes.InterimRentSetByTheCourtController.submit)
+ val fakePostRequest = FakeRequest(routes.InterimRentSetByTheCourtController.submit(NormalMode))
.withFormUrlEncodedBody(
"interimAmount" -> "",
"date.month" -> "1",
@@ -95,14 +125,13 @@ class InterimRentSetByTheCourtControllerSpec extends ControllerSpecSupport {
)
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
- val result = controller.submit()(authenticatedFakeRequest(fakePostRequest))
+ val result = controllerProperty(None).submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include("Enter how much the interim rent was, in pounds")
}
"Return BAD_REQUEST for missing month input and the correct view" in {
- mockRequest()
- val fakePostRequest = FakeRequest(routes.InterimRentSetByTheCourtController.submit)
+ val fakePostRequest = FakeRequest(routes.InterimRentSetByTheCourtController.submit(NormalMode))
.withFormUrlEncodedBody(
"interimAmount" -> "1000",
"date.month" -> "",
@@ -110,14 +139,13 @@ class InterimRentSetByTheCourtControllerSpec extends ControllerSpecSupport {
)
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
- val result = controller.submit()(authenticatedFakeRequest(fakePostRequest))
+ val result = controllerProperty(None).submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include("Date you started paying the interim rent must include a month")
}
"Return BAD_REQUEST for missing year input and the correct view" in {
- mockRequest()
- val fakePostRequest = FakeRequest(routes.InterimRentSetByTheCourtController.submit)
+ val fakePostRequest = FakeRequest(routes.InterimRentSetByTheCourtController.submit(NormalMode))
.withFormUrlEncodedBody(
"interimAmount" -> "1000",
"date.month" -> "1",
@@ -125,20 +153,19 @@ class InterimRentSetByTheCourtControllerSpec extends ControllerSpecSupport {
)
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
- val result = controller.submit()(authenticatedFakeRequest(fakePostRequest))
+ val result = controllerProperty(None).submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include("Date you started paying the interim rent must include a year")
}
"Return Exception if no address is in the mongo" in {
- mockRequestWithoutProperty()
- val fakePostRequest = FakeRequest(routes.InterimRentSetByTheCourtController.submit)
+ val fakePostRequest = FakeRequest(routes.InterimRentSetByTheCourtController.submit(NormalMode))
.withFormUrlEncodedBody(("how–much–is–total–annual–rent-value", ""))
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
val exception = intercept[NotFoundException] {
- await(controller.submit()(authenticatedFakeRequest(fakePostRequest)))
+ await(controllerNoProperty.submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest)))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordControllerSpec.scala
index 6f4b8a58..590c2cea 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/LandlordControllerSpec.scala
@@ -16,6 +16,7 @@
package uk.gov.hmrc.ngrraldfrontend.controllers
+import org.jsoup.Jsoup
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.when
import play.api.http.Status.{BAD_REQUEST, OK, SEE_OTHER}
@@ -24,9 +25,10 @@ import play.api.test.Helpers.{await, contentAsString, defaultAwaitTimeout, redir
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.AgreementType.{NewAgreement, RenewedAgreement, RentAgreement}
import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, RaldUserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, NormalMode, RaldUserAnswers, UserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.pages.{LandlordPage, TellUsAboutRentPage, TellUsAboutYourNewAgreementPage, TellUsAboutYourRenewedAgreementPage}
import uk.gov.hmrc.ngrraldfrontend.views.html.LandlordView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.NGRCharacterCountComponent
@@ -36,31 +38,44 @@ class LandlordControllerSpec extends ControllerSpecSupport {
val pageTitle = "Landlord"
val view: LandlordView = inject[LandlordView]
val mockNGRCharacterCountComponent: NGRCharacterCountComponent = inject[NGRCharacterCountComponent]
- val controller: LandlordController = new LandlordController(view, mockAuthJourney, mockPropertyLinkingAction, mockRaldRepo, mockNGRCharacterCountComponent, mcc)(mockConfig, ec)
+ val controllerNoProperty: LandlordController = new LandlordController(view, fakeAuth, mockNGRCharacterCountComponent, mcc, fakeData(None), mockSessionRepository, mockNavigator)(mockConfig, ec)
+ val controllerProperty: LandlordController = new LandlordController(view, fakeAuth, mockNGRCharacterCountComponent, mcc, fakeDataProperty(Some(property),None), mockSessionRepository, mockNavigator)(mockConfig, ec)
+ lazy val renewedAgreementAnswers: Option[UserAnswers] = UserAnswers("id").set(TellUsAboutYourRenewedAgreementPage, RenewedAgreement).toOption
+ lazy val newAgreementAnswers: Option[UserAnswers] = UserAnswers("id").set(TellUsAboutYourNewAgreementPage, NewAgreement).toOption
+ lazy val rentAgreementAnswers: Option[UserAnswers] = UserAnswers("id").set(TellUsAboutRentPage, RentAgreement).toOption
+ lazy val filledController: Option[UserAnswers] => LandlordController = answers => LandlordController(view, fakeAuth, mockNGRCharacterCountComponent, mcc, fakeDataProperty(Some(property), answers), mockSessionRepository, mockNavigator)
+ lazy val landlordAnswers: Option[UserAnswers] = UserAnswers("id").set(LandlordPage, landlordModel).toOption
- "Tell us about your new agreement controller" must {
+ "Landlord 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())
+ val result = controllerProperty.show(NormalMode)(authenticatedFakeRequest)
status(result) mustBe OK
val content = contentAsString(result)
content must include(pageTitle)
}
+ "Return OK and the correct view with prepopulated data" in {
+ val result = filledController(landlordAnswers).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[name=landlord-name-value]").attr("value") mustBe "Joe Bloggs"
+ document.select("input[name=landlord-radio]").attr("value") mustBe "LandLordAndTenant"
+
+ }
"Return NotFoundException when property is not found in the mongo" in {
- mockRequestWithoutProperty()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(NormalMode)(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
"method submit" must {
- "Return OK and the correct view after submitting with name and radio button selected" 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.LandlordController.submit)
+ "Return OK and the correct view after submitting with name and radio button selected while in the rent agreement journey" in {
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = filledController(rentAgreementAnswers).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit(NormalMode))
.withFormUrlEncodedBody(
"landlord-name-value" -> "Bob",
"landlord-radio" -> "LandLordAndTenant"
@@ -70,12 +85,25 @@ class LandlordControllerSpec extends ControllerSpecSupport {
result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord")
})
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.WhatTypeOfAgreementController.show.url)
+ redirectLocation(result) mustBe Some(routes.WhatIsYourRentBasedOnController.show(NormalMode).url)
}
- "Return OK and the correct view after submitting with name and other radio button selected with description 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.LandlordController.submit)
+ "Return OK and the correct view after submitting with name and radio button selected while in the renewedAgreement journey" in {
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = filledController(renewedAgreementAnswers).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit(NormalMode))
+ .withFormUrlEncodedBody(
+ "landlord-name-value" -> "Bob",
+ "landlord-radio" -> "LandLordAndTenant"
+ )
+ .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 SEE_OTHER
+ redirectLocation(result) mustBe Some(routes.WhatTypeOfAgreementController.show(NormalMode).url)
+ }
+ "Return OK and the correct view after submitting with name and other radio button selected with description added while in the new agreement journey" in {
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = filledController(newAgreementAnswers).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit(NormalMode))
.withFormUrlEncodedBody(
"landlord-name-value" -> "Bob",
"landlord-radio" -> "LandLordAndTenant",
@@ -86,11 +114,10 @@ class LandlordControllerSpec extends ControllerSpecSupport {
result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord")
})
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.WhatTypeOfAgreementController.show.url)
+ redirectLocation(result) mustBe Some(routes.WhatTypeOfAgreementController.show(NormalMode).url)
}
"Return Form with Errors when no name is input" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty.submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit(NormalMode))
.withFormUrlEncodedBody(
"landlord-name-value" -> "",
"landlord-radio" -> "LandLordAndTenant"
@@ -104,8 +131,7 @@ class LandlordControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when no radio button is selected" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty.submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit(NormalMode))
.withFormUrlEncodedBody(
"landlord-name-value" -> "Bob",
"landlord-radio" -> ""
@@ -119,8 +145,7 @@ class LandlordControllerSpec extends ControllerSpecSupport {
content must include(pageTitle)
}
"Return Form with Errors when other radio button is selected with no text" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty.submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit(NormalMode))
.withFormUrlEncodedBody(
"landlord-name-value" -> "Bob",
"landlord-radio" -> "OtherRelationship",
@@ -134,15 +159,15 @@ class LandlordControllerSpec extends ControllerSpecSupport {
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
- }
+// "Return Exception if no address is in the mongo" in {
+// mockRequestWithoutProperty()
+// val exception = intercept[NotFoundException] {
+// await(controller.submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit(NormalMode))
+// .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/controllers/ProvideDetailsOfFirstSecondRentPeriodControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/ProvideDetailsOfFirstSecondRentPeriodControllerSpec.scala
index e3b64397..8ed59e4f 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/ProvideDetailsOfFirstSecondRentPeriodControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/ProvideDetailsOfFirstSecondRentPeriodControllerSpec.scala
@@ -16,58 +16,114 @@
package uk.gov.hmrc.ngrraldfrontend.controllers
+import org.jsoup.Jsoup
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}
+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.{AuthenticatedUserRequest, NormalMode, RaldUserAnswers, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
+import uk.gov.hmrc.ngrraldfrontend.pages.ProvideDetailsOfFirstSecondRentPeriodPage
import uk.gov.hmrc.ngrraldfrontend.views.html.ProvideDetailsOfFirstSecondRentPeriodView
-import uk.gov.hmrc.ngrraldfrontend.views.html.components.InputText
+import uk.gov.hmrc.ngrraldfrontend.views.html.components.{DateTextFields, InputText}
import scala.concurrent.Future
-class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpecSupport {
+class ProvideDetailsOfFirstSecondRentPeriodSpec extends ControllerSpecSupport {
val pageTitle = "Provide details of each rent period"
val view: ProvideDetailsOfFirstSecondRentPeriodView = inject[ProvideDetailsOfFirstSecondRentPeriodView]
- val controller: ProvideDetailsOfFirstSecondRentPeriodController = new ProvideDetailsOfFirstSecondRentPeriodController(
+ val controllerNoProperty: ProvideDetailsOfFirstSecondRentPeriodController = new ProvideDetailsOfFirstSecondRentPeriodController(
view,
- mockAuthJourney,
+ fakeAuth,
mockInputText,
- mockPropertyLinkingAction,
- mockRaldRepo, mcc
+ mcc,
+ fakeData(None),
+ mockSessionRepository,
+ mockNavigator
)(mockConfig, ec)
+ val controllerProperty: Option[UserAnswers] => ProvideDetailsOfFirstSecondRentPeriodController = answers => new ProvideDetailsOfFirstSecondRentPeriodController(
+ view,
+ fakeAuth,
+ mockInputText,
+ mcc,
+ fakeDataProperty(Some(property), answers),
+ mockSessionRepository,
+ mockNavigator
+ )(mockConfig, ec)
+
+ val firstSecondRentPeriodAnswers: Option[UserAnswers] = UserAnswers("id").set(ProvideDetailsOfFirstSecondRentPeriodPage, firstSecondRentPeriod).toOption
+ val firstSecondRentPeriodAnswersMin: Option[UserAnswers] = UserAnswers("id").set(ProvideDetailsOfFirstSecondRentPeriodPage, firstSecondRentPeriodNoRentPayed).toOption
+
+
"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())
+ val result = controllerProperty(None).show(NormalMode)(authenticatedFakeRequest)
status(result) mustBe OK
val content = contentAsString(result)
content must include(pageTitle)
}
+ "Return OK and the correct view with prepopulated data and YesPayedRent" in {
+ val result = controllerProperty(firstSecondRentPeriodAnswers).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[name=first.startDate.day]").attr("value") mustBe "1"
+ document.select("input[name=first.startDate.month]").attr("value") mustBe "1"
+ document.select("input[name=first.startDate.year]").attr("value") mustBe "2025"
+ document.select("input[name=first.endDate.day]").attr("value") mustBe "31"
+ document.select("input[name=first.endDate.month]").attr("value") mustBe "1"
+ document.select("input[name=first.endDate.year]").attr("value") mustBe "2025"
+ document.select("input[type=radio][name=provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio][value=yesPayedRent]").hasAttr("checked") mustBe true
+ document.select("input[name=second.startDate.day]").attr("value") mustBe "1"
+ document.select("input[name=second.startDate.month]").attr("value") mustBe "2"
+ document.select("input[name=second.startDate.year]").attr("value") mustBe "2025"
+ document.select("input[name=second.endDate.day]").attr("value") mustBe "28"
+ document.select("input[name=second.endDate.month]").attr("value") mustBe "2"
+ document.select("input[name=second.endDate.year]").attr("value") mustBe "2025"
+ document.select("input[name=SecondRentPeriodAmount]").attr("value") mustBe "1000"
+ }
+ "Return OK and the correct view with prepopulated data and noRentPayed" in {
+ val result = controllerProperty(firstSecondRentPeriodAnswersMin).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[name=first.startDate.day]").attr("value") mustBe "1"
+ document.select("input[name=first.startDate.month]").attr("value") mustBe "1"
+ document.select("input[name=first.startDate.year]").attr("value") mustBe "2025"
+ document.select("input[name=first.endDate.day]").attr("value") mustBe "31"
+ document.select("input[name=first.endDate.month]").attr("value") mustBe "1"
+ document.select("input[name=first.endDate.year]").attr("value") mustBe "2025"
+ document.select("input[type=radio][name=provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio][value=noRentPayed]").hasAttr("checked") mustBe true
+ document.select("input[name=second.startDate.day]").attr("value") mustBe "1"
+ document.select("input[name=second.startDate.month]").attr("value") mustBe "2"
+ document.select("input[name=second.startDate.year]").attr("value") mustBe "2025"
+ document.select("input[name=second.endDate.day]").attr("value") mustBe "28"
+ document.select("input[name=second.endDate.month]").attr("value") mustBe "2"
+ document.select("input[name=second.endDate.year]").attr("value") mustBe "2025"
+ document.select("input[name=SecondRentPeriodAmount]").attr("value") mustBe "1000"
+ }
"Return NotFoundException when property is not found in the mongo" in {
- mockRequestWithoutProperty()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(NormalMode)(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend 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)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(NormalMode))
.withFormUrlEncodedBody(
"first.startDate.day" -> "12",
"first.startDate.month" -> "12",
@@ -75,7 +131,8 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
"first.endDate.day" -> "12",
"first.endDate.month" -> "12",
"first.endDate.year" -> "2026",
- "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "noRentPayed",
+ "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "yesPayedRent",
+ "RentPeriodAmount" -> "20000.00",
"second.startDate.day" -> "12",
"second.startDate.month" -> "12",
"second.startDate.year" -> "2026",
@@ -85,15 +142,16 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
"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.RentPeriodsController.show.url)
+ redirectLocation(result) mustBe Some(routes.RentPeriodsController.show(NormalMode).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)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(NormalMode))
.withFormUrlEncodedBody(
"first.startDate.day" -> "12",
"first.startDate.month" -> "12",
@@ -101,8 +159,7 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
"first.endDate.day" -> "12",
"first.endDate.month" -> "12",
"first.endDate.year" -> "2026",
- "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "yesPayedRent",
- "RentPeriodAmount" -> "20000.00",
+ "provideDetailsOfFirstSecondRentPeriod-radio-firstRentPeriodRadio" -> "noRentPayed",
"second.startDate.day" -> "12",
"second.startDate.month" -> "12",
"second.startDate.year" -> "2026",
@@ -112,13 +169,14 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
"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.RentPeriodsController.show.url)
+ redirectLocation(result) mustBe Some(routes.RentPeriodsController.show(NormalMode).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)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(NormalMode))
.withFormUrlEncodedBody(
"first.startDate.day" -> "",
"first.startDate.month" -> "12",
@@ -143,11 +201,9 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("Start date of the first rent period must include a day")
}
"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)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(NormalMode))
.withFormUrlEncodedBody(
"first.startDate.day" -> "12",
"first.startDate.month" -> "",
@@ -172,11 +228,9 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("Start date of the first rent period must include a month")
}
"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)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(NormalMode))
.withFormUrlEncodedBody(
"first.startDate.day" -> "12",
"first.startDate.month" -> "12",
@@ -201,11 +255,9 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("Start date of the first rent period must include a year")
}
"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)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(NormalMode))
.withFormUrlEncodedBody(
"first.startDate.day" -> "12",
"first.startDate.month" -> "12",
@@ -230,11 +282,9 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("End date of the first rent period must include a day")
}
"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)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(NormalMode))
.withFormUrlEncodedBody(
"first.startDate.day" -> "12",
"first.startDate.month" -> "12",
@@ -259,12 +309,11 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("End date of the first rent period must include a month")
}
"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)
+
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(NormalMode))
.withFormUrlEncodedBody(
"first.startDate.day" -> "12",
"first.startDate.month" -> "12",
@@ -289,11 +338,9 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("End date of the first rent period must include a year")
}
"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)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(NormalMode))
.withFormUrlEncodedBody(
"first.startDate.day" -> "12",
"first.startDate.month" -> "12",
@@ -318,12 +365,10 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("Start date of the second rent period must include a day")
}
"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)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(NormalMode))
.withFormUrlEncodedBody(
"first.startDate.day" -> "12",
"first.startDate.month" -> "12",
@@ -348,11 +393,9 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("Start date of the second rent period must include a month")
}
"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)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(NormalMode))
.withFormUrlEncodedBody(
"first.startDate.day" -> "12",
"first.startDate.month" -> "12",
@@ -377,11 +420,9 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("Start date of the second rent period must include a year")
}
"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)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(NormalMode))
.withFormUrlEncodedBody(
"first.startDate.day" -> "12",
"first.startDate.day" -> "12",
@@ -406,11 +447,9 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("End date of the second rent period must include a day")
}
"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)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(NormalMode))
.withFormUrlEncodedBody(
"first.startDate.day" -> "12",
"first.startDate.month" -> "12",
@@ -435,11 +474,9 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("End date of the second rent period must include a month")
}
"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)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(NormalMode))
.withFormUrlEncodedBody(
"first.startDate.day" -> "12",
"first.startDate.month" -> "12",
@@ -464,11 +501,9 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("End date of the second rent period must include a year")
}
"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)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(NormalMode))
.withFormUrlEncodedBody(
"first.startDate.day" -> "12",
"first.startDate.month" -> "12",
@@ -493,11 +528,9 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("Select yes if you pay rent in this period.")
}
"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)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(NormalMode))
.withFormUrlEncodedBody(
"first.startDate.day" -> "12",
"first.startDate.month" -> "12",
@@ -522,11 +555,9 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("Enter the rent for the first rent period, in pounds.")
}
"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)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(NormalMode))
.withFormUrlEncodedBody(
"first.startDate.day" -> "12",
"first.startDate.month" -> "12",
@@ -551,11 +582,9 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("Enter the rent for the second rent period, in pounds.")
}
"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)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(NormalMode))
.withFormUrlEncodedBody(
"first.startDate.day" -> "12",
"first.startDate.month" -> "12",
@@ -580,11 +609,9 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("Select yes if you pay rent in this period.")
}
"Return Form with Errors when format is wrong for RentPeriodAmount" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(NormalMode))
.withFormUrlEncodedBody(
"first.startDate.day" -> "12",
"first.startDate.month" -> "12",
@@ -609,11 +636,9 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("Rent for the first rent period must be a number, like 30,000")
}
"Return Form with Errors when format is wrong for SecondRentPeriodAmount" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.ProvideDetailsOfFirstSecondRentPeriodController.submit(NormalMode))
.withFormUrlEncodedBody(
"first.startDate.day" -> "12",
"first.startDate.month" -> "12",
@@ -638,16 +663,14 @@ class ProvideDetailsOfFirstSecondRentPeriodControllerSpec extends ControllerSpec
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("Rent for the second rent period must be a number, like 30,000")
}
"Return Exception if no address is in the mongo" in {
- mockRequestWithoutProperty()
val exception = intercept[NotFoundException] {
- await(controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ await(controllerNoProperty.submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit(NormalMode))
.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
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/RentDatesAgreeControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/RentDatesAgreeControllerSpec.scala
index 693972f6..4057d032 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/RentDatesAgreeControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/RentDatesAgreeControllerSpec.scala
@@ -16,6 +16,7 @@
package uk.gov.hmrc.ngrraldfrontend.controllers
+import org.jsoup.Jsoup
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.when
import play.api.test.FakeRequest
@@ -25,8 +26,9 @@ 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.{AuthenticatedUserRequest, NormalMode, RaldUserAnswers, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
+import uk.gov.hmrc.ngrraldfrontend.pages.{AgreedRentChangePage, RentDatesAgreePage}
import uk.gov.hmrc.ngrraldfrontend.views.html.RentDatesAgreeView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.InputText
@@ -35,57 +37,77 @@ import scala.concurrent.Future
class RentDatesAgreeControllerSpec extends ControllerSpecSupport {
val pageTitle = "Rent dates"
val view: RentDatesAgreeView = inject[RentDatesAgreeView]
- val controller: RentDatesAgreeController = new RentDatesAgreeController(
+ val controllerNoProperty: RentDatesAgreeController = new RentDatesAgreeController(
view,
- mockAuthJourney,
- mockPropertyLinkingAction,
- mockRaldRepo,
- mcc
+ fakeAuth,
+ mcc,
+ fakeData(None),
+ mockNavigator,
+ mockSessionRepository
)(mockConfig, ec)
- "Agreement controller" must {
+ val controllerProperty: Option[UserAnswers] => RentDatesAgreeController = answers => new RentDatesAgreeController(
+ view,
+ fakeAuth,
+ mcc,
+ fakeDataProperty(Some(property), answers),
+ mockNavigator,
+ mockSessionRepository
+ )(mockConfig, ec)
+
+ val rentDatesAgreeAnswers: Option[UserAnswers] = UserAnswers("id").set(RentDatesAgreePage, "2025-02-01").toOption
+
+
+
+ "Rent Date Agree 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())
+ val result = controllerProperty(None).show(NormalMode)(authenticatedFakeRequest)
status(result) mustBe OK
val content = contentAsString(result)
content must include(pageTitle)
}
+ "Return OK and the correct view with prepopulated answers" in {
+ val result = controllerProperty(rentDatesAgreeAnswers).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[name=date.day]").attr("value") mustBe "1"
+ document.select("input[name=date.month]").attr("value") mustBe "2"
+ document.select("input[name=date.year]").attr("value") mustBe "2025"
+ }
"Return NotFoundException when property is not found in the mongo" in {
- mockRequestWithoutProperty()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(NormalMode)(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend 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.RentDatesAgreeController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeController.submit(NormalMode))
.withFormUrlEncodedBody(
"date.day" -> "12",
"date.month" -> "12",
- "date.year" -> "2026",
+ "date.year" -> "2026"
)
.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-type-of-lease-renewal-is-it")
+ result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/rent-dates-agree")
})
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.WhatTypeOfLeaseRenewalController.show.url)
+ redirectLocation(result) mustBe Some(routes.WhatYourRentIncludesController.show(NormalMode).url)
}
"Return Form with Errors when no day is added" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeController.submit(NormalMode))
.withFormUrlEncodedBody(
"date.day" -> "",
"date.month" -> "12",
- "date.year" -> "2026",
+ "date.year" -> "2026"
)
.withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some(""))))
result.map(result => {
@@ -94,15 +116,13 @@ class RentDatesAgreeControllerSpec extends ControllerSpecSupport {
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("Date you agreed your rent must include a day.")
}
"Return Form with Errors when no month is added" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeController.submit(NormalMode))
.withFormUrlEncodedBody(
"date.day" -> "12",
"date.month" -> "",
- "date.year" -> "2026",
+ "date.year" -> "2026"
)
.withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some(""))))
result.map(result => {
@@ -111,11 +131,9 @@ class RentDatesAgreeControllerSpec extends ControllerSpecSupport {
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("Date you agreed your rent must include a month.")
}
"Return Form with Errors when no year is added" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeController.submit(NormalMode))
.withFormUrlEncodedBody(
"date.day" -> "12",
"date.month" -> "12",
@@ -128,15 +146,13 @@ class RentDatesAgreeControllerSpec extends ControllerSpecSupport {
status(result) mustBe BAD_REQUEST
val content = contentAsString(result)
content must include(pageTitle)
- content must include("Date you agreed your rent must include a year.")
}
"Return Exception if no address is in the mongo" in {
- mockRequestWithoutProperty()
val exception = intercept[NotFoundException] {
- await(controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeController.submit)
+ await(controllerNoProperty.submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeController.submit(NormalMode))
.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
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/RentDatesAgreeStartControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/RentDatesAgreeStartControllerSpec.scala
index 862c1d49..480789fd 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/RentDatesAgreeStartControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/RentDatesAgreeStartControllerSpec.scala
@@ -16,6 +16,7 @@
package uk.gov.hmrc.ngrraldfrontend.controllers
+import org.jsoup.Jsoup
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.when
import play.api.http.Status.{BAD_REQUEST, OK, SEE_OTHER}
@@ -26,7 +27,8 @@ 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.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, RaldUserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, NormalMode, RaldUserAnswers, RentDatesAgreeStart, UserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.pages.RentDatesAgreeStartPage
import uk.gov.hmrc.ngrraldfrontend.views.html.components.DateTextFields
import uk.gov.hmrc.ngrraldfrontend.views.html.RentDatesAgreeStartView
@@ -37,30 +39,42 @@ class RentDatesAgreeStartControllerSpec extends ControllerSpecSupport {
val pageTitle = "Rent dates"
val view: RentDatesAgreeStartView = inject[RentDatesAgreeStartView]
val mockDateTextFields: DateTextFields = inject[DateTextFields]
- val controller: RentDatesAgreeStartController = new RentDatesAgreeStartController(view, mockAuthJourney, mockPropertyLinkingAction, mockRaldRepo, mcc)(mockConfig, ec)
+ val controllerNoProperty: RentDatesAgreeStartController = new RentDatesAgreeStartController(view, fakeAuth, fakeData(None), mockSessionRepository, mockNavigator, mcc)(mockConfig, ec)
+ val controllerProperty: Option[UserAnswers] => RentDatesAgreeStartController = answers => new RentDatesAgreeStartController(view, fakeAuth, fakeDataProperty(Some(property), answers), mockSessionRepository, mockNavigator, mcc)(mockConfig, ec)
+ val rentDatesAgreeStartAnswers: Option[UserAnswers] = UserAnswers("id").set(RentDatesAgreeStartPage, rentDatesAgreeStartModel).toOption
"Rent Dates Agree Start 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())
+ val result = controllerProperty(None).show(NormalMode)(authenticatedFakeRequest)
status(result) mustBe OK
val content = contentAsString(result)
content must include(pageTitle)
}
+ "Return OK and the correct view with prepopulated data" in {
+ val result = controllerProperty(rentDatesAgreeStartAnswers).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[name=agreedDate.day]").attr("value") mustBe "1"
+ document.select("input[name=agreedDate.month]").attr("value") mustBe "1"
+ document.select("input[name=agreedDate.year]").attr("value") mustBe "2025"
+ document.select("input[name=startPayingDate.day]").attr("value") mustBe "2"
+ document.select("input[name=startPayingDate.month]").attr("value") mustBe "2"
+ document.select("input[name=startPayingDate.year]").attr("value") mustBe "2025"
+ }
"Return NotFoundException when property is not found in the mongo" in {
- mockRequestWithoutProperty()
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(NormalMode)(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
"method submit" must {
"Return SEE_OTHER and redirect WhatRentIncludes view when dates are provided" in {
- when(mockRaldRepo.findByCredId(any())) thenReturn (Future.successful(Some(RaldUserAnswers(credId = CredId(null), NewAgreement, selectedProperty = property))))
- val result = controller.submit(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreedDate.day" -> "30",
"agreedDate.month" -> "4",
@@ -72,11 +86,10 @@ class RentDatesAgreeStartControllerSpec extends ControllerSpecSupport {
.withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some(""))))
headers(result) mustBe TreeMap("Location" -> "/ngr-rald-frontend/what-rent-includes")
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.WhatYourRentIncludesController.show.url)
+ redirectLocation(result) mustBe Some(routes.WhatYourRentIncludesController.show(NormalMode).url)
}
"Return Form with Errors when dates are missing" in {
- mockRequest()
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreedDate.day" -> "",
"agreedDate.month" -> "",
@@ -94,7 +107,7 @@ class RentDatesAgreeStartControllerSpec extends ControllerSpecSupport {
content must include("Enter the date you will start paying rent")
}
"Return Form with Errors when agreed and start paying dates are missing day" in {
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreedDate.day" -> "",
"agreedDate.month" -> "4",
@@ -111,7 +124,7 @@ class RentDatesAgreeStartControllerSpec extends ControllerSpecSupport {
content must include("Date you will start paying rent must include a day")
}
"Return Form with Errors when agreed and start paying dates are missing month" in {
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreedDate.day" -> "30",
"agreedDate.month" -> "",
@@ -128,7 +141,7 @@ class RentDatesAgreeStartControllerSpec extends ControllerSpecSupport {
content must include("Date you will start paying rent must include a month")
}
"Return Form with Errors when agreed and start paying dates are missing year" in {
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreedDate.day" -> "30",
"agreedDate.month" -> "4",
@@ -145,7 +158,7 @@ class RentDatesAgreeStartControllerSpec extends ControllerSpecSupport {
content must include("Date you will start paying rent must include a year")
}
"Return Form with Errors when agreed and start paying dates month is invalid" in {
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreedDate.day" -> "50",
"agreedDate.month" -> "AS",
@@ -162,7 +175,7 @@ class RentDatesAgreeStartControllerSpec extends ControllerSpecSupport {
content must include("Date you will start paying rent must be a real date")
}
"Return Form with Errors when agreed and start paying dates day is invalid" in {
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreedDate.day" -> "30",
"agreedDate.month" -> "2",
@@ -179,7 +192,7 @@ class RentDatesAgreeStartControllerSpec extends ControllerSpecSupport {
content must include("Date you will start paying rent must be a real date")
}
"Return Form with Errors when agreed and start paying dates day is before 1900" in {
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreedDate.day" -> "30",
"agreedDate.month" -> "5",
@@ -196,9 +209,8 @@ class RentDatesAgreeStartControllerSpec extends ControllerSpecSupport {
content must include("Date you will start paying rent must be 1900 or after")
}
"Return Exception if no address is in the mongo" in {
- mockRequestWithoutProperty()
val exception = intercept[NotFoundException] {
- await(controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit)
+ await(controllerNoProperty.submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit(NormalMode))
.withFormUrlEncodedBody(
"agreedDate.day" -> "30",
"agreedDate.month" -> "4",
@@ -209,7 +221,7 @@ class RentDatesAgreeStartControllerSpec extends ControllerSpecSupport {
)
.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
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/RentFreePeriodControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/RentFreePeriodControllerSpec.scala
index d1174e78..b735b2e9 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/RentFreePeriodControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/RentFreePeriodControllerSpec.scala
@@ -26,7 +26,7 @@ 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.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, RaldUserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, NormalMode, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.views.html.RentFreePeriodView
import scala.collection.immutable.TreeMap
@@ -35,30 +35,30 @@ import scala.concurrent.Future
class RentFreePeriodControllerSpec extends ControllerSpecSupport {
val pageTitle = "Rent-free period"
val view: RentFreePeriodView = inject[RentFreePeriodView]
- val controller: RentFreePeriodController = new RentFreePeriodController(view, mockAuthJourney, mockPropertyLinkingAction, mockRaldRepo, mcc)(mockConfig, ec)
+ val controllerNoProperty: RentFreePeriodController = new RentFreePeriodController(view, fakeAuth, fakeData(None), mockSessionRepository, mockNavigator, mcc)(mockConfig, ec)
+ val controllerProperty: Option[UserAnswers] => RentFreePeriodController = answers => new RentFreePeriodController(view, fakeAuth, fakeDataProperty(Some(property), answers), mockSessionRepository, mockNavigator, mcc)(mockConfig, ec)
"Rent free period 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())
+ val result = controllerProperty(None).show(NormalMode)(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()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(NormalMode)(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
"method submit" must {
"Return SEE_OTHER and redirect RentDatesAgreeStart view when everything is provided" in {
- when(mockRaldRepo.findByCredId(any())) thenReturn (Future.successful(Some(RaldUserAnswers(credId = CredId(null), NewAgreement, selectedProperty = property))))
- val result = controller.submit(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit(NormalMode))
.withFormUrlEncodedBody(
"rentFreePeriodMonths" -> "5",
"reasons" -> "Any reasons"
@@ -66,11 +66,10 @@ class RentFreePeriodControllerSpec extends ControllerSpecSupport {
.withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some(""))))
headers(result) mustBe TreeMap("Location" -> "/ngr-rald-frontend/rent-dates-agree-start")
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.RentDatesAgreeStartController.show.url)
+ redirectLocation(result) mustBe Some(routes.RentDatesAgreeStartController.show(NormalMode).url)
}
"Return Form with Errors when rentFreePeriodMonths is missing" in {
- mockRequest()
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit(NormalMode))
.withFormUrlEncodedBody(
"rentFreePeriodMonths" -> "",
"reasons" -> "Any reasons"
@@ -83,7 +82,7 @@ class RentFreePeriodControllerSpec extends ControllerSpecSupport {
content must include("Enter how many months the rent-free period is")
}
"Return Form with Errors when rentFreePeriodMonths isn't numeric" in {
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit(NormalMode))
.withFormUrlEncodedBody(
"rentFreePeriodMonths" -> "$A,",
"reasons" -> "Any reasons"
@@ -95,7 +94,7 @@ class RentFreePeriodControllerSpec extends ControllerSpecSupport {
content must include("Rent-free period must be a number, like 6")
}
"Return Form with Errors when rentFreePeriodMonths is over 999" in {
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit(NormalMode))
.withFormUrlEncodedBody(
"rentFreePeriodMonths" -> "1000",
"reasons" -> "Any reasons"
@@ -107,7 +106,7 @@ class RentFreePeriodControllerSpec extends ControllerSpecSupport {
content must include("Rent-free period must be 99 months or less")
}
"Return Form with Errors when rentFreePeriodMonths is less than 1" in {
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit(NormalMode))
.withFormUrlEncodedBody(
"rentFreePeriodMonths" -> "0",
"reasons" -> "Any reasons"
@@ -119,7 +118,7 @@ class RentFreePeriodControllerSpec extends ControllerSpecSupport {
content must include("Rent-free period must be more more than 0")
}
"Return Form with Errors when reasons is missing" in {
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit(NormalMode))
.withFormUrlEncodedBody(
"rentFreePeriodMonths" -> "5",
"reasons" -> ""
@@ -131,16 +130,16 @@ class RentFreePeriodControllerSpec extends ControllerSpecSupport {
content must include("Tell us why you have a rent-free period")
}
"Return Exception if no address is in the mongo" in {
- mockRequestWithoutProperty()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit)
+ await(controllerNoProperty.submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentDatesAgreeStartController.submit(NormalMode))
.withFormUrlEncodedBody(
"rentFreePeriodMonths" -> "5",
"reasons" -> ""
)
.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
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/RentInterimControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/RentInterimControllerSpec.scala
index 50d05066..eae3b5a1 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/RentInterimControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/RentInterimControllerSpec.scala
@@ -16,72 +16,89 @@
package uk.gov.hmrc.ngrraldfrontend.controllers
+import org.jsoup.Jsoup
+import org.mockito.Mockito.when
+import org.mockito.ArgumentMatchers.any
import play.api.test.FakeRequest
import play.api.http.Status.{BAD_REQUEST, OK, SEE_OTHER}
import play.api.test.Helpers.{await, contentAsString, defaultAwaitTimeout, redirectLocation, status}
import uk.gov.hmrc.http.{HeaderNames, NotFoundException}
import uk.gov.hmrc.ngrraldfrontend.helpers.ControllerSpecSupport
+import uk.gov.hmrc.ngrraldfrontend.models.{NormalMode, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.forms.RentInterimForm
+import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
+import uk.gov.hmrc.ngrraldfrontend.pages.{RentDatesAgreeStartPage, RentInterimPage}
import uk.gov.hmrc.ngrraldfrontend.views.html.RentInterimView
+import scala.concurrent.Future
class RentInterimControllerSpec extends ControllerSpecSupport {
val pageTitle = "Did the court also set an interim rent?"
val view: RentInterimView = inject[RentInterimView]
- val controller: RentInterimController = new RentInterimController(view, mockAuthJourney, mockPropertyLinkingAction, mockRaldRepo, mcc)(mockConfig)
+ val controllerNoProperty: RentInterimController = new RentInterimController(view, fakeAuth, fakeData(None), mockNavigator, mockSessionRepository, mcc)(mockConfig)
+ val controllerProperty: Option[UserAnswers] => RentInterimController = answers => new RentInterimController(view, fakeAuth, fakeDataProperty(Some(property), answers), mockNavigator, mockSessionRepository, mcc)(mockConfig)
+ val rentInterimAnswers: Option[UserAnswers] = UserAnswers("id").set(RentInterimPage, "Yes").toOption
"RentInterimController" must {
"method show" must {
"Return OK and the correct view" in {
- val result = controller.show()(authenticatedFakeRequest())
+ val result = controllerProperty(None).show(NormalMode)(authenticatedFakeRequest)
status(result) mustBe OK
val content = contentAsString(result)
content must include(pageTitle)
}
+ "Return OK and the correct view with prepopulated answers" in {
+ val result = controllerProperty(rentInterimAnswers).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[type=radio][name=rent-interim-radio][value=Yes]").hasAttr("checked") mustBe true
+ document.select("input[type=radio][name=rent-interim-radio][value=No]").hasAttr("checked") mustBe false
+ }
"Return NotFoundException when property is not found in the mongo" in {
- mockRequestWithoutProperty()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(NormalMode)(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
"method submit" must {
"Return OK and the correct view" in {
- val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit(NormalMode))
.withFormUrlEncodedBody((RentInterimForm.agreedRentChangeRadio, "Yes"))
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
- val result = controller.submit()(authenticatedFakeRequest(fakePostRequest))
+ val result = controllerProperty(None).submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.InterimRentSetByTheCourtController.show.url)
+ redirectLocation(result) mustBe Some(routes.InterimRentSetByTheCourtController.show(NormalMode).url)
}
"Return OK and the correct view when no is selected" in {
- val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit(NormalMode))
.withFormUrlEncodedBody((RentInterimForm.agreedRentChangeRadio, "No"))
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
- val result = controller.submit()(authenticatedFakeRequest(fakePostRequest))
+ val result = controllerProperty(None).submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.CheckRentFreePeriodController.show.url)
+ redirectLocation(result) mustBe Some(routes.CheckRentFreePeriodController.show(NormalMode).url)
}
"Return BAD_REQUEST for missing input and the correct view" in {
- mockRequest()
- val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit)
+ val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit(NormalMode))
.withFormUrlEncodedBody((RentInterimForm.agreedRentChangeRadio, ""))
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
- val result = controller.submit()(authenticatedFakeRequest(fakePostRequest))
+ val result = controllerProperty(None).submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
status(result) mustBe BAD_REQUEST
}
"Return Exception if no address is in the mongo" in {
- mockRequestWithoutProperty()
- val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit)
+ val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit(NormalMode))
.withFormUrlEncodedBody((RentInterimForm.agreedRentChangeRadio, ""))
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
val exception = intercept[NotFoundException] {
- await(controller.submit()(authenticatedFakeRequest(fakePostRequest)))
+ await(controllerNoProperty.submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest)))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/RentPeriodsControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/RentPeriodsControllerSpec.scala
index ad950977..1a9154ff 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/RentPeriodsControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/RentPeriodsControllerSpec.scala
@@ -26,7 +26,8 @@ import uk.gov.hmrc.http.HeaderNames
import uk.gov.hmrc.ngrraldfrontend.helpers.ControllerSpecSupport
import uk.gov.hmrc.ngrraldfrontend.models.AgreementType.NewAgreement
import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, ProvideDetailsOfFirstSecondRentPeriod, RaldUserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, NormalMode, ProvideDetailsOfFirstSecondRentPeriod, RaldUserAnswers, UserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.pages.ProvideDetailsOfFirstSecondRentPeriodPage
import uk.gov.hmrc.ngrraldfrontend.views.html.RentPeriodView
import scala.concurrent.Future
@@ -34,46 +35,23 @@ import scala.concurrent.Future
class RentPeriodsControllerSpec extends ControllerSpecSupport {
val pageTitle = "Rent periods"
val view: RentPeriodView = inject[RentPeriodView]
- val controller: RentPeriodsController = new RentPeriodsController(view, mockAuthJourney, mockPropertyLinkingAction, mockRaldRepo, mcc)(mockConfig, ec)
+ val controllerNoProperty: RentPeriodsController = new RentPeriodsController(view, fakeAuth, fakeData(None),mcc, mockSessionRepository, mockNavigator)(mockConfig, ec)
+ val controllerProperty: Option[UserAnswers] => RentPeriodsController = answers => new RentPeriodsController(view, fakeAuth, fakeDataProperty(Some(property), answers), mcc, mockSessionRepository, mockNavigator)(mockConfig, ec)
- "Tell us about your new 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)
- }
- }
+ lazy val firstSecondRentPeriodAnswers: Option[UserAnswers] = UserAnswers("id").set(ProvideDetailsOfFirstSecondRentPeriodPage, firstSecondRentPeriod).toOption
- "method show" must {
- "Return OK and the correct view when the user has said yes to having paid rent for the first period" in {
- when(mockRaldRepo.findByCredId(any())) thenReturn Future.successful(Some(RaldUserAnswers(
- credId = CredId(null),
- agreementType = NewAgreement,
- selectedProperty = property,
- provideDetailsOfFirstSecondRentPeriod =
- Some(ProvideDetailsOfFirstSecondRentPeriod(
- firstDateStart = "2016-12-12",
- firstDateEnd = "2017-12-12",
- firstRentPeriodRadio = true,
- firstRentPeriodAmount = Some("10000"),
- secondDateStart = "2018-12-12",
- secondDateEnd = "2019-12-12",
- secondHowMuchIsRent = "10000")))))
- val result = controller.show()(authenticatedFakeRequest())
- status(result) mustBe OK
- val content = contentAsString(result)
- content must include(pageTitle)
- }
+ "method show" must {
+ "Return OK and the correct view when the user has said yes to having paid rent for the first period" in {
+ val result = controllerProperty(firstSecondRentPeriodAnswers).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ content must include(pageTitle)
}
-
+ }
"method submit" must {
"Return OK and the correct view after submitting yes" 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.RentPeriodsController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentPeriodsController.submit(NormalMode))
.withFormUrlEncodedBody(
"rent-periods-radio" -> "Yes"
)
@@ -82,12 +60,11 @@ class RentPeriodsControllerSpec extends ControllerSpecSupport {
result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord")
})
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.WhatTypeOfAgreementController.show.url)
+ redirectLocation(result) mustBe Some(routes.ProvideDetailsOfFirstSecondRentPeriodController.show(NormalMode).url)
}
"Return OK and the correct view after submitting no" 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.LandlordController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentPeriodsController.submit(NormalMode))
.withFormUrlEncodedBody(
"rent-periods-radio" -> "No"
)
@@ -96,11 +73,10 @@ class RentPeriodsControllerSpec extends ControllerSpecSupport {
result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord")
})
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.WhatTypeOfAgreementController.show.url)
+ redirectLocation(result) mustBe Some(routes.DidYouAgreeRentWithLandlordController.show(NormalMode).url)
}
"Return Form with Errors when no name is input" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit)
+ val result = controllerProperty(firstSecondRentPeriodAnswers).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.RentPeriodsController.submit(NormalMode))
.withFormUrlEncodedBody(
"rent-periods-radio" -> ""
)
@@ -114,5 +90,3 @@ class RentPeriodsControllerSpec extends ControllerSpecSupport {
}
}
}
-}
-
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutYourNewAgreementControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutYourNewAgreementControllerSpec.scala
index fb02853d..b08b3048 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutYourNewAgreementControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutYourNewAgreementControllerSpec.scala
@@ -17,13 +17,15 @@
package uk.gov.hmrc.ngrraldfrontend.controllers
import org.mockito.Mockito.when
+import org.mockito.ArgumentMatchers.any
import org.scalatest.matchers.should.Matchers.shouldBe
import play.api.http.Status.{OK, SEE_OTHER}
import play.api.test.Helpers.{await, contentAsString, defaultAwaitTimeout, redirectLocation, status}
import uk.gov.hmrc.http.NotFoundException
import uk.gov.hmrc.ngrraldfrontend.helpers.ControllerSpecSupport
import uk.gov.hmrc.ngrraldfrontend.models.AgreementType.NewAgreement
-import uk.gov.hmrc.ngrraldfrontend.models.RaldUserAnswers
+import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
+import uk.gov.hmrc.ngrraldfrontend.models.{NormalMode, RaldUserAnswers, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.views.html.TellUsAboutYourAgreementView
import scala.concurrent.Future
@@ -31,35 +33,31 @@ import scala.concurrent.Future
class TellUsAboutYourNewAgreementControllerSpec extends ControllerSpecSupport {
val pageTitle = "Tell us about your new agreement"
val view: TellUsAboutYourAgreementView = inject[TellUsAboutYourAgreementView]
- val controller: TellUsAboutYourNewAgreementController = new TellUsAboutYourNewAgreementController(view, mockAuthJourney, mockPropertyLinkingAction, mockRaldRepo, mcc)(mockConfig)
+ val controllerNoProperty: TellUsAboutYourNewAgreementController = new TellUsAboutYourNewAgreementController(view, fakeAuth, mcc, fakeData(None), mockSessionRepository, mockNavigator)(mockConfig)
+ val controllerProperty: Option[UserAnswers] => TellUsAboutYourNewAgreementController = answers => new TellUsAboutYourNewAgreementController(view, fakeAuth, mcc, fakeDataProperty(Some(property),answers), mockSessionRepository, mockNavigator)(mockConfig)
"Tell us about your new agreement controller" must {
"method show" must {
"Return OK and the correct view" in {
- val result = controller.show()(authenticatedFakeRequest())
+ val result = controllerProperty(None).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()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
"method submit" must {
"Return OK and the correct view" in {
- val result = controller.submit()(authenticatedFakeRequest())
- when(mockRaldRepo.upsertRaldUserAnswers(
- raldUserAnswers = RaldUserAnswers(credId,
- NewAgreement,
- property,
- None)
- )).thenReturn(Future.successful(true))
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(authenticatedFakeRequest)
status(result) mustBe SEE_OTHER
- redirectLocation(result) shouldBe Some(routes.LandlordController.show.url)
+ redirectLocation(result) shouldBe Some(routes.LandlordController.show(NormalMode).url)
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutYourRenewedAgreementControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutYourRenewedAgreementControllerSpec.scala
index d78fdf88..88766dcf 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutYourRenewedAgreementControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutYourRenewedAgreementControllerSpec.scala
@@ -16,40 +16,48 @@
package uk.gov.hmrc.ngrraldfrontend.controllers
+import org.mockito.ArgumentMatchers.any
+import org.mockito.Mockito.when
import org.scalatest.matchers.should.Matchers.shouldBe
import play.api.http.Status.{OK, SEE_OTHER}
import play.api.test.Helpers.{await, contentAsString, defaultAwaitTimeout, redirectLocation, status}
import uk.gov.hmrc.http.NotFoundException
import uk.gov.hmrc.ngrraldfrontend.helpers.ControllerSpecSupport
+import uk.gov.hmrc.ngrraldfrontend.models.NormalMode
+import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
import uk.gov.hmrc.ngrraldfrontend.views.html.TellUsAboutYourAgreementView
+import scala.concurrent.Future
+
class TellUsAboutYourRenewedAgreementControllerSpec extends ControllerSpecSupport {
val pageTitle = "Tell us about your renewed agreement"
val view: TellUsAboutYourAgreementView = inject[TellUsAboutYourAgreementView]
- val controller: TellUsAboutYourRenewedAgreementController = new TellUsAboutYourRenewedAgreementController(view, mockAuthJourney, mockPropertyLinkingAction, mockRaldRepo, mcc)(mockConfig)
+ val controllerNoProperty: TellUsAboutYourRenewedAgreementController = new TellUsAboutYourRenewedAgreementController(view, fakeAuth, mcc, fakeData(None), mockSessionRepository, mockNavigator)(mockConfig)
+ val controllerProperty: TellUsAboutYourRenewedAgreementController = new TellUsAboutYourRenewedAgreementController(view, fakeAuth, mcc, fakeDataProperty(Some(property), None), mockSessionRepository, mockNavigator)(mockConfig)
"Tell us about your new agreement controller" must {
"method show" must {
"Return OK and the correct view" in {
- val result = controller.show()(authenticatedFakeRequest())
+ val result = controllerProperty.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()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
"method submit" must {
"Return OK and the correct view" in {
- val result = controller.submit()(authenticatedFakeRequest())
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty.submit()(authenticatedFakeRequest)
status(result) mustBe SEE_OTHER
- redirectLocation(result) shouldBe Some(routes.WhatTypeOfLeaseRenewalController.show.url)
+ redirectLocation(result) shouldBe Some(routes.WhatTypeOfLeaseRenewalController.show(NormalMode).url)
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutYourRentControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutYourRentControllerSpec.scala
index 4f9acf4c..bb881a76 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutYourRentControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/TellUsAboutYourRentControllerSpec.scala
@@ -17,38 +17,46 @@
package uk.gov.hmrc.ngrraldfrontend.controllers
import org.scalatest.matchers.should.Matchers.shouldBe
+import org.mockito.ArgumentMatchers.any
+import org.mockito.Mockito.when
import play.api.http.Status.{OK, SEE_OTHER}
import play.api.test.Helpers.{await, contentAsString, defaultAwaitTimeout, redirectLocation, status}
import uk.gov.hmrc.http.NotFoundException
import uk.gov.hmrc.ngrraldfrontend.helpers.ControllerSpecSupport
+import uk.gov.hmrc.ngrraldfrontend.models.NormalMode
+import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
import uk.gov.hmrc.ngrraldfrontend.views.html.TellUsAboutYourAgreementView
+import scala.concurrent.Future
+
class TellUsAboutYourRentControllerSpec extends ControllerSpecSupport {
val pageTitle = "Tell us about your rent review"
val view: TellUsAboutYourAgreementView = inject[TellUsAboutYourAgreementView]
- val controller: TellUsAboutRentController = new TellUsAboutRentController(view, mockAuthJourney, mockPropertyLinkingAction, mockRaldRepo, mcc)(mockConfig)
+ val controllerProperty: TellUsAboutRentController = new TellUsAboutRentController(view, fakeAuth, mockNavigator, mcc, fakeDataProperty(Some(property),None), mockSessionRepository)(mockConfig)
+ val controllerNoProperty: TellUsAboutRentController = new TellUsAboutRentController(view, fakeAuth, mockNavigator, mcc, fakeData(None), mockSessionRepository)(mockConfig)
"Tell us about your rent controller" must {
"method show" must {
"Return OK and the correct view" in {
- val result = controller.show()(authenticatedFakeRequest())
+ val result = controllerProperty.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()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show()(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
"method submit" must {
"Return OK and the correct view" in {
- val result = controller.submit()(authenticatedFakeRequest())
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty.submit()(authenticatedFakeRequest)
status(result) mustBe SEE_OTHER
- redirectLocation(result) shouldBe Some(routes.LandlordController.show.url)
+ redirectLocation(result) shouldBe Some(routes.LandlordController.show(NormalMode).url)
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/WhatIsYourRentBasedOnControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/WhatIsYourRentBasedOnControllerSpec.scala
index 8b02cdf4..7b6c6855 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/WhatIsYourRentBasedOnControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/WhatIsYourRentBasedOnControllerSpec.scala
@@ -16,6 +16,7 @@
package uk.gov.hmrc.ngrraldfrontend.controllers
+import org.jsoup.Jsoup
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.when
import play.api.http.Status.{BAD_REQUEST, OK, SEE_OTHER}
@@ -26,7 +27,8 @@ 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.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, RaldUserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, NormalMode, RaldUserAnswers, UserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.pages.WhatIsYourRentBasedOnPage
import uk.gov.hmrc.ngrraldfrontend.views.html.WhatIsYourRentBasedOnView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.NGRCharacterCountComponent
@@ -37,41 +39,50 @@ class WhatIsYourRentBasedOnControllerSpec extends ControllerSpecSupport {
val pageTitle = "What is your rent based on?"
val view: WhatIsYourRentBasedOnView = inject[WhatIsYourRentBasedOnView]
val mockNGRCharacterCountComponent: NGRCharacterCountComponent = inject[NGRCharacterCountComponent]
- val controller: WhatIsYourRentBasedOnController = new WhatIsYourRentBasedOnController(view, mockAuthJourney, mockPropertyLinkingAction, mockRaldRepo, mockNGRCharacterCountComponent, mcc)(mockConfig, ec)
+ val controllerProperty: Option[UserAnswers] => WhatIsYourRentBasedOnController = answers => new WhatIsYourRentBasedOnController(view, fakeAuth, mockNGRCharacterCountComponent, mcc, fakeDataProperty(Some(property),answers), mockNavigator, mockSessionRepository)(mockConfig, ec)
+ val controllerNoProperty: WhatIsYourRentBasedOnController = new WhatIsYourRentBasedOnController(view, fakeAuth, mockNGRCharacterCountComponent, mcc, fakeData(None), mockNavigator, mockSessionRepository)(mockConfig, ec)
+ val whatIsYourRentBasedOnAnswers: Option[UserAnswers] = UserAnswers("id").set(WhatIsYourRentBasedOnPage, rentBasedOnModel).toOption
"What is your rent based on 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())
+ val result = controllerProperty(None).show(NormalMode)(authenticatedFakeRequest)
status(result) mustBe OK
val content = contentAsString(result)
content must include(pageTitle)
}
+ "Return OK and the correct view with prepopulated data" in {
+ val result = controllerProperty(whatIsYourRentBasedOnAnswers).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[type=radio][name=rent-based-on-radio][value=Other]").hasAttr("checked") mustBe true
+ document.select("textarea[name=rent-based-on-other-desc]").text() mustBe "The rent was agreed"
+
+ }
"Return NotFoundException when property is not found in the mongo" in {
- mockRequestWithoutProperty()
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(NormalMode)(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
"method submit" must {
"Return SEE_OTHER and redirect HowMuchIsTotalAnnualRent view when radio button selected PercentageTurnover" in {
- when(mockRaldRepo.findByCredId(any())) thenReturn (Future.successful(Some(RaldUserAnswers(credId = CredId(null), NewAgreement, selectedProperty = property))))
- val result = controller.submit(AuthenticatedUserRequest(FakeRequest(routes.WhatIsYourRentBasedOnController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.WhatIsYourRentBasedOnController.submit(NormalMode))
.withFormUrlEncodedBody(
"rent-based-on-radio" -> "PercentageTurnover"
)
.withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some(""))))
headers(result) mustBe TreeMap("Location" -> "/ngr-rald-frontend/how-much-is-total-annual-rent")
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.HowMuchIsTotalAnnualRentController.show.url)
+ redirectLocation(result) mustBe Some(routes.HowMuchIsTotalAnnualRentController.show(NormalMode).url)
}
"Return SEE_OTHER and the correct view when radio button selected Other and description has been entered" in {
- when(mockRaldRepo.findByCredId(any())) thenReturn (Future.successful(Some(RaldUserAnswers(credId = CredId(null), NewAgreement, selectedProperty = property))))
- val result = controller.submit(AuthenticatedUserRequest(FakeRequest(routes.WhatIsYourRentBasedOnController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.WhatIsYourRentBasedOnController.submit(NormalMode))
.withFormUrlEncodedBody(
"rent-based-on-radio" -> "Other",
"rent-based-on-other-desc" -> "The rent was agreed"
@@ -79,11 +90,10 @@ class WhatIsYourRentBasedOnControllerSpec extends ControllerSpecSupport {
.withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some(""))))
headers(result) mustBe TreeMap("Location" -> "/ngr-rald-frontend/have-you-agreed-rent-changes-with-landlord")
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.AgreedRentChangeController.show.url)
+ redirectLocation(result) mustBe Some(routes.AgreedRentChangeController.show(NormalMode).url)
}
"Return Form with Errors when no radio button is selected" in {
- mockRequest()
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.WhatIsYourRentBasedOnController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.WhatIsYourRentBasedOnController.submit(NormalMode))
.withFormUrlEncodedBody(
"rent-based-on-radio" -> ""
)
@@ -95,7 +105,7 @@ class WhatIsYourRentBasedOnControllerSpec extends ControllerSpecSupport {
content must include("Select what your rent is based on")
}
"Return Form with Errors when radio button Other is selected but no other description is given" in {
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.WhatIsYourRentBasedOnController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.WhatIsYourRentBasedOnController.submit(NormalMode))
.withFormUrlEncodedBody(
"rent-based-on-radio" -> "Other",
"rent-based-on-other-desc" -> ""
@@ -108,7 +118,7 @@ class WhatIsYourRentBasedOnControllerSpec extends ControllerSpecSupport {
}
"Return Form with Errors when radio button Other is selected but other description is over 250 characters" in {
val over250Characters = "Bug Me Not PVT LTD, RODLEY LANE, RODLEY, LEEDS, BH1 1HU What is your rent based on?Open market value This is the rent a landlord could rent the property for if, it was available to anyoneA percentage of open market value This is a percentage of the rent a landlord could rent the property for if, it was available to anyoneTurnover top-up The rent is a fixed base rent with an additional payment based on a percentage of your turnoverA percentage of expected turnover The rent paid is based on a percentage of turnoverTotal Occupancy Cost leases (TOCs)The rent is the total cost of leasing the property. It includes base rent, business rates, insurance and utilities. It also includes common area maintenance and tenant improvements Indexation The rent is reviewed according to an index (such as Retail Price Index)Other The rent was agreed another way Can you tell us how your rent was agreed?"
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.WhatIsYourRentBasedOnController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.WhatIsYourRentBasedOnController.submit(NormalMode))
.withFormUrlEncodedBody(
"rent-based-on-radio" -> "Other",
"rent-based-on-other-desc" -> over250Characters
@@ -120,13 +130,12 @@ class WhatIsYourRentBasedOnControllerSpec extends ControllerSpecSupport {
content must include("Maximum character allowed is 250")
}
"Return Exception if no address is in the mongo" in {
- mockRequestWithoutProperty()
val exception = intercept[NotFoundException] {
- await(controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.WhatIsYourRentBasedOnController.submit)
+ await(controllerNoProperty.submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.WhatIsYourRentBasedOnController.submit(NormalMode))
.withFormUrlEncodedBody(("rent-based-on-radio" -> "Other"))
.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
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/WhatTypeOfAgreementControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/WhatTypeOfAgreementControllerSpec.scala
index 575feb9d..dea9cad2 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/WhatTypeOfAgreementControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/WhatTypeOfAgreementControllerSpec.scala
@@ -16,6 +16,7 @@
package uk.gov.hmrc.ngrraldfrontend.controllers
+import org.jsoup.Jsoup
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.when
import org.scalatest.matchers.should.Matchers.shouldBe
@@ -27,7 +28,8 @@ 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.registration.CredId
-import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, RaldUserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, NormalMode, RaldUserAnswers, UserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.pages.WhatTypeOfAgreementPage
import uk.gov.hmrc.ngrraldfrontend.views.html.WhatTypeOfAgreementView
import scala.concurrent.Future
@@ -35,54 +37,62 @@ import scala.concurrent.Future
class WhatTypeOfAgreementControllerSpec extends ControllerSpecSupport {
val pageTitle = "What type of agreement do you have?"
val view: WhatTypeOfAgreementView = inject[WhatTypeOfAgreementView]
- val controller: WhatTypeOfAgreementController = new WhatTypeOfAgreementController(view, mockAuthJourney, mockPropertyLinkingAction, mockRaldRepo, mcc)(mockConfig, ec)
+ val controllerProperty: Option[UserAnswers] => WhatTypeOfAgreementController = answers => new WhatTypeOfAgreementController(view, fakeAuth, mcc, fakeDataProperty(Some(property),answers), mockNavigator, mockSessionRepository)(mockConfig, ec)
+ val controllerNoProperty: WhatTypeOfAgreementController = new WhatTypeOfAgreementController(view, fakeAuth, mcc, fakeData(None), mockNavigator, mockSessionRepository)(mockConfig, ec)
+ val whatTypeOfAgreementAnswers: Option[UserAnswers] = UserAnswers("id").set(WhatTypeOfAgreementPage, "Verbal").toOption
+
+
"Tell us about your new 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())
+ val result = controllerProperty(None).show(NormalMode)(authenticatedFakeRequest)
status(result) mustBe OK
val content = contentAsString(result)
content must include(pageTitle)
}
+ "Return OK and the correct view with prepopulated answers for Verbal" in {
+ val result = controllerProperty(whatTypeOfAgreementAnswers).show(NormalMode)(authenticatedFakeRequest)
+ status(result)
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[type=radio][name=what-type-of-agreement-radio][value=Verbal]").hasAttr("checked") mustBe true
+ document.select("input[type=radio][name=what-type-of-agreement-radio][value=Written]").hasAttr("checked") mustBe false
+ document.select("input[type=radio][name=what-type-of-agreement-radio][value=LeaseOrTenancy]").hasAttr("checked") mustBe false
+ }
"Return NotFoundException when property is not found in the mongo" in {
- mockRequestWithoutProperty()
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(NormalMode)(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
"method submit" must {
"Return OK and the correct view after submitting with written radio button" 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.WhatTypeOfAgreementController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.WhatTypeOfAgreementController.submit(NormalMode))
.withFormUrlEncodedBody(("what-type-of-agreement-radio", "Written"))
.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") shouldBe Some("/ngr-rald-frontend/what-type-of-agreement-do-you-have ")
})
status(result) mustBe SEE_OTHER
- redirectLocation(result) shouldBe Some(routes.AgreementController.show.url)
+ redirectLocation(result) shouldBe Some(routes.AgreementController.show(NormalMode).url)
}
"Return OK and the correct view after submitting with verbal radio button" 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.WhatTypeOfAgreementController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.WhatTypeOfAgreementController.submit(NormalMode))
.withFormUrlEncodedBody(("what-type-of-agreement-radio", "Verbal"))
.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") shouldBe Some("/ngr-rald-frontend/agreement-verbal")
})
status(result) mustBe SEE_OTHER
- redirectLocation(result) shouldBe Some(routes.AgreementVerbalController.show.url)
+ redirectLocation(result) shouldBe Some(routes.AgreementVerbalController.show(NormalMode).url)
}
"Return Form with Errors when no radio button is selected" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.WhatTypeOfAgreementController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.WhatTypeOfAgreementController.submit(NormalMode))
.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(""))))
result.map(result => {
@@ -93,13 +103,12 @@ class WhatTypeOfAgreementControllerSpec extends ControllerSpecSupport {
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.WhatTypeOfAgreementController.submit)
+ await(controllerNoProperty.submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.WhatTypeOfAgreementController.submit(NormalMode))
.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
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/WhatTypeOfLeaseRenewalControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/WhatTypeOfLeaseRenewalControllerSpec.scala
index 3a9c4e24..5b00bec1 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/WhatTypeOfLeaseRenewalControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/WhatTypeOfLeaseRenewalControllerSpec.scala
@@ -16,64 +16,101 @@
package uk.gov.hmrc.ngrraldfrontend.controllers
+import org.jsoup.Jsoup
+import org.mockito.ArgumentMatchers.any
+import org.mockito.Mockito.when
import play.api.http.Status.{BAD_REQUEST, OK, SEE_OTHER}
import play.api.test.FakeRequest
import play.api.test.Helpers.{await, contentAsString, defaultAwaitTimeout, redirectLocation, status}
import uk.gov.hmrc.http.{HeaderNames, NotFoundException}
import uk.gov.hmrc.ngrraldfrontend.helpers.ControllerSpecSupport
+import uk.gov.hmrc.ngrraldfrontend.models.{NormalMode, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.forms.WhatTypeOfLeaseRenewalForm
+import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
+import uk.gov.hmrc.ngrraldfrontend.pages.WhatTypeOfLeaseRenewalPage
+import uk.gov.hmrc.ngrraldfrontend.utils.Constants
import uk.gov.hmrc.ngrraldfrontend.views.html.WhatTypeOfLeaseRenewalView
+import scala.concurrent.Future
+
class WhatTypeOfLeaseRenewalControllerSpec extends ControllerSpecSupport {
val pageTitle = "What type of lease renewal is it?"
val view: WhatTypeOfLeaseRenewalView = inject[WhatTypeOfLeaseRenewalView]
- val controller: WhatTypeOfLeaseRenewalController = new WhatTypeOfLeaseRenewalController(view, mockAuthJourney, mockPropertyLinkingAction, mockRaldRepo, mcc)(mockConfig)
+ val controllerNoProperty: WhatTypeOfLeaseRenewalController = new WhatTypeOfLeaseRenewalController(view, fakeAuth, fakeData(None),mockSessionRepository,mockNavigator, mcc)(mockConfig)
+ val controllerProperty: Option[UserAnswers] => WhatTypeOfLeaseRenewalController = answers => new WhatTypeOfLeaseRenewalController(view, fakeAuth, fakeDataProperty(Some(property),answers),mockSessionRepository,mockNavigator, mcc)(mockConfig)
+ val renewedAgreementAnswers: Option[UserAnswers] = UserAnswers("id").set(WhatTypeOfLeaseRenewalPage, Constants.renewedAgreement).toOption
+ val surrenderAndRenewalAnswers: Option[UserAnswers] = UserAnswers("id").set(WhatTypeOfLeaseRenewalPage, Constants.surrenderAndRenewal).toOption
"TypeOfLeaseRenewalController" must {
"method show" must {
"Return OK and the correct view" in {
- val result = controller.show()(authenticatedFakeRequest())
+ val result = controllerProperty(None).show(NormalMode)(authenticatedFakeRequest)
status(result) mustBe OK
val content = contentAsString(result)
content must include(pageTitle)
}
+ "Return OK and the correct view with prepopulated data for a Renewed Agreement" in {
+ val result = controllerProperty(renewedAgreementAnswers).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[type=radio][name=type-of-renewal][value=RenewedAgreement]").hasAttr("checked") mustBe true
+ document.select("input[type=radio][name=type-of-renewal][value=SurrenderAndRenewal]").hasAttr("checked") mustBe false
+ }
+ "Return OK and the correct view with prepopulated data for a Surrender And Renewal" in {
+ val result = controllerProperty(surrenderAndRenewalAnswers).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[type=radio][name=type-of-renewal][value=RenewedAgreement]").hasAttr("checked") mustBe false
+ document.select("input[type=radio][name=type-of-renewal][value=SurrenderAndRenewal]").hasAttr("checked") mustBe true
+ }
"Return NotFoundException when property is not found in the mongo" in {
- mockRequestWithoutProperty()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(NormalMode)(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
"method submit" must {
- "Return OK and the correct view" in {
- val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit)
+ "Return OK and the correct view for Renewed Agreement" in {
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit(NormalMode))
.withFormUrlEncodedBody((WhatTypeOfLeaseRenewalForm.formName, "RenewedAgreement"))
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
-
- val result = controller.submit()(authenticatedFakeRequest(fakePostRequest))
+
+ val result = controllerProperty(None).submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
+ status(result) mustBe SEE_OTHER
+ redirectLocation(result) mustBe Some(routes.LandlordController.show(NormalMode).url)
+ }
+ "Return OK and the correct view for " in {
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit(NormalMode))
+ .withFormUrlEncodedBody((WhatTypeOfLeaseRenewalForm.formName, "SurrenderAndRenewal"))
+ .withHeaders(HeaderNames.authorisation -> "Bearer 1")
+
+ val result = controllerProperty(None).submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.LandlordController.show.url)
+ redirectLocation(result) mustBe Some(routes.LandlordController.show(NormalMode).url)
}
"Return BAD_REQUEST for missing input and the correct view" in {
- mockRequest()
- val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit)
+ val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit(NormalMode))
.withFormUrlEncodedBody((WhatTypeOfLeaseRenewalForm.formName, ""))
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
- val result = controller.submit()(authenticatedFakeRequest(fakePostRequest))
+ val result = controllerProperty(None).submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest))
status(result) mustBe BAD_REQUEST
}
"Return Exception if no address is in the mongo" in {
- mockRequestWithoutProperty()
- val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit)
+ val fakePostRequest = FakeRequest(routes.WhatTypeOfLeaseRenewalController.submit((NormalMode)))
.withFormUrlEncodedBody((WhatTypeOfLeaseRenewalForm.formName, ""))
.withHeaders(HeaderNames.authorisation -> "Bearer 1")
val exception = intercept[NotFoundException] {
- await(controller.submit()(authenticatedFakeRequest(fakePostRequest)))
+ await(controllerNoProperty.submit(NormalMode)(authenticatedFakePostRequest(fakePostRequest)))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/WhatYourRentIncludesControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/WhatYourRentIncludesControllerSpec.scala
index 11f49732..415a191b 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/WhatYourRentIncludesControllerSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/WhatYourRentIncludesControllerSpec.scala
@@ -16,6 +16,7 @@
package uk.gov.hmrc.ngrraldfrontend.controllers
+import org.jsoup.Jsoup
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.when
import play.api.http.Status.{BAD_REQUEST, OK, SEE_OTHER}
@@ -25,8 +26,9 @@ 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.{AuthenticatedUserRequest, NormalMode, RaldUserAnswers, UserAnswers}
import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
+import uk.gov.hmrc.ngrraldfrontend.pages.WhatYourRentIncludesPage
import uk.gov.hmrc.ngrraldfrontend.views.html.WhatYourRentIncludesView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.NGRCharacterCountComponent
@@ -36,37 +38,70 @@ class WhatYourRentIncludesControllerSpec extends ControllerSpecSupport {
val pageTitle = "What your rent includes"
val view: WhatYourRentIncludesView = inject[ WhatYourRentIncludesView]
val mockNGRCharacterCountComponent: NGRCharacterCountComponent = inject[NGRCharacterCountComponent]
- val controller:WhatYourRentIncludesController = new WhatYourRentIncludesController(
+ val controllerNoProperty :WhatYourRentIncludesController = new WhatYourRentIncludesController(
view,
- mockAuthJourney,
+ fakeAuth,
mockInputText,
- mockPropertyLinkingAction,
- mockRaldRepo,
+ fakeData(None),
+ mockSessionRepository,
+ mockNavigator,
mcc)(mockConfig, ec)
+ val controllerProperty: Option[UserAnswers] => WhatYourRentIncludesController = answers => new WhatYourRentIncludesController(
+ view,
+ fakeAuth,
+ mockInputText,
+ fakeDataProperty(Some(property), answers),
+ mockSessionRepository,
+ mockNavigator,
+ mcc)(mockConfig, ec)
+ val whatYourRentIncludesAnswersAllYes: Option[UserAnswers] = UserAnswers("id").set(WhatYourRentIncludesPage, whatYourRentIncludesModelAllYes).toOption
+ val whatYourRentIncludesAnswersAllNo: Option[UserAnswers] = UserAnswers("id").set(WhatYourRentIncludesPage, whatYourRentIncludesModelAllNo).toOption
"Tell us about what your rent includes 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())
+ val result = controllerProperty(None).show(NormalMode)(authenticatedFakeRequest)
status(result) mustBe OK
val content = contentAsString(result)
content must include(pageTitle)
}
+ "Return OK and the correct view with prepopulated answers all Yes" in {
+ val result = controllerProperty(whatYourRentIncludesAnswersAllYes).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[type=radio][name=livingAccommodationRadio][value=livingAccommodationYes]").hasAttr("checked") mustBe true
+ document.select("input[type=radio][name=rentPartAddressRadio][value=rentPartAddressYes]").hasAttr("checked") mustBe true
+ document.select("input[type=radio][name=rentEmptyShellRadio][value=rentEmptyShellYes]").hasAttr("checked") mustBe true
+ document.select("input[type=radio][name=rentIncBusinessRatesRadio][value=rentIncBusinessRatesYes]").hasAttr("checked") mustBe true
+ document.select("input[type=radio][name=rentIncWaterChargesRadio][value=rentIncWaterChargesYes]").hasAttr("checked") mustBe true
+ document.select("input[type=radio][name=rentIncServiceRadio][value=rentIncServiceYes]").hasAttr("checked") mustBe true
+ }
+ "Return OK and the correct view with prepopulated answers all No" in {
+ val result = controllerProperty(whatYourRentIncludesAnswersAllNo).show(NormalMode)(authenticatedFakeRequest)
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ val document = Jsoup.parse(content)
+ document.select("input[type=radio][name=livingAccommodationRadio][value=livingAccommodationNo]").hasAttr("checked") mustBe true
+ document.select("input[type=radio][name=rentPartAddressRadio][value=rentPartAddressNo]").hasAttr("checked") mustBe true
+ document.select("input[type=radio][name=rentEmptyShellRadio][value=rentEmptyShellNo]").hasAttr("checked") mustBe true
+ document.select("input[type=radio][name=rentIncBusinessRatesRadio][value=rentIncBusinessRatesNo]").hasAttr("checked") mustBe true
+ document.select("input[type=radio][name=rentIncWaterChargesRadio][value=rentIncWaterChargesNo]").hasAttr("checked") mustBe true
+ document.select("input[type=radio][name=rentIncServiceRadio][value=rentIncServiceNo]").hasAttr("checked") mustBe true
+ }
"Return NotFoundException when property is not found in the mongo" in {
- mockRequestWithoutProperty()
+ when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None))
val exception = intercept[NotFoundException] {
- await(controller.show(authenticatedFakeRequest()))
+ await(controllerNoProperty.show(NormalMode)(authenticatedFakeRequest))
}
- exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
"method submit" must {
"Return OK and the correct view after submitting with all radio buttons selected" 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.WhatYourRentIncludesController.submit)
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.WhatYourRentIncludesController.submit(NormalMode))
.withFormUrlEncodedBody(
"livingAccommodationRadio" -> "livingAccommodationYes",
"rentPartAddressRadio" -> "No",
@@ -81,11 +116,28 @@ class WhatYourRentIncludesControllerSpec extends ControllerSpecSupport {
result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/does-rent-include-parking-spaces-or-garages")
})
status(result) mustBe SEE_OTHER
- redirectLocation(result) mustBe Some(routes.DoesYourRentIncludeParkingController.show.url)
+ redirectLocation(result) mustBe Some(routes.DoesYourRentIncludeParkingController.show(NormalMode).url)
+ }
+ "Return OK and the correct view after submitting with all radio buttons selected but no bedrooms" in {
+ when(mockSessionRepository.set(any())).thenReturn(Future.successful(true))
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.WhatYourRentIncludesController.submit(NormalMode))
+ .withFormUrlEncodedBody(
+ "livingAccommodationRadio" -> "livingAccommodationNo",
+ "rentPartAddressRadio" -> "Yes",
+ "rentEmptyShellRadio" -> "No",
+ "rentIncBusinessRatesRadio" -> "Yes",
+ "rentIncWaterChargesRadio" -> "Yes",
+ "rentIncServiceRadio" -> "No"
+ )
+ .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/does-rent-include-parking-spaces-or-garages")
+ })
+ status(result) mustBe SEE_OTHER
+ redirectLocation(result) mustBe Some(routes.DoesYourRentIncludeParkingController.show(NormalMode).url)
}
"Return Form with Errors when no radio button is selected" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.WhatYourRentIncludesController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.WhatYourRentIncludesController.submit(NormalMode))
.withFormUrlEncodedBody(
"livingAccommodationRadio" -> "",
"rentPartAddressRadio" -> "No",
@@ -104,8 +156,7 @@ class WhatYourRentIncludesControllerSpec extends ControllerSpecSupport {
content must include("Select yes if your rent includes any living accommodation")
}
"Return Form with Errors when bedroom numbers is not provide" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.WhatYourRentIncludesController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.WhatYourRentIncludesController.submit(NormalMode))
.withFormUrlEncodedBody(
"livingAccommodationRadio" -> "livingAccommodationYes",
"rentPartAddressRadio" -> "No",
@@ -125,8 +176,7 @@ class WhatYourRentIncludesControllerSpec extends ControllerSpecSupport {
content must include("Enter how many bedrooms the living accommodation has")
}
"Return Form with Errors when bedroom numbers is not numeric" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.WhatYourRentIncludesController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.WhatYourRentIncludesController.submit(NormalMode))
.withFormUrlEncodedBody(
"livingAccommodationRadio" -> "livingAccommodationYes",
"rentPartAddressRadio" -> "No",
@@ -146,8 +196,7 @@ class WhatYourRentIncludesControllerSpec extends ControllerSpecSupport {
content must include("How many bedrooms must be a number, like 6")
}
"Return Form with Errors when bedroom numbers is less than 1" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.WhatYourRentIncludesController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.WhatYourRentIncludesController.submit(NormalMode))
.withFormUrlEncodedBody(
"livingAccommodationRadio" -> "livingAccommodationYes",
"rentPartAddressRadio" -> "No",
@@ -167,8 +216,7 @@ class WhatYourRentIncludesControllerSpec extends ControllerSpecSupport {
content must include("How many bedrooms must be 1 or more")
}
"Return Form with Errors when bedroom numbers is greater than 99" in {
- mockRequest(hasCredId = true)
- val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.WhatYourRentIncludesController.submit)
+ val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.WhatYourRentIncludesController.submit(NormalMode))
.withFormUrlEncodedBody(
"livingAccommodationRadio" -> "livingAccommodationYes",
"rentPartAddressRadio" -> "No",
@@ -188,13 +236,13 @@ class WhatYourRentIncludesControllerSpec extends ControllerSpecSupport {
content must include("How many bedrooms must be 99 or less")
}
"Return Exception if no address is in the mongo" in {
- mockRequestWithoutProperty()
+
val exception = intercept[NotFoundException] {
- await(controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.WhatYourRentIncludesController.submit)
+ await(controllerNoProperty.submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.WhatYourRentIncludesController.submit(NormalMode))
.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
+ exception.getMessage contains "Could not find answers in backend mongo" mustBe true
}
}
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/helpers/ControllerSpecSupport.scala b/test/uk/gov/hmrc/ngrraldfrontend/helpers/ControllerSpecSupport.scala
index f87baa70..be981f7f 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/helpers/ControllerSpecSupport.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/helpers/ControllerSpecSupport.scala
@@ -20,64 +20,73 @@ import org.mockito.Mockito.when
import play.api.mvc.*
import uk.gov.hmrc.auth.core.Nino
import uk.gov.hmrc.http.HeaderCarrier
-import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalActionSpec, FakeAuthenticatedRequest, FakeDataRetrievalAction}
import uk.gov.hmrc.ngrraldfrontend.connectors.NGRConnector
import uk.gov.hmrc.ngrraldfrontend.models.AuthenticatedUserRequest
+import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository
+import uk.gov.hmrc.ngrraldfrontend.models.UserAnswers
+import uk.gov.hmrc.ngrraldfrontend.models.requests.OptionalDataRequest
+import uk.gov.hmrc.ngrraldfrontend.models.vmvProperty.VMVProperty
+import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator
import uk.gov.hmrc.ngrraldfrontend.views.html.components.InputText
import scala.concurrent.{ExecutionContext, Future}
trait ControllerSpecSupport extends TestSupport {
- val mockPropertyLinkingAction: PropertyLinkingAction = mock[PropertyLinkingAction]
+ val mockGetData: DataRetrievalActionSpec = mock[DataRetrievalActionSpec]
val mockAuthJourney: AuthRetrievals = mock[AuthRetrievals]
+ val mockSessionRepository: SessionRepository = mock[SessionRepository]
+ def fakeData(answers: Option[UserAnswers]) = new FakeDataRetrievalAction(answers, None)
+ def fakeDataProperty(property: Option[VMVProperty], answers: Option[UserAnswers]) = new FakeDataRetrievalAction(answers, property)
+ val mockNavigator: Navigator = inject[Navigator]
val mockInputText: InputText = inject[InputText]
val mockNgrConnector: NGRConnector = mock[NGRConnector]
implicit val headerCarrier: HeaderCarrier = HeaderCarrier()
- mockRequest()
+ val fakeAuth = new FakeAuthenticatedRequest(mcc.parsers.defaultBodyParser)
- def mockRequest(hasCredId: Boolean = false, hasNino: Boolean = true): Unit =
- when(mockAuthJourney andThen mockPropertyLinkingAction) thenReturn new ActionBuilder[AuthenticatedUserRequest, AnyContent] {
- override def invokeBlock[A](request: Request[A], block: AuthenticatedUserRequest[A] => Future[Result]): Future[Result] = {
- val authRequest = AuthenticatedUserRequest(
- request,
- None,
- None,
- Some("user@email.com"),
- Some(property),
- if (hasCredId) Some("1234") else None,
- None,
- None,
- nino = if (hasNino) Nino(hasNino = true, Some("AA000003D")) else Nino(hasNino = false, None)
- )
- block(authRequest)
- }
-
- override def parser: BodyParser[AnyContent] = mcc.parsers.defaultBodyParser
-
- override protected def executionContext: ExecutionContext = ec
- }
-
-
- def mockRequestWithoutProperty(hasCredId: Boolean = false, hasNino: Boolean = true): Unit =
- when(mockAuthJourney andThen mockPropertyLinkingAction) thenReturn new ActionBuilder[AuthenticatedUserRequest, AnyContent] {
- override def invokeBlock[A](request: Request[A], block: AuthenticatedUserRequest[A] => Future[Result]): Future[Result] = {
- val authRequest = AuthenticatedUserRequest(
- request,
- None,
- None,
- Some("user@email.com"),
- None,
- if (hasCredId) Some("1234") else None,
- None,
- None,
- nino = if (hasNino) Nino(hasNino = true, Some("AA000003D")) else Nino(hasNino = false, None)
- )
- block(authRequest)
- }
-
- override def parser: BodyParser[AnyContent] = mcc.parsers.defaultBodyParser
-
- override protected def executionContext: ExecutionContext = ec
- }
+ // def mockRequest(hasCredId: Boolean = false, hasNino: Boolean = true): Unit =
+// when(mockAuthJourney andThen mockGetData) thenReturn new ActionBuilder[AuthenticatedUserRequest, AnyContent] {
+// override def invokeBlock[A](request: Request[A], block: AuthenticatedUserRequest[A] => Future[Result]): Future[Result] = {
+// val authRequest = AuthenticatedUserRequest(
+// request,
+// None,
+// None,
+// Some("user@email.com"),
+// Some(property),
+// if (hasCredId) Some("1234") else None,
+// None,
+// None,
+// nino = if (hasNino) Nino(hasNino = true, Some("AA000003D")) else Nino(hasNino = false, None)
+// )
+// block(authRequest)
+// }
+//
+// override def parser: BodyParser[AnyContent] = mcc.parsers.defaultBodyParser
+//
+// override protected def executionContext: ExecutionContext = ec
+// }
+//
+//
+// def mockRequestWithoutProperty(hasCredId: Boolean = false, hasNino: Boolean = true): Unit =
+// when(mockAuthJourney andThen mockGetData) thenReturn new ActionBuilder[AuthenticatedUserRequest, AnyContent] {
+// override def invokeBlock[A](request: Request[A], block: AuthenticatedUserRequest[A] => Future[Result]): Future[Result] = {
+// val authRequest = AuthenticatedUserRequest(
+// request,
+// None,
+// None,
+// Some("user@email.com"),
+// None,
+// if (hasCredId) Some("1234") else None,
+// None,
+// None,
+// nino = if (hasNino) Nino(hasNino = true, Some("AA000003D")) else Nino(hasNino = false, None)
+// )
+// block(authRequest)
+// }
+//
+// override def parser: BodyParser[AnyContent] = mcc.parsers.defaultBodyParser
+//
+// override protected def executionContext: ExecutionContext = ec
+// }
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/helpers/TestData.scala b/test/uk/gov/hmrc/ngrraldfrontend/helpers/TestData.scala
index 54d6cfc0..d47fb12a 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/helpers/TestData.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/helpers/TestData.scala
@@ -56,7 +56,27 @@ trait TestData {
)
)
)
-
+
+ val firstSecondRentPeriod: ProvideDetailsOfFirstSecondRentPeriod = ProvideDetailsOfFirstSecondRentPeriod(
+ firstDateStart = "2025-01-01",
+ firstDateEnd = "2025-01-31",
+ firstRentPeriodRadio = true,
+ firstRentPeriodAmount = Some("1000"),
+ secondDateStart = "2025-02-01",
+ secondDateEnd = "2025-02-28",
+ secondHowMuchIsRent = "1000"
+ )
+
+ val firstSecondRentPeriodNoRentPayed: ProvideDetailsOfFirstSecondRentPeriod = ProvideDetailsOfFirstSecondRentPeriod(
+ firstDateStart = "2025-01-01",
+ firstDateEnd = "2025-01-31",
+ firstRentPeriodRadio = false,
+ firstRentPeriodAmount = None,
+ secondDateStart = "2025-02-01",
+ secondDateEnd = "2025-02-28",
+ secondHowMuchIsRent = "1000"
+ )
+
val testRegistrationModel: RatepayerRegistration = RatepayerRegistration(
userType = Some(Individual),
agentStatus = Some(AgentStatus.Agent),
@@ -85,8 +105,8 @@ trait TestData {
postcode = Postcode("BN110AA")
)
val regResponseJson: JsValue = Json.parse(
- """{"userType":"Individual","agentStatus":"Agent","name":{"value":"John Doe"},"tradingName":{"value":"CompanyLTD"},"email":{"value":"JohnDoe@digital.hmrc.gov.uk"},"contactNumber":{"value":"07123456789"},"secondaryNumber":{"value":"07123456789"},"address":{"line1":"99","line2":"Wibble Rd","town":"Worthing","county":"West Sussex","postcode":{"value":"BN110AA"}},"trnReferenceNumber":{"referenceType":"TRN","value":"12345"},"isRegistered":false}
- |""".stripMargin
+ """{"userType":"Individual","agentStatus":"Agent","name":{"value":"John Doe"},"tradingName":{"value":"CompanyLTD"},"email":{"value":"JohnDoe@digital.hmrc.gov.uk"},"contactNumber":{"value":"07123456789"},"secondaryNumber":{"value":"07123456789"},"address":{"line1":"99","line2":"Wibble Rd","town":"Worthing","county":"West Sussex","postcode":{"value":"BN110AA"}},"trnReferenceNumber":{"referenceType":"TRN","value":"12345"},"isRegistered":false}
+ |""".stripMargin
)
val minRegResponseModel: RatepayerRegistration = testRegistrationModel.copy(tradingName = None, secondaryNumber = None)
val minRegResponseJson: JsValue = Json.parse(
@@ -105,4 +125,28 @@ trait TestData {
|{"credId":{"value":"1234"}}
|""".stripMargin
)
-}
+
+ val agreementModel: Agreement = Agreement(
+ agreementStart = "2025-01-01", isOpenEnded = true, openEndedDate = Some("2025-02-02"), haveBreakClause = true, breakClauseInfo = Some("he has a break clause")
+ )
+
+ val agreementModelMin: Agreement = Agreement(
+ agreementStart = "2025-01-01", isOpenEnded = false, openEndedDate = None, haveBreakClause = false, breakClauseInfo = None
+ )
+
+ val agreementVerbalModelMin: AgreementVerbal = AgreementVerbal(startDate = "2025-01-01", openEnded = true, endDate = None)
+
+ val agreementVerbalModel: AgreementVerbal = AgreementVerbal(startDate = "2025-01-01", openEnded = false, endDate = Some("2025-02-02"))
+
+ val interimRentSetByTheCourtModel: InterimRentSetByTheCourt = InterimRentSetByTheCourt("10000", "1990-01")
+
+ val landlordModel: Landlord = Landlord("Joe Bloggs", "LandLordAndTenant", None)
+
+ val rentDatesAgreeStartModel: RentDatesAgreeStart = RentDatesAgreeStart("2025-01-01", "2025-02-02")
+
+ val whatYourRentIncludesModelAllYes: WhatYourRentIncludes = WhatYourRentIncludes(true,true,true,true,true,true,Some(5))
+
+ val whatYourRentIncludesModelAllNo: WhatYourRentIncludes = WhatYourRentIncludes(false,false,false,false,false,false,None)
+
+ val rentBasedOnModel: RentBasedOn = RentBasedOn("Other",Some("The rent was agreed"))
+}
\ No newline at end of file
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/helpers/TestSupport.scala b/test/uk/gov/hmrc/ngrraldfrontend/helpers/TestSupport.scala
index 73e1bd43..eee1e186 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/helpers/TestSupport.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/helpers/TestSupport.scala
@@ -25,15 +25,15 @@ import org.scalatestplus.play.guice.GuiceOneAppPerSuite
import play.api.Application
import play.api.i18n.{Lang, Messages, MessagesApi, MessagesImpl}
import play.api.inject.guice.GuiceApplicationBuilder
-import play.api.mvc.{AnyContentAsEmpty, MessagesControllerComponents}
+import play.api.mvc.{AnyContentAsEmpty, AnyContentAsFormUrlEncoded, MessagesControllerComponents}
import play.api.test.{FakeRequest, Injecting}
import uk.gov.hmrc.auth.core.retrieve.{Credentials, Name}
import uk.gov.hmrc.auth.core.{AffinityGroup, ConfidenceLevel, Nino}
import uk.gov.hmrc.http.{HeaderCarrier, HeaderNames}
import uk.gov.hmrc.ngrraldfrontend.connectors.NGRConnector
import uk.gov.hmrc.ngrraldfrontend.mocks.MockAppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.requests.{IdentifierRequest, OptionalDataRequest}
import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, Postcode}
-import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
import scala.concurrent.ExecutionContext
@@ -56,7 +56,7 @@ trait TestSupport extends PlaySpec
}
override implicit lazy val app: Application = localGuiceApplicationBuilder().build()
-
+
lazy val mcc: MessagesControllerComponents = inject[MessagesControllerComponents]
@@ -72,15 +72,22 @@ trait TestSupport extends PlaySpec
lazy val testName: Name = Name(name = Some("testUser"), lastName = Some("testUserLastName"))
lazy val testNoResultsFoundPostCode: Postcode = Postcode("LS1 6RE")
lazy implicit val mockConfig: MockAppConfig = new MockAppConfig(app.configuration)
- lazy implicit val mockRaldRepo: RaldRepo = mock[RaldRepo]
lazy implicit val mockNGRConnector: NGRConnector = mock[NGRConnector]
lazy val messagesApi: MessagesApi = inject[MessagesApi]
implicit lazy val messages: Messages = MessagesImpl(Lang("en"), messagesApi)
lazy val fakeRequest: FakeRequest[AnyContentAsEmpty.type] =
- FakeRequest("", "").withHeaders(HeaderNames.authorisation -> "Bearer 1")
+ FakeRequest("", "").withHeaders(HeaderNames.authorisation -> "Bearer 1")
+
+ lazy val authenticatedFakeRequest: AuthenticatedUserRequest[AnyContentAsEmpty.type] = {
+ AuthenticatedUserRequest(fakeRequest, None, None, None, None, credId = Some("1234"), None, None, nino = Nino(true, Some("")))
+ }
- def authenticatedFakeRequest[A](fakeRequest: FakeRequest[A] = fakeRequest): AuthenticatedUserRequest[A] =
- AuthenticatedUserRequest[A](fakeRequest, None, None, None, None, credId = Some("1234"), None, None, nino = Nino(true, Some("")))
+ def authenticatedFakePostRequest[A](fakeRequest: FakeRequest[A]): AuthenticatedUserRequest[A] = {
+ AuthenticatedUserRequest[A](
+ fakeRequest,
+ None, None, None, Some(property), credId = Some("1234"), None, None, nino = Nino(true, Some(""))
+ )
+ }
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/mocks/MockAppConfig.scala b/test/uk/gov/hmrc/ngrraldfrontend/mocks/MockAppConfig.scala
index 8711cf2b..4703204b 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/mocks/MockAppConfig.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/mocks/MockAppConfig.scala
@@ -27,7 +27,6 @@ class MockAppConfig(val runModeConfiguration: Configuration) extends AppConfig {
override val ngrDashboardUrl: String = "http://localhost:1503/ngr-dashboard-frontend/dashboard"
override val ngrLogoutUrl: String = "http://localhost:1503/ngr-dashboard-frontend/signout"
override def getString(key: String): String = ""
-
- override val timeToLive: String = "3"
+ override val cacheTtl: Long = 8
}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/models/ModeSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/models/ModeSpec.scala
new file mode 100644
index 00000000..cf1c4fa9
--- /dev/null
+++ b/test/uk/gov/hmrc/ngrraldfrontend/models/ModeSpec.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 org.scalatest.matchers.must.Matchers
+import org.scalatest.wordspec.AnyWordSpec
+
+class ModeSpec extends AnyWordSpec with Matchers {
+
+ "Mode" must {
+ "return a normal type" in {
+ Mode.jsLiteral.to(NormalMode) mustBe "NormalMode"
+ }
+ "return a check mode type" in {
+ Mode.jsLiteral.to(CheckMode) mustBe "CheckMode"
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepoSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepoSpec.scala
index 7c092e27..e69de29b 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepoSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepoSpec.scala
@@ -1,535 +0,0 @@
-/*
- * 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.repo
-
-import org.mongodb.scala.SingleObservableFuture
-import org.scalatest.matchers.should.Matchers.shouldBe
-import play.api.test.Helpers.{await, defaultAwaitTimeout}
-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.*
-import uk.gov.hmrc.ngrraldfrontend.models.components.*
-
-class RaldRepoSpec extends TestSupport with TestData
- with DefaultPlayMongoRepositorySupport[RaldUserAnswers] {
- override val repository: RaldRepo = app.injector.instanceOf[RaldRepo]
- val credId2: CredId = CredId("123456")
-
- override def beforeEach(): Unit = {
- await(repository.collection.drop().toFuture())
- await(repository.ensureIndexes())
- await(repository.upsertRaldUserAnswers(RaldUserAnswers(credId, NewAgreement, property)))
- }
-
- "repository" can {
- "save a new PropertyLinkingUserAnswer" when {
- "correct LookUpAddresses has been supplied" in {
- val isSuccessful = await(
- repository.upsertRaldUserAnswers(RaldUserAnswers(credId2, NewAgreement, property)))
- isSuccessful shouldBe true
- val actual = await(repository.findByCredId(credId2))
- actual shouldBe Some(RaldUserAnswers(credId2, NewAgreement, property))
- }
- "missing credId" in {
- val missingCredId = RaldUserAnswers(credId = CredId(null), NewAgreement, selectedProperty = property)
- val exception = intercept[IllegalStateException] {
- await(repository.upsertRaldUserAnswers(missingCredId))
- }
- exception.getMessage contains "Rald user answers has not been inserted" shouldBe true
- }
- }
-
- "insert type of agreement successfully" in {
- await(
- repository.insertTypeOfAgreement(
- credId, "Written"
- ))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, whatTypeOfAgreement = Some("Written")))
- }
-
- "insert type of lease renewal successfully" in {
- await(repository.insertTypeOfRenewal(credId, "RenewedAgreement"))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, whatTypeOfRenewal = Some("RenewedAgreement")))
- }
-
- "insert landlord with other description successfully" in {
- val landlordName = "John Doe"
- val landlordType = "OtherRelationship"
- val landlordOther = Some("Other description")
-
- await(repository.insertLandlord(credId, landlordName = landlordName, landLordType = landlordType, landlordOther = landlordOther))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, landlord = Some(Landlord("John Doe", "OtherRelationship", Some("Other description")))))
- }
-
- "insert landlord without other description successfully" in {
- val landlordName = "John Doe"
- val landlordType = "OtherRelationship"
-
- await(repository.insertLandlord(credId, landlordName = landlordName, landLordType = landlordType, landlordOther = None))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, landlord = Some(Landlord("John Doe", "OtherRelationship", None))))
- }
-
- "insert agreed rent change successfully" in {
- val agreedValue = "Yes"
-
- await(repository.insertAgreedRentChange(credId, agreedRentChange = agreedValue))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, agreedRentChange = Some(agreedValue)))
- }
-
- "insert agreement with open end date and break clause info successfully" in {
- val agreementStart = "12-12-2026"
- val openEndedRadio = "NoOpenEnded"
- val openEndedDate = Some("12-12-2026")
- val breakClauseRadio = "YesBreakClause"
- val breakClauseInfo = Some("break clause info")
-
-
- await(repository.insertAgreement(
- credId,
- agreementStart = agreementStart,
- openEndedRadio = openEndedRadio,
- openEndedDate = openEndedDate,
- breakClauseRadio = breakClauseRadio,
- breakClauseInfo = breakClauseInfo,
- ))
-
- val actual = await(repository.findByCredId(credId))
- actual shouldBe
- Some(
- RaldUserAnswers(
- credId,
- NewAgreement,
- property,
- agreement =
- Some(
- Agreement(
- agreementStart = agreementStart,
- isOpenEnded = false,
- openEndedDate = openEndedDate,
- haveBreakClause = true,
- breakClauseInfo = breakClauseInfo
- )
- )
- )
- )
- }
-
- "insert agreement with open end date successfully" in {
- val agreementStart = "12-12-2026"
- val openEndedRadio = "NoOpenEnded"
- val openEndedDate = Some("12-12-2026")
- val breakClauseRadio = "NoBreakClause"
-
-
-
- await(repository.insertAgreement(
- credId,
- agreementStart = agreementStart,
- openEndedRadio = openEndedRadio,
- openEndedDate = openEndedDate,
- breakClauseRadio = breakClauseRadio,
- breakClauseInfo = None
- ))
-
- val actual = await(repository.findByCredId(credId))
- actual shouldBe
- Some(
- RaldUserAnswers(
- credId,
- NewAgreement,
- property,
- agreement =
- Some(
- Agreement(
- agreementStart = agreementStart,
- isOpenEnded = false,
- openEndedDate = openEndedDate,
- haveBreakClause = false,
- breakClauseInfo = None
- )
- )
- )
- )
- }
-
- "insert agreement with break clause info successfully" in {
- val agreementStart = "12-12-2026"
- val openEndedRadio = "YesOpenEnded"
- val breakClauseRadio = "YesBreakClause"
- val breakClauseInfo = Some("break clause info")
-
-
- await(repository.insertAgreement(
- credId,
- agreementStart = agreementStart,
- openEndedRadio = openEndedRadio,
- openEndedDate = None,
- breakClauseRadio = breakClauseRadio,
- breakClauseInfo = breakClauseInfo,
- ))
-
- val actual = await(repository.findByCredId(credId))
- actual shouldBe
- Some(
- RaldUserAnswers(
- credId,
- NewAgreement,
- property,
- agreement =
- Some(
- Agreement(
- agreementStart = agreementStart,
- isOpenEnded = true,
- openEndedDate = None,
- haveBreakClause = true,
- breakClauseInfo = breakClauseInfo
- )
- )
- )
- )
- }
-
- "insert agreement with no break clause info and no open end date successfully" in {
- val agreementStart = "12-12-2026"
- val openEndedRadio = "YesOpenEnded"
- val breakClauseRadio = "NoBreakClause"
- val breakClauseInfo = None
-
-
- await(repository.insertAgreement(
- credId,
- agreementStart = agreementStart,
- openEndedRadio = openEndedRadio,
- openEndedDate = None,
- breakClauseRadio = breakClauseRadio,
- breakClauseInfo = breakClauseInfo,
- ))
-
- val actual = await(repository.findByCredId(credId))
- actual shouldBe
- Some(
- RaldUserAnswers(
- credId,
- NewAgreement,
- property,
- agreement =
- Some(
- Agreement(
- agreementStart = agreementStart,
- isOpenEnded = true,
- openEndedDate = None,
- haveBreakClause = false,
- breakClauseInfo = None
- )
- )
- )
- )
- }
-
- "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 expected = RaldUserAnswers(
- credId,
- NewAgreement,
- property,
- provideDetailsOfFirstSecondRentPeriod = Some(ProvideDetailsOfFirstSecondRentPeriod(
- firstDateStart = "2025-01-01",
- firstDateEnd = "2025-01-31",
- firstRentPeriodRadio = true,
- firstRentPeriodAmount = Some("1000"),
- secondDateStart = "2025-02-01",
- secondDateEnd = "2025-02-28",
- secondHowMuchIsRent = "1000"
- ))
- )
-
- 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))
-
- actual mustBe Some(expected)
- }
-
- "insert rent based on with other desc successfully" in {
- await(
- repository.insertRentBased(
- credId, "Other", Some("The rent agree")
- ))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, rentBasedOn = Some(RentBasedOn("Other", Some("The rent agree")))))
- }
-
- "insert rent based on without other desc successfully" in {
- await(repository.insertRentBased(credId, "Other", Some("The rent agree")))
- //Testing if other description value has been deleted
- await(
- repository.insertRentBased(
- credId, "PercentageTurnover", None
- ))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, rentBasedOn = Some(RentBasedOn("PercentageTurnover", None))))
- }
-
- "insert rent amount successfully" in {
- val annualRent = 10000.99
-
- await(repository.insertAnnualRent(credId, annualRent))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, rentAmount = Some("10000.99")))
- }
-
- "insert agreement verbal with end date successfully" in {
- await(
- repository.insertAgreementVerbal(
- credId, "2025-10-30", true, Some("2027-11-30")
- ))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, agreementVerbal = Some(AgreementVerbal("2025-10-30", true, Some("2027-11-30")))))
- }
-
- "insert agreement verbal without end date successfully" in {
- await(repository.insertAgreementVerbal(credId, "2025-10-30", true, Some("2027-11-30")))
- //Testing if end date value has been deleted
- await(
- repository.insertAgreementVerbal(
- credId, "2025-10-30", false, None
- ))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, agreementVerbal = Some(AgreementVerbal("2025-10-30", false, None))))
- }
-
- "insert AgreedRentChange successfully" in {
- val agreedRentChange = "Yes"
-
- await(repository.insertAgreedRentChange(credId, agreedRentChange))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, agreedRentChange = Some("Yes")))
- }
-
- "insert hasRentFreePeriod successfully with Yes" in {
- val hasRentFreePeriod = "Yes"
-
- await(repository.insertHasRentFreePeriod(credId, hasRentFreePeriod))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, hasRentFreePeriod = Some(true)))
- }
-
- "insert Did You Agree Rent With Landlord successfully with true" in {
- val yes = "YesTheLandlord"
-
- await(repository.insertDidYouAgreeRentWithLandlord(credId, yes))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, didYouAgreeRentWithLandlord = Some(true)))
- }
-
- "insert Did You Agree Rent With Landlord successfully with false" in {
- val no = "NoACourtSet"
-
- await(repository.insertDidYouAgreeRentWithLandlord(credId, no))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, didYouAgreeRentWithLandlord = Some(false)))
- }
-
- "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)))
- }
-
- "insert rent date successfully" in {
- val rentDate = "2025-4-30"
-
- await(repository.insertRentDates(credId, rentDate))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, agreedRentDate = Some(rentDate)))
- }
-
- "insert rent dates agree and start successfully" in {
- await(
- repository.insertRentAgreeStartDates(
- credId, "2025-10-30", "2027-12-1")
- )
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, rentDatesAgreeStart = Some(RentDatesAgreeStart("2025-10-30", "2027-12-1"))))
- }
-
- "insert rent period successfully with yes" in {
- await(repository.insertRentPeriod(credId, "Yes"))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, hasAnotherRentPeriod = Some(true)))
- }
-
- "insert rent period successfully with no" in {
- await(repository.insertRentPeriod(credId, "No"))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, hasAnotherRentPeriod = Some(false)))
- }
-
- "insert what your rent includes with all radios selected as yes" in {
- val radio1yes = livingAccommodationYes
- val radio2yes = rentPartAddressYes
- val radio3yes = rentEmptyShellYes
- val radio4yes = rentIncBusinessRatesYes
- val radio5yes = rentIncWaterChargesYes
- val radio6yes = rentIncServiceYes
- val bedroomNumbers = Some("6")
-
- await(repository.insertWhatYourRentIncludes(
- credId,
- radio1yes.toString,
- radio2yes.toString,
- radio3yes.toString,
- radio4yes.toString,
- radio5yes.toString,
- radio6yes.toString,
- bedroomNumbers
- ))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, whatYourRentIncludes = Some(WhatYourRentIncludes(
- true,
- true,
- true,
- true,
- true,
- true,
- Some(6)
- ))))
- }
-
- "insert what your rent includes with all radios selected as no" in {
- val radio1yes = livingAccommodationNo
- val radio2yes = rentPartAddressNo
- val radio3yes = rentEmptyShellNo
- val radio4yes = rentIncBusinessRatesNo
- val radio5yes = rentIncWaterChargesNo
- val radio6yes = rentIncServiceNo
- val bedroomNumbers = Some("6")
-
- await(repository.insertWhatYourRentIncludes(
- credId,
- radio1yes.toString,
- radio2yes.toString,
- radio3yes.toString,
- radio4yes.toString,
- radio5yes.toString,
- radio6yes.toString,
- bedroomNumbers
- ))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, whatYourRentIncludes = Some(WhatYourRentIncludes(
- false,
- false,
- false,
- false,
- false,
- false,
- None
- ))))
- }
-
- "insert how many parking spaces or garages included in rent with 1 uncoveredSpaces" in {
- await(repository.insertHowManyParkingSpacesOrGaragesIncludedInRent(credId, uncoveredSpaces = 1, coveredSpaces = 0, garages = 0))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, howManyParkingSpacesOrGaragesIncludedInRent = Some(HowManyParkingSpacesOrGarages(uncoveredSpaces = "1", coveredSpaces = "0", garages = "0"))))
- }
-
- "insert how many parking spaces or garages included in rent with 1 coveredSpaces" in {
- await(repository.insertHowManyParkingSpacesOrGaragesIncludedInRent(credId, uncoveredSpaces = 0, coveredSpaces = 1, garages = 0))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, howManyParkingSpacesOrGaragesIncludedInRent = Some(HowManyParkingSpacesOrGarages(uncoveredSpaces = "0", coveredSpaces = "1", garages = "0"))))
- }
-
- "insert how many parking spaces or garages included in rent with 1 garage" in {
- await(repository.insertHowManyParkingSpacesOrGaragesIncludedInRent(credId, uncoveredSpaces = 0, coveredSpaces = 0, garages = 1))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, howManyParkingSpacesOrGaragesIncludedInRent = Some(HowManyParkingSpacesOrGarages(uncoveredSpaces = "0", coveredSpaces = "0", garages = "1"))))
- }
-
- "insert rent free period" in {
- await(repository.insertRentFreePeriod(credId, rentFreePeriodMonths = 5, reasons = "Any reasons"))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, rentFreePeriod = Some(RentFreePeriod(months = 5, reasons = "Any reasons"))))
- }
-
- "credId doesn't exist in mongoDB" in {
- val actual = await(repository.findByCredId(credId2))
- actual mustBe None
- }
-
- "insert has parking included in rent successfully with yes" in {
- await(repository.insertDoesYourRentIncludeParking(credId, "Yes"))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, doesYourRentIncludeParking = Some(true)))
- }
-
- "insert interim rent amount and start date" in {
- await(repository.insertInterimRentSetByTheCourt(credId, 10000.12, "2020-1"))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, interimRentSetByTheCourt = Some(InterimRentSetByTheCourt(amount = "10000.12", date = "2020-1"))))
- }
-
- "insert interim rent amount With decimal of .00 and start date" in {
- await(repository.insertInterimRentSetByTheCourt(credId, 10000.00, "2020-1"))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, interimRentSetByTheCourt = Some(InterimRentSetByTheCourt(amount = "10000.0", date = "2020-1"))))
- }
-
- "insert has parking included in rent successfully with no" in {
- await(repository.insertDoesYourRentIncludeParking(credId, "No"))
- val actual = await(repository.findByCredId(credId))
- actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, doesYourRentIncludeParking = Some(false)))
- }
- }
-}
-
-
-
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/AgreedRentChangeViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/AgreedRentChangeViewSpec.scala
index 2181f7af..3cbc49c9 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/views/AgreedRentChangeViewSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/views/AgreedRentChangeViewSpec.scala
@@ -21,9 +21,10 @@ import org.jsoup.nodes.Document
import play.api.libs.json.Json
import uk.gov.hmrc.govukfrontend.views.viewmodels.radios.Radios
import uk.gov.hmrc.ngrraldfrontend.helpers.ViewBaseSpec
+import uk.gov.hmrc.ngrraldfrontend.models.NormalMode
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.{buildRadios, noButton, yesButton}
-import uk.gov.hmrc.ngrraldfrontend.models.components.{NGRRadio, NGRRadioButtons, NGRRadioName}
-import uk.gov.hmrc.ngrraldfrontend.models.forms.AgreedRentChangeForm
+import uk.gov.hmrc.ngrraldfrontend.models.components.{LeaseOrTenancy, NGRRadio, NGRRadioButtons, NGRRadioName, NavBarContents, NavBarCurrentPage, NavBarPageContents, NavigationBarContent, Verbal, Written, Yes}
+import uk.gov.hmrc.ngrraldfrontend.models.forms.{AgreedRentChangeForm, WhatTypeOfAgreementForm}
import uk.gov.hmrc.ngrraldfrontend.views.html.AgreedRentChangeView
class AgreedRentChangeViewSpec extends ViewBaseSpec {
@@ -51,11 +52,11 @@ class AgreedRentChangeViewSpec extends ViewBaseSpec {
val radio: Radios = buildRadios(form, ngrRadio)
"TellUsAboutYourNewAgreementView" must {
- val agreedRentChangeView = view(form, radio, address)
+ val agreedRentChangeView = view(form, radio, address, NormalMode)
lazy implicit val document: Document = Jsoup.parse(agreedRentChangeView.body)
- val htmlApply = view.apply(form, radio, address).body
- val htmlRender = view.render(form, radio, address, request, messages, mockConfig).body
- lazy val htmlF = view.f(form, radio, address)
+ val htmlApply = view.apply(form, radio, address, NormalMode).body
+ val htmlRender = view.render(form, radio, address, NormalMode, request, messages, mockConfig).body
+ lazy val htmlF = view.f(form, radio, address, NormalMode)
"htmlF is not empty" in {
htmlF.toString() must not be empty
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/AgreementVerbalViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/AgreementVerbalViewSpec.scala
index c3ead8b1..ec92d5dc 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/views/AgreementVerbalViewSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/views/AgreementVerbalViewSpec.scala
@@ -25,7 +25,7 @@ import uk.gov.hmrc.govukfrontend.views.viewmodels.fieldset.Fieldset
import uk.gov.hmrc.govukfrontend.views.viewmodels.hint.Hint
import uk.gov.hmrc.govukfrontend.views.viewmodels.radios.Radios
import uk.gov.hmrc.ngrraldfrontend.helpers.ViewBaseSpec
-import uk.gov.hmrc.ngrraldfrontend.models.NGRDate
+import uk.gov.hmrc.ngrraldfrontend.models.{NGRDate, NormalMode}
import uk.gov.hmrc.ngrraldfrontend.models.components.*
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.forms.AgreementVerbalForm
@@ -91,11 +91,11 @@ class AgreementVerbalViewSpec extends ViewBaseSpec {
}
"AgreementVerbalView" must {
- val agreementVerbalView = view(form, radio, address)
+ val agreementVerbalView = view(form, radio, address, NormalMode)
lazy implicit val document: Document = Jsoup.parse(agreementVerbalView.body)
- val htmlApply = view.apply(form, radio, address).body
- val htmlRender = view.render(form, radio, address, request, messages, mockConfig).body
- lazy val htmlF = view.f(form, radio, address)
+ val htmlApply = view.apply(form, radio, address, NormalMode).body
+ val htmlRender = view.render(form, radio, address, NormalMode, request, messages, mockConfig).body
+ lazy val htmlF = view.f(form, radio, address, NormalMode)
"htmlF is not empty" in {
htmlF.toString() must not be empty
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/CheckRentFreePeriodViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/CheckRentFreePeriodViewSpec.scala
index 2c12942e..074ad827 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/views/CheckRentFreePeriodViewSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/views/CheckRentFreePeriodViewSpec.scala
@@ -21,6 +21,7 @@ import org.jsoup.nodes.Document
import play.api.libs.json.Json
import uk.gov.hmrc.govukfrontend.views.viewmodels.radios.Radios
import uk.gov.hmrc.ngrraldfrontend.helpers.ViewBaseSpec
+import uk.gov.hmrc.ngrraldfrontend.models.NormalMode
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.{buildRadios, noButton, yesButton}
import uk.gov.hmrc.ngrraldfrontend.models.components.{NGRRadio, NGRRadioName}
import uk.gov.hmrc.ngrraldfrontend.models.forms.CheckRentFreePeriodForm
@@ -51,11 +52,11 @@ class CheckRentFreePeriodViewSpec extends ViewBaseSpec {
val radio: Radios = buildRadios(form, ngrRadio)
"TellUsAboutYourNewAgreementView" must {
- val checkRentFreePeriodView = view(form, radio, address)
+ val checkRentFreePeriodView = view(form, radio, address, NormalMode)
lazy implicit val document: Document = Jsoup.parse(checkRentFreePeriodView.body)
- val htmlApply = view.apply(form, radio, address).body
- val htmlRender = view.render(form, radio, address, request, messages, mockConfig).body
- lazy val htmlF = view.f(form, radio, address)
+ val htmlApply = view.apply(form, radio, address, NormalMode).body
+ val htmlRender = view.render(form, radio, address, NormalMode, request, messages, mockConfig).body
+ lazy val htmlF = view.f(form, radio, address, NormalMode)
"htmlF is not empty" in {
htmlF.toString() must not be empty
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/DidYouAgreeRentWithLandlordViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/DidYouAgreeRentWithLandlordViewSpec.scala
index 277a309b..18aac013 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/views/DidYouAgreeRentWithLandlordViewSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/views/DidYouAgreeRentWithLandlordViewSpec.scala
@@ -20,6 +20,7 @@ import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import uk.gov.hmrc.govukfrontend.views.viewmodels.radios.Radios
import uk.gov.hmrc.ngrraldfrontend.helpers.ViewBaseSpec
+import uk.gov.hmrc.ngrraldfrontend.models.NormalMode
import uk.gov.hmrc.ngrraldfrontend.models.components.*
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.forms.DidYouAgreeRentWithLandlordForm
@@ -49,11 +50,11 @@ class DidYouAgreeRentWithLandlordViewSpec extends ViewBaseSpec {
val radio: Radios = buildRadios(form, ngrRadio)
"DidYouAgreeRentWithLandlordView" must {
- val whatTypeOfAgreementView = view(address, form, radio)
+ val whatTypeOfAgreementView = view(address, form, radio, NormalMode)
lazy implicit val document: Document = Jsoup.parse(whatTypeOfAgreementView.body)
- val htmlApply = view.apply(address, form, radio).body
- val htmlRender = view.render(address, form, radio, request, messages, mockConfig).body
- lazy val htmlF = view.f(address, form, radio)
+ val htmlApply = view.apply(address, form, radio, NormalMode).body
+ val htmlRender = view.render(address, form, radio, NormalMode, request, messages, mockConfig).body
+ lazy val htmlF = view.f(address, form, radio, NormalMode)
"htmlF is not empty" in {
htmlF.toString() must not be empty
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/DoesYourRentIncludeParkingViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/DoesYourRentIncludeParkingViewSpec.scala
index dfed0537..08b2d748 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/views/DoesYourRentIncludeParkingViewSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/views/DoesYourRentIncludeParkingViewSpec.scala
@@ -22,6 +22,7 @@ import uk.gov.hmrc.govukfrontend.views.Aliases.Text
import uk.gov.hmrc.govukfrontend.views.viewmodels.fieldset.Legend
import uk.gov.hmrc.govukfrontend.views.viewmodels.radios.Radios
import uk.gov.hmrc.ngrraldfrontend.helpers.ViewBaseSpec
+import uk.gov.hmrc.ngrraldfrontend.models.NormalMode
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.{buildRadios, noButton, yesButton}
import uk.gov.hmrc.ngrraldfrontend.models.components.{NGRRadio, NGRRadioName}
import uk.gov.hmrc.ngrraldfrontend.models.forms.DoesYourRentIncludeParkingForm
@@ -50,11 +51,11 @@ class DoesYourRentIncludeParkingViewSpec extends ViewBaseSpec {
val radio: Radios = buildRadios(form, ngrRadio)
"DidYouAgreeRentWithLandlordView" must {
- val whatTypeOfAgreementView = view(address, form, radio)
+ val whatTypeOfAgreementView = view(address, form, radio, NormalMode)
lazy implicit val document: Document = Jsoup.parse(whatTypeOfAgreementView.body)
- val htmlApply = view.apply(address, form, radio).body
- val htmlRender = view.render(address, form, radio, request, messages, mockConfig).body
- lazy val htmlF = view.f(address, form, radio)
+ val htmlApply = view.apply(address, form, radio, NormalMode).body
+ val htmlRender = view.render(address, form, radio, NormalMode, request, messages, mockConfig).body
+ lazy val htmlF = view.f(address, form, radio, NormalMode)
"htmlF is not empty" in {
htmlF.toString() must not be empty
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/HowManyParkingSpacesOrGaragesIncludedInRentViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/HowManyParkingSpacesOrGaragesIncludedInRentViewSpec.scala
index 29c2300b..e48e94b7 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/views/HowManyParkingSpacesOrGaragesIncludedInRentViewSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/views/HowManyParkingSpacesOrGaragesIncludedInRentViewSpec.scala
@@ -22,6 +22,7 @@ import play.api.data.Form
import play.api.i18n.Messages
import play.twirl.api.HtmlFormat
import uk.gov.hmrc.ngrraldfrontend.helpers.ViewBaseSpec
+import uk.gov.hmrc.ngrraldfrontend.models.NormalMode
import uk.gov.hmrc.ngrraldfrontend.models.forms.HowManyParkingSpacesOrGaragesIncludedInRentForm
import uk.gov.hmrc.ngrraldfrontend.views.html.HowManyParkingSpacesOrGaragesIncludedInRentView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.InputText
@@ -74,12 +75,13 @@ class HowManyParkingSpacesOrGaragesIncludedInRentViewSpec extends ViewBaseSpec {
propertyAddress = address,
uncoveredSpaces = uncoveredSpaces,
coveredSpaces = coveredSpaces,
- garages = garages
+ garages = garages,
+ mode = NormalMode
)
lazy implicit val document: Document = Jsoup.parse(HowManyParkingSpacesOrGaragesIncludedInRentView.body)
- val htmlApply = view.apply(form, address, uncoveredSpaces, coveredSpaces, garages).body
- val htmlRender = view.render(form, address, uncoveredSpaces, coveredSpaces, garages, request, messages, mockConfig).body
- lazy val htmlF = view.f(form, address, uncoveredSpaces, coveredSpaces, garages)
+ val htmlApply = view.apply(form, address, uncoveredSpaces, coveredSpaces, garages, NormalMode).body
+ val htmlRender = view.render(form, address, uncoveredSpaces, coveredSpaces, garages, NormalMode, request, messages, mockConfig).body
+ lazy val htmlF = view.f(form, address, uncoveredSpaces, coveredSpaces, garages, NormalMode)
"htmlF is not empty" in {
htmlF.toString() must not be empty
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/HowMuchIsTotalAnnualRentViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/HowMuchIsTotalAnnualRentViewSpec.scala
index ef9e8d9b..b031a4b0 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/views/HowMuchIsTotalAnnualRentViewSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/views/HowMuchIsTotalAnnualRentViewSpec.scala
@@ -19,6 +19,8 @@ package uk.gov.hmrc.ngrraldfrontend.views
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import uk.gov.hmrc.ngrraldfrontend.helpers.ViewBaseSpec
+import uk.gov.hmrc.ngrraldfrontend.models.NormalMode
+import uk.gov.hmrc.ngrraldfrontend.models.components.*
import uk.gov.hmrc.ngrraldfrontend.models.forms.HowMuchIsTotalAnnualRentForm
import uk.gov.hmrc.ngrraldfrontend.views.html.HowMuchIsTotalAnnualRentView
@@ -48,11 +50,11 @@ class HowMuchIsTotalAnnualRentViewSpec extends ViewBaseSpec {
val form = HowMuchIsTotalAnnualRentForm.form.fillAndValidate(HowMuchIsTotalAnnualRentForm(10000))
"TellUsAboutYourNewAgreementView" must {
- val howMuchIsTotalAnnualRentView = view(form, address)
+ val howMuchIsTotalAnnualRentView = view(form, address, NormalMode)
lazy implicit val document: Document = Jsoup.parse(howMuchIsTotalAnnualRentView.body)
- val htmlApply = view.apply(form, address).body
- val htmlRender = view.render(form, address, request, messages, mockConfig).body
- lazy val htmlF = view.f(form, address)
+ val htmlApply = view.apply(form, address, NormalMode).body
+ val htmlRender = view.render(form, address, NormalMode, request, messages, mockConfig).body
+ lazy val htmlF = view.f(form, address, NormalMode)
"htmlF is not empty" in {
htmlF.toString() must not be empty
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/InterimRentSetByTheCourtViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/InterimRentSetByTheCourtViewSpec.scala
index a29c106d..e4a651f4 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/views/InterimRentSetByTheCourtViewSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/views/InterimRentSetByTheCourtViewSpec.scala
@@ -23,7 +23,7 @@ import play.api.i18n.Messages
import play.twirl.api.HtmlFormat
import uk.gov.hmrc.govukfrontend.views.Aliases.{PrefixOrSuffix, Text}
import uk.gov.hmrc.ngrraldfrontend.helpers.ViewBaseSpec
-import uk.gov.hmrc.ngrraldfrontend.models.NGRMonthYear
+import uk.gov.hmrc.ngrraldfrontend.models.{NGRMonthYear, NormalMode}
import uk.gov.hmrc.ngrraldfrontend.models.forms.InterimRentSetByTheCourtForm
import uk.gov.hmrc.ngrraldfrontend.views.html.InterimRentSetByTheCourtView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.InputText
@@ -68,11 +68,11 @@ class InterimRentSetByTheCourtViewSpec extends ViewBaseSpec {
val howMuch: HtmlFormat.Appendable = generateInputText(form, "howMuch")
"InterimRentSetByTheCourtView" must {
- val interimRentSetByTheCourtView = view(form, address, howMuch)
+ val interimRentSetByTheCourtView = view(form, address, howMuch, NormalMode)
lazy implicit val document: Document = Jsoup.parse(interimRentSetByTheCourtView.body)
- val htmlApply = view.apply(form, address, howMuch).body
- val htmlRender = view.render(form, address, howMuch, request, messages, mockConfig).body
- lazy val htmlF = view.f(form, address, howMuch)
+ val htmlApply = view.apply(form, address, howMuch, NormalMode).body
+ val htmlRender = view.render(form, address, howMuch, NormalMode, request, messages, mockConfig).body
+ lazy val htmlF = view.f(form, address, howMuch, NormalMode)
"htmlF is not empty" in {
htmlF.toString() must not be empty
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/LandlordViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/LandlordViewSpec.scala
index c75b72d1..fdb687d9 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/views/LandlordViewSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/views/LandlordViewSpec.scala
@@ -23,6 +23,7 @@ import play.api.i18n.Messages
import uk.gov.hmrc.govukfrontend.views.Aliases.{ErrorMessage, Label, Text}
import uk.gov.hmrc.govukfrontend.views.viewmodels.radios.Radios
import uk.gov.hmrc.ngrraldfrontend.helpers.ViewBaseSpec
+import uk.gov.hmrc.ngrraldfrontend.models.NormalMode
import uk.gov.hmrc.ngrraldfrontend.models.components.*
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.forms.LandlordForm
@@ -86,12 +87,12 @@ class LandlordViewSpec extends ViewBaseSpec {
val form = LandlordForm.form.fillAndValidate(LandlordForm(landlordName = "Bob", landLordType = "FamilyMember", None))
val radio: Radios = buildRadios(form, ngrRadio)
- "TellUsAboutYourNewAgreementView" must {
- val landlordView = view(address, form, radio)
+ "LandlordView" must {
+ val landlordView = view(address, form, radio , NormalMode)
lazy implicit val document: Document = Jsoup.parse(landlordView.body)
- val htmlApply = view.apply(address, form, radio).body
- val htmlRender = view.render(address, form, radio, request, messages, mockConfig).body
- lazy val htmlF = view.f(address, form, radio)
+ val htmlApply = view.apply(address, form, radio, NormalMode).body
+ val htmlRender = view.render(address, form, radio, NormalMode, request, messages, mockConfig).body
+ lazy val htmlF = view.f(address, form, radio, NormalMode)
"htmlF is not empty" in {
htmlF.toString() must not be empty
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/RentDatesAgreeStartViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/RentDatesAgreeStartViewSpec.scala
index d6e1f7ea..8be8bf41 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/views/RentDatesAgreeStartViewSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/views/RentDatesAgreeStartViewSpec.scala
@@ -20,7 +20,7 @@ import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import play.api.data.Form
import uk.gov.hmrc.ngrraldfrontend.helpers.ViewBaseSpec
-import uk.gov.hmrc.ngrraldfrontend.models.NGRDate
+import uk.gov.hmrc.ngrraldfrontend.models.{NGRDate, NormalMode}
import uk.gov.hmrc.ngrraldfrontend.models.forms.RentDatesAgreeStartForm
import uk.gov.hmrc.ngrraldfrontend.views.html.RentDatesAgreeStartView
import uk.gov.hmrc.ngrraldfrontend.views.html.components.DateTextFields
@@ -61,11 +61,11 @@ class RentDatesAgreeStartViewSpec extends ViewBaseSpec {
}
"RentDatesAgreeStartView" must {
- val rentDatesAgreeStartView = view(form, address)
+ val rentDatesAgreeStartView = view(form, address, NormalMode)
lazy implicit val document: Document = Jsoup.parse(rentDatesAgreeStartView.body)
- val htmlApply = view.apply(form, address).body
- val htmlRender = view.render(form, address, request, messages, mockConfig).body
- lazy val htmlF = view.f(form, address)
+ val htmlApply = view.apply(form, address, NormalMode).body
+ val htmlRender = view.render(form, address, NormalMode, request, messages, mockConfig).body
+ lazy val htmlF = view.f(form, address, NormalMode)
"htmlF is not empty" in {
htmlF.toString() must not be empty
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/RentFreePeriodViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/RentFreePeriodViewSpec.scala
index e5816b04..af469994 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/views/RentFreePeriodViewSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/views/RentFreePeriodViewSpec.scala
@@ -20,6 +20,7 @@ import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import play.api.data.Form
import uk.gov.hmrc.ngrraldfrontend.helpers.ViewBaseSpec
+import uk.gov.hmrc.ngrraldfrontend.models.NormalMode
import uk.gov.hmrc.ngrraldfrontend.models.forms.RentFreePeriodForm
import uk.gov.hmrc.ngrraldfrontend.views.html.RentFreePeriodView
@@ -49,11 +50,11 @@ class RentFreePeriodViewSpec extends ViewBaseSpec {
}
"RentDatesAgreeStartView" must {
- val rentFreePeriodView = view(form, address)
+ val rentFreePeriodView = view(form, address, NormalMode)
lazy implicit val document: Document = Jsoup.parse(rentFreePeriodView.body)
- val htmlApply = view.apply(form, address).body
- val htmlRender = view.render(form, address, request, messages, mockConfig).body
- lazy val htmlF = view.f(form, address)
+ val htmlApply = view.apply(form, address, NormalMode).body
+ val htmlRender = view.render(form, address, NormalMode, request, messages, mockConfig).body
+ lazy val htmlF = view.f(form, address, NormalMode)
"htmlF is not empty" in {
htmlF.toString() must not be empty
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/TypeOfLeaseRenewalViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/TypeOfLeaseRenewalViewSpec.scala
index eb6e3457..595e9a12 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/views/TypeOfLeaseRenewalViewSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/views/TypeOfLeaseRenewalViewSpec.scala
@@ -21,6 +21,7 @@ import org.jsoup.nodes.Document
import play.api.data.Form
import uk.gov.hmrc.govukfrontend.views.viewmodels.radios.Radios
import uk.gov.hmrc.ngrraldfrontend.helpers.ViewBaseSpec
+import uk.gov.hmrc.ngrraldfrontend.models.NormalMode
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.components.{NGRRadio, NGRRadioButtons, NGRRadioName}
import uk.gov.hmrc.ngrraldfrontend.models.forms.WhatTypeOfLeaseRenewalForm
@@ -52,11 +53,11 @@ class TypeOfLeaseRenewalViewSpec extends ViewBaseSpec {
}
"TypeOfLeaseRenewalView" must {
- val leaseRenewalView = view(form, radio, address)
+ val leaseRenewalView = view(form, radio, address, NormalMode)
lazy implicit val document: Document = Jsoup.parse(leaseRenewalView.body)
- val htmlApply = view.apply(form, radio, address).body
- val htmlRender = view.render(form, radio, address, request, messages, mockConfig).body
- lazy val htmlF = view.f(form, radio, address)
+ val htmlApply = view.apply(form, radio, address, NormalMode).body
+ val htmlRender = view.render(form, radio, address, NormalMode, request, messages, mockConfig).body
+ lazy val htmlF = view.f(form, radio, address, NormalMode)
"htmlF is not empty" in {
htmlF.toString() must not be empty
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/WhatIsYourRentBasedOnViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/WhatIsYourRentBasedOnViewSpec.scala
index 549bfd0c..922c9d60 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/views/WhatIsYourRentBasedOnViewSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/views/WhatIsYourRentBasedOnViewSpec.scala
@@ -23,6 +23,7 @@ import play.api.i18n.Messages
import uk.gov.hmrc.govukfrontend.views.Aliases.{Label, Text}
import uk.gov.hmrc.govukfrontend.views.viewmodels.radios.Radios
import uk.gov.hmrc.ngrraldfrontend.helpers.ViewBaseSpec
+import uk.gov.hmrc.ngrraldfrontend.models.NormalMode
import uk.gov.hmrc.ngrraldfrontend.models.components.*
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.forms.WhatIsYourRentBasedOnForm
@@ -104,11 +105,11 @@ class WhatIsYourRentBasedOnViewSpec extends ViewBaseSpec {
}
"WhatIsYourRentBasedOnView" must {
- val rentBasedOnView = view(form, radio, address)
+ val rentBasedOnView = view(form, radio, address, NormalMode)
lazy implicit val document: Document = Jsoup.parse(rentBasedOnView.body)
- val htmlApply = view.apply(form, radio, address).body
- val htmlRender = view.render(form, radio, address, request, messages, mockConfig).body
- lazy val htmlF = view.f(form, radio, address)
+ val htmlApply = view.apply(form, radio, address, NormalMode).body
+ val htmlRender = view.render(form, radio, address, NormalMode, request, messages, mockConfig).body
+ lazy val htmlF = view.f(form, radio, address, NormalMode)
"htmlF is not empty" in {
htmlF.toString() must not be empty
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/WhatTypeOfAgreementViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/WhatTypeOfAgreementViewSpec.scala
index e845464e..7496ab52 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/views/WhatTypeOfAgreementViewSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/views/WhatTypeOfAgreementViewSpec.scala
@@ -20,6 +20,7 @@ import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import uk.gov.hmrc.govukfrontend.views.viewmodels.radios.Radios
import uk.gov.hmrc.ngrraldfrontend.helpers.ViewBaseSpec
+import uk.gov.hmrc.ngrraldfrontend.models.NormalMode
import uk.gov.hmrc.ngrraldfrontend.models.components.*
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.forms.WhatTypeOfAgreementForm
@@ -53,11 +54,11 @@ class WhatTypeOfAgreementViewSpec extends ViewBaseSpec {
val radio: Radios = buildRadios(form, ngrRadio)
"TellUsAboutYourNewAgreementView" must {
- val whatTypeOfAgreementView = view(address, form, radio)
+ val whatTypeOfAgreementView = view(address, form, radio, NormalMode)
lazy implicit val document: Document = Jsoup.parse(whatTypeOfAgreementView.body)
- val htmlApply = view.apply(address, form, radio).body
- val htmlRender = view.render(address, form, radio, request, messages, mockConfig).body
- lazy val htmlF = view.f(address, form, radio)
+ val htmlApply = view.apply(address, form, radio, NormalMode).body
+ val htmlRender = view.render(address, form, radio, NormalMode, request, messages, mockConfig).body
+ lazy val htmlF = view.f(address, form, radio, NormalMode)
"htmlF is not empty" in {
htmlF.toString() must not be empty
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/WhatYourRentIncludesViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/WhatYourRentIncludesViewSpec.scala
index b4991dd5..74619a47 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/views/WhatYourRentIncludesViewSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/views/WhatYourRentIncludesViewSpec.scala
@@ -21,6 +21,7 @@ import org.jsoup.nodes.Document
import uk.gov.hmrc.govukfrontend.views.Aliases.{Legend, Text}
import uk.gov.hmrc.govukfrontend.views.viewmodels.radios.Radios
import uk.gov.hmrc.ngrraldfrontend.helpers.ViewBaseSpec
+import uk.gov.hmrc.ngrraldfrontend.models.NormalMode
import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
import uk.gov.hmrc.ngrraldfrontend.models.components.*
import uk.gov.hmrc.ngrraldfrontend.models.forms.WhatYourRentIncludesForm
@@ -138,11 +139,11 @@ class WhatYourRentIncludesViewSpec extends ViewBaseSpec {
val radio6: Radios = buildRadios(form, ngrRadio6)
"WhatYourRentIncludesView" must {
- val whatYourRentIncludesView = view(form, radio1, radio2, radio3, radio4, radio5, radio6, address)
+ val whatYourRentIncludesView = view(form, radio1, radio2, radio3, radio4, radio5, radio6, address, NormalMode)
lazy implicit val document: Document = Jsoup.parse(whatYourRentIncludesView.body)
- val htmlApply = view.apply(form, radio1, radio2, radio3, radio4, radio5, radio6, propertyAddress = "5 Brixham Marina, Berry Head Road, Brixham, Devon, TQ5 9BW").body
- val htmlRender = view.render(form, radio1, radio2, radio3, radio4, radio5, radio6, address, request, messages, mockConfig).body
- lazy val htmlF = view.f(form, radio1, radio2, radio3, radio4, radio5, radio6, address)
+ val htmlApply = view.apply(form, radio1, radio2, radio3, radio4, radio5, radio6, propertyAddress = "5 Brixham Marina, Berry Head Road, Brixham, Devon, TQ5 9BW", NormalMode).body
+ val htmlRender = view.render(form, radio1, radio2, radio3, radio4, radio5, radio6, address, NormalMode, request, messages, mockConfig).body
+ lazy val htmlF = view.f(form, radio1, radio2, radio3, radio4, radio5, radio6, address, NormalMode)
"htmlF is not empty" in {
htmlF.toString() must not be empty