diff --git a/app/controllers/aboutyouandtheproperty/PartsUnavailableController.scala b/app/controllers/aboutyouandtheproperty/PartsUnavailableController.scala new file mode 100644 index 000000000..aa0cd4b19 --- /dev/null +++ b/app/controllers/aboutyouandtheproperty/PartsUnavailableController.scala @@ -0,0 +1,93 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package controllers.aboutyouandtheproperty + +import actions.{SessionRequest, WithSessionRefiner} +import controllers.FORDataCaptureController +import form.aboutyouandtheproperty.PartsUnavailableForm.partsUnavailableForm +import models.submissions.aboutyouandtheproperty.AboutYouAndThePropertyPartTwo.updateAboutYouAndThePropertyPartTwo +import models.submissions.common.AnswersYesNo +import navigation.AboutYouAndThePropertyNavigator +import navigation.identifiers.PartsUnavailableId +import play.api.Logging +import play.api.i18n.I18nSupport +import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} +import repositories.SessionRepo +import views.html.aboutyouandtheproperty.partsUnavailable + +import javax.inject.{Inject, Named, Singleton} +import scala.concurrent.{ExecutionContext, Future} + +@Singleton +class PartsUnavailableController @Inject() ( + mcc: MessagesControllerComponents, + navigator: AboutYouAndThePropertyNavigator, + view: partsUnavailable, + withSessionRefiner: WithSessionRefiner, + @Named("session") val session: SessionRepo +)(implicit val ec: ExecutionContext) + extends FORDataCaptureController(mcc) + with I18nSupport + with Logging { + + def show: Action[AnyContent] = (Action andThen withSessionRefiner).async { implicit request => + Future.successful( + Ok( + view( + request.sessionData.aboutYouAndThePropertyPartTwo.flatMap(_.partsUnavailable) match { + case Some(tiedForGoods) => partsUnavailableForm.fill(tiedForGoods) + case _ => partsUnavailableForm + }, + calculateBackLink, + request.sessionData.toSummary + ) + ) + ) + } + + def submit: Action[AnyContent] = (Action andThen withSessionRefiner).async { implicit request => + continueOrSaveAsDraft[AnswersYesNo]( + partsUnavailableForm, + formWithErrors => + BadRequest( + view( + formWithErrors, + calculateBackLink, + request.sessionData.toSummary + ) + ), + data => { + val updatedData = updateAboutYouAndThePropertyPartTwo(_.copy(partsUnavailable = Some(data))) + session + .saveOrUpdate(updatedData) + .map(_ => Redirect(navigator.nextPage(PartsUnavailableId, updatedData).apply(updatedData))) + } + ) + } + + private def calculateBackLink(implicit request: SessionRequest[AnyContent]): String = + navigator.from match { + case "CYA" => controllers.aboutyouandtheproperty.routes.CheckYourAnswersAboutThePropertyController.show().url + case "TL" => s"${controllers.routes.TaskListController.show().url}#family-usage" + case _ => + if (request.sessionData.isWelsh) { + controllers.aboutyouandtheproperty.routes.CompletedCommercialLettingsWelshController.show().url + } else { + controllers.aboutyouandtheproperty.routes.CompletedCommercialLettingsController.show().url + } + } +} diff --git a/app/controllers/aboutyouandtheproperty/ThreeYearsConstructedController.scala b/app/controllers/aboutyouandtheproperty/ThreeYearsConstructedController.scala index 1ad7c6220..a433e2d61 100644 --- a/app/controllers/aboutyouandtheproperty/ThreeYearsConstructedController.scala +++ b/app/controllers/aboutyouandtheproperty/ThreeYearsConstructedController.scala @@ -29,16 +29,18 @@ import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import repositories.SessionRepo import views.html.aboutyouandtheproperty.threeYearsConstructed -import javax.inject.{Inject, Named} -import scala.concurrent.Future +import javax.inject.{Inject, Named, Singleton} +import scala.concurrent.{ExecutionContext, Future} +@Singleton class ThreeYearsConstructedController @Inject() ( mcc: MessagesControllerComponents, navigator: AboutYouAndThePropertyNavigator, view: threeYearsConstructed, withSessionRefiner: WithSessionRefiner, @Named("session") val session: SessionRepo -) extends FORDataCaptureController(mcc) +)(implicit val ec: ExecutionContext) + extends FORDataCaptureController(mcc) with I18nSupport with Logging { @@ -70,8 +72,9 @@ class ThreeYearsConstructedController @Inject() ( ), data => { val updatedData = updateAboutYouAndTheProperty(_.copy(threeYearsConstructed = Some(data))) - session.saveOrUpdate(updatedData) - Redirect(navigator.nextPage(ThreeYearsConstructedPageId, updatedData).apply(updatedData)) + session + .saveOrUpdate(updatedData) + .map(_ => Redirect(navigator.nextPage(ThreeYearsConstructedPageId, updatedData).apply(updatedData))) } ) } diff --git a/app/form/aboutyouandtheproperty/PartsUnavailableForm.scala b/app/form/aboutyouandtheproperty/PartsUnavailableForm.scala new file mode 100644 index 000000000..3d1a3f470 --- /dev/null +++ b/app/form/aboutyouandtheproperty/PartsUnavailableForm.scala @@ -0,0 +1,32 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package form.aboutyouandtheproperty + +import form.MappingSupport.createYesNoType +import models.submissions.common.AnswersYesNo +import play.api.data.Form +import play.api.data.Forms.single + +object PartsUnavailableForm { + + val partsUnavailableForm: Form[AnswersYesNo] = + Form( + single( + "partsUnavailable" -> createYesNoType("error.partsUnavailable.required") + ) + ) +} diff --git a/app/models/submissions/aboutyouandtheproperty/AboutYouAndThePropertyPartTwo.scala b/app/models/submissions/aboutyouandtheproperty/AboutYouAndThePropertyPartTwo.scala index fe93d940b..58bba0fe7 100644 --- a/app/models/submissions/aboutyouandtheproperty/AboutYouAndThePropertyPartTwo.scala +++ b/app/models/submissions/aboutyouandtheproperty/AboutYouAndThePropertyPartTwo.scala @@ -19,6 +19,7 @@ package models.submissions.aboutyouandtheproperty import actions.SessionRequest import models.Session import models.submissions.Form6010.MonthsYearDuration +import models.submissions.common.AnswersYesNo import play.api.libs.json.{Json, OFormat} import java.time.LocalDate @@ -33,7 +34,8 @@ case class AboutYouAndThePropertyPartTwo( commercialLetAvailabilityWelsh: Option[Seq[LettingAvailability]] = None, financialEndYearDates: Option[Seq[LocalDate]] = None, completedCommercialLettings: Option[Int] = None, - completedCommercialLettingsWelsh: Option[Seq[CompletedLettings]] = None + completedCommercialLettingsWelsh: Option[Seq[CompletedLettings]] = None, + partsUnavailable: Option[AnswersYesNo] = None ) object AboutYouAndThePropertyPartTwo { diff --git a/app/navigation/AboutYouAndThePropertyNavigator.scala b/app/navigation/AboutYouAndThePropertyNavigator.scala index e05fc04cb..00d98e135 100644 --- a/app/navigation/AboutYouAndThePropertyNavigator.scala +++ b/app/navigation/AboutYouAndThePropertyNavigator.scala @@ -172,6 +172,43 @@ class AboutYouAndThePropertyNavigator @Inject() (audit: Audit) extends Navigator throw new RuntimeException("Invalid option exception for alternative details question routing") } + private def completedCommercialLettingsRouting: Session => Call = answers => { + val canProceed: Boolean = + answers.aboutYouAndThePropertyPartTwo.flatMap(_.commercialLetAvailability).getOrElse(0) >= 140 && + answers.aboutYouAndThePropertyPartTwo.flatMap(_.completedCommercialLettings).getOrElse(0) >= 70 + if canProceed then controllers.aboutyouandtheproperty.routes.PartsUnavailableController.show() + else controllers.aboutyouandtheproperty.routes.CheckYourAnswersAboutThePropertyController.show() + } + + private def completedCommercialLettingsWelshRouting: Session => Call = answers => { + val canProceed: Boolean = { + val commercialLetNightsSum = answers.aboutYouAndThePropertyPartTwo + .flatMap(_.commercialLetAvailabilityWelsh) + .getOrElse(Seq.empty) + .map(_.numberOfNights) + .sum + + val completedLettingsNightsSum = answers.aboutYouAndThePropertyPartTwo + .flatMap(_.completedCommercialLettingsWelsh) + .getOrElse(Seq.empty) + .map(_.numberOfNights) + .sum + + commercialLetNightsSum >= 252 && completedLettingsNightsSum >= 182 + } + + if (canProceed) + controllers.aboutyouandtheproperty.routes.PartsUnavailableController.show() + else + controllers.aboutyouandtheproperty.routes.CheckYourAnswersAboutThePropertyController.show() + } + + private def partsUnavailableRouting: Session => Call = answers => + answers.aboutYouAndThePropertyPartTwo.flatMap(_.partsUnavailable) match { + case Some(AnswerYes) => controllers.routes.TaskListController.show() // TODO !!! + case _ => controllers.aboutyouandtheproperty.routes.CheckYourAnswersAboutThePropertyController.show() + } + private def threeYearsConstructedRouting: Session => Call = answers => answers.aboutYouAndTheProperty.flatMap(_.threeYearsConstructed) match { case Some(AnswerYes) => controllers.aboutyouandtheproperty.routes.CostsBreakdownController.show() @@ -194,8 +231,9 @@ class AboutYouAndThePropertyNavigator @Inject() (audit: Audit) extends Navigator CommercialLettingAvailabilityWelshId -> (_ => controllers.aboutyouandtheproperty.routes.CompletedCommercialLettingsWelshController.show() ), - CompletedCommercialLettingsId -> (_ => controllers.routes.TaskListController.show()), // TODO!!! - CompletedCommercialLettingsWelshId -> (_ => controllers.routes.TaskListController.show()), // TODO!!! + CompletedCommercialLettingsId -> completedCommercialLettingsRouting, + CompletedCommercialLettingsWelshId -> completedCommercialLettingsWelshRouting, + PartsUnavailableId -> partsUnavailableRouting, AboutThePropertyPageId -> aboutThePropertyDescriptionRouting, PropertyCurrentlyUsedPageId -> (_ => controllers.aboutyouandtheproperty.routes.WebsiteForPropertyController.show()), WebsiteForPropertyPageId -> websiteForPropertyRouting, diff --git a/app/navigation/identifiers/AboutYouAndThePropertyIdentifiers.scala b/app/navigation/identifiers/AboutYouAndThePropertyIdentifiers.scala index 8b6563f8d..51d36c9fa 100644 --- a/app/navigation/identifiers/AboutYouAndThePropertyIdentifiers.scala +++ b/app/navigation/identifiers/AboutYouAndThePropertyIdentifiers.scala @@ -118,6 +118,10 @@ case object CompletedCommercialLettingsWelshId extends Identifier { override def toString: String = "completedCommercialLettingsWelshPage" } +case object PartsUnavailableId extends Identifier { + override def toString: String = "partsUnavailablePage" +} + case object PlantAndTechnologyId extends Identifier { override def toString: String = "plantAndTechnologyPage" } diff --git a/app/views/aboutyouandtheproperty/partsUnavailable.scala.html b/app/views/aboutyouandtheproperty/partsUnavailable.scala.html new file mode 100644 index 000000000..396391738 --- /dev/null +++ b/app/views/aboutyouandtheproperty/partsUnavailable.scala.html @@ -0,0 +1,52 @@ +@* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *@ + +@import models.submissions.common.AnswersYesNo +@import uk.gov.hmrc.govukfrontend.views.html.components._ +@import models.pages.Summary + +@this(layout: Layout, + govukButton: GovukButton, + govukRadios: GovukRadios, + formWithCSRF: FormWithCSRF +) + +@(theForm: Form[AnswersYesNo],backLink: String, summary: Summary)(implicit request: Request[?], messages: Messages) + +@layout( + pageHeading = messages("partsUnavailable.heading"), + showSection = true, + summary = Option(summary), + sectionName = messages("label.section.aboutTheProperty"), + backLinkUrl = backLink, + theForm = theForm +) { + +

@messages("partsUnavailable.p")

+ + @formWithCSRF(action = controllers.aboutyouandtheproperty.routes.PartsUnavailableController.submit()) { + + @includes.radioButtonsYesNo( + govukRadios, + theForm, + "partsUnavailable", + "partsUnavailable.label", + classes = "govuk-fieldset__legend--m", + ) + + @includes.continueSaveAsDraftButtons(govukButton) + } +} \ No newline at end of file diff --git a/app/views/taskList.scala.html b/app/views/taskList.scala.html index 106b7526d..f9d4c8ec4 100644 --- a/app/views/taskList.scala.html +++ b/app/views/taskList.scala.html @@ -174,10 +174,10 @@

session.aboutYouAndThePropertyPartTwo.flatMap(_.commercialLetDate), session.aboutYouAndTheProperty.flatMap(_.customerDetails).isEmpty ) - @includes.taskListItem("site-construction-details", "taskList.familyUse", - controllers.routes.TaskListController.show(), // TODO, + @includes.taskListItem("family-use", "taskList.familyUse", + controllers.aboutyouandtheproperty.routes.PartsUnavailableController.show(), section2Completed, - session.aboutYouAndThePropertyPartTwo.flatMap(_.commercialLetDate), // TODO + session.aboutYouAndThePropertyPartTwo.flatMap(_.partsUnavailable), session.aboutYouAndThePropertyPartTwo.flatMap(_.commercialLetDate).isEmpty ) } diff --git a/conf/messages b/conf/messages index 0ee837e38..d0e0438e6 100644 --- a/conf/messages +++ b/conf/messages @@ -2982,7 +2982,12 @@ error.commercialLettingAvailability.range = The number of nights must be a figur error.commercialLettingAvailability.welsh.required = State how many nights was the property available in the year ending {0} error.commercialLettingAvailability.welsh.range = Number of nights in the year ending {0} must be a number between 1 and 365 +#PARTS OF THE PROPERTY UNAVAILABLE TO RENT +partsUnavailable.heading = Parts of the property unavailable for rent +partsUnavailable.p = You must declare if parts of the property are unavailable for rent as they are occupied by you or your family. This includes any accommodation used as main residence or as a second home. +partsUnavailable.label = Do you or your family occupy any part of the property as a main residence or a second home? +error.partsUnavailable.required = Select yes if you or your family occupy any part of the property #TYPE OF RENEWABLE PLANT renewablesPlant.heading = What type of renewables plant do you operate? diff --git a/conf/youAndProperty.routes b/conf/youAndProperty.routes index 25c3a48b4..edd43e74d 100644 --- a/conf/youAndProperty.routes +++ b/conf/youAndProperty.routes @@ -61,6 +61,9 @@ POST /completed-commercial-lettings controllers.aboutyouan GET /completed-commercial-lettings-welsh controllers.aboutyouandtheproperty.CompletedCommercialLettingsWelshController.show() POST /completed-commercial-lettings-welsh controllers.aboutyouandtheproperty.CompletedCommercialLettingsWelshController.submit() +GET /parts-unavailable controllers.aboutyouandtheproperty.PartsUnavailableController.show() +POST /parts-unavailable controllers.aboutyouandtheproperty.PartsUnavailableController.submit() + # About you and the property 6076 GET /renewables-plants controllers.aboutyouandtheproperty.RenewablesPlantController.show() diff --git a/test/controllers/aboutyouandtheproperty/CompletedCommercialLettingsWelshControllerSpec.scala b/test/controllers/aboutyouandtheproperty/CompletedCommercialLettingsWelshControllerSpec.scala index 16f8dd68f..22c6c7ede 100644 --- a/test/controllers/aboutyouandtheproperty/CompletedCommercialLettingsWelshControllerSpec.scala +++ b/test/controllers/aboutyouandtheproperty/CompletedCommercialLettingsWelshControllerSpec.scala @@ -88,10 +88,9 @@ class CompletedCommercialLettingsWelshControllerSpec extends TestBaseSpec { "save the form data and redirect to the next page" in { val res = controller().submit( - fakePostRequest.withFormUrlEncodedBody(formData(12)*) + fakePostRequest.withFormUrlEncodedBody(formData(2)*) ) - status(res) shouldBe SEE_OTHER - redirectLocation(res) shouldBe Option(controllers.routes.TaskListController.show().url) // TOD0 + status(res) shouldBe SEE_OTHER } "return 400 and error message for invalid character" in { diff --git a/test/controllers/aboutyouandtheproperty/PartsUnavailableControllerSpec.scala b/test/controllers/aboutyouandtheproperty/PartsUnavailableControllerSpec.scala new file mode 100644 index 000000000..9a26b9712 --- /dev/null +++ b/test/controllers/aboutyouandtheproperty/PartsUnavailableControllerSpec.scala @@ -0,0 +1,120 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package controllers.aboutyouandtheproperty + +import form.aboutyouandtheproperty.PartsUnavailableForm.partsUnavailableForm +import play.api.http.Status +import play.api.http.Status.{BAD_REQUEST, SEE_OTHER} +import play.api.test.FakeRequest +import play.api.test.Helpers.{POST, charset, contentAsString, contentType, status, stubMessagesControllerComponents} +import utils.TestBaseSpec + +class PartsUnavailableControllerSpec extends TestBaseSpec { + + import TestData._ + import utils.FormBindingTestAssertions._ + + def controller(isWelsh: Boolean = false) = new PartsUnavailableController( + stubMessagesControllerComponents(), + aboutYouAndThePropertyNavigator, + partsUnavailableView, + preEnrichedActionRefiner(isWelsh = isWelsh), + mockSessionRepo + ) + + "Controller - commercial letting question" should { + "return 200" in { + val result = controller().show(fakeRequest) + status(result) shouldBe Status.OK + } + + "return HTML" in { + val result = controller().show(fakeRequest) + contentType(result) shouldBe Some("text/html") + charset(result) shouldBe Some("utf-8") + } + + "return correct backLink when 'from=TL' query param is present" in { + val result = controller().show()(fakeRequestFromTL) + contentAsString(result) should include(s"${controllers.routes.TaskListController.show().url}#family-usage") + } + "return correct backLink when 'from=CYA' query param is present" in { + val result = controller().show()(fakeRequestFromCYA) + contentAsString(result) should include( + controllers.aboutyouandtheproperty.routes.CheckYourAnswersAboutThePropertyController.show().url + ) + } + "return correct backLink when no query param is present fo english property" in { + val result = controller().show()(fakeRequest) + contentAsString(result) should include( + controllers.aboutyouandtheproperty.routes.CompletedCommercialLettingsController.show().url + ) + } + + "return correct backLink when no query param is present fo welsh property" in { + val result = controller(isWelsh = true).show()(fakeRequest) + contentAsString(result) should include( + controllers.aboutyouandtheproperty.routes.CompletedCommercialLettingsWelshController.show().url + ) + } + } + + "SUBMIT /" should { + "throw a BAD_REQUEST if an empty form is submitted" in { + val res = controller().submit(FakeRequest().withFormUrlEncodedBody(Seq.empty*)) + status(res) shouldBe BAD_REQUEST + + } + + "Redirect to when form data submitted with yes" in { + val res = controller().submit( + FakeRequest(POST, "/").withFormUrlEncodedBody( + "partsUnavailable" -> "yes" + ) + ) + status(res) shouldBe SEE_OTHER + } + "Redirect when form data submitted with no" in { + val res = controller().submit( + FakeRequest(POST, "/").withFormUrlEncodedBody( + "partsUnavailable" -> "no" + ) + ) + status(res) shouldBe SEE_OTHER + } + } + + "Parts unavailable form" should { + "error if answer is missing" in { + val formData = baseFormData - errorKey.partsUnavailableQuestion + val form = partsUnavailableForm.bind(formData) + + mustContainError(errorKey.partsUnavailableQuestion, "error.partsUnavailable.required", form) + } + } + + object TestData { + val errorKey: ErrorKey = new ErrorKey + + class ErrorKey { + val partsUnavailableQuestion: String = "partsUnavailable" + } + + val baseFormData: Map[String, String] = Map("partsUnavailable" -> "yes") + } + +} diff --git a/test/navigation/AboutYouAndTheProperty6048NavigatorSpec.scala b/test/navigation/AboutYouAndTheProperty6048NavigatorSpec.scala new file mode 100644 index 000000000..7a94f02b3 --- /dev/null +++ b/test/navigation/AboutYouAndTheProperty6048NavigatorSpec.scala @@ -0,0 +1,213 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package navigation + +import connectors.Audit +import models.submissions.aboutyouandtheproperty.{AboutYouAndTheProperty, AboutYouAndThePropertyPartTwo, CompletedLettings, ContactDetailsQuestion, LettingAvailability} +import models.submissions.common.{AnswerNo, AnswerYes} +import navigation.identifiers.{AlternativeContactDetailsId, CommercialLettingAvailabilityId, CommercialLettingAvailabilityWelshId, CommercialLettingQuestionId, CompletedCommercialLettingsId, CompletedCommercialLettingsWelshId, ContactDetailsQuestionId, PartsUnavailableId} +import play.api.libs.json.JsObject +import uk.gov.hmrc.http.HeaderCarrier +import utils.TestBaseSpec + +import java.time.LocalDate +import scala.concurrent.ExecutionContext + +class AboutYouAndTheProperty6048NavigatorSpec extends TestBaseSpec { + + val audit = mock[Audit] + doNothing.when(audit).sendExplicitAudit(any[String], any[JsObject])(any[HeaderCarrier], any[ExecutionContext]) + + val navigator = new AdditionalInformationNavigator(audit) + + "About you and the property navigator" when { + + "return a function that goes to commercial letting, when alternative correspondence question have been completed with no" in { + + val answers = baseFilled6048Session.copy( + aboutYouAndTheProperty = + Some(AboutYouAndTheProperty(altDetailsQuestion = Some(ContactDetailsQuestion(AnswerNo)))) + ) + aboutYouAndThePropertyNavigator + .nextPage(ContactDetailsQuestionId, answers) + .apply( + answers + ) shouldBe controllers.aboutyouandtheproperty.routes.CommercialLettingQuestionController.show() + } + + "return a function that goes to Availability for commercial letting for England when alternative contact details filled" in { + aboutYouAndThePropertyNavigator + .nextPage(AlternativeContactDetailsId, baseFilled6048Session) + .apply( + baseFilled6048Session + ) shouldBe controllers.aboutyouandtheproperty.routes.CommercialLettingQuestionController.show() + } + + "return a function that goes to Availability for commercial letting for England when commercial letting question completed for english property" in { + aboutYouAndThePropertyNavigator + .nextPage(CommercialLettingQuestionId, baseFilled6048Session) + .apply( + baseFilled6048Session + ) shouldBe controllers.aboutyouandtheproperty.routes.CommercialLettingAvailabilityController + .show() + } + + "return a function that goes to Availability for commercial letting for Wales when commercial letting question completed for welsh property" in { + aboutYouAndThePropertyNavigator + .nextPage(CommercialLettingQuestionId, baseFilled6048WelshSession) + .apply( + baseFilled6048WelshSession + ) shouldBe controllers.aboutyouandtheproperty.routes.CommercialLettingAvailabilityWelshController + .show() + } + "return a function that goes to completed commercial letting for England" in { + + aboutYouAndThePropertyNavigator + .nextPage(CommercialLettingAvailabilityId, baseFilled6048Session) + .apply( + baseFilled6048Session + ) shouldBe controllers.aboutyouandtheproperty.routes.CompletedCommercialLettingsController + .show() + } + + "return a function that goes to completed commercial letting for Wales" in { + + aboutYouAndThePropertyNavigator + .nextPage(CommercialLettingAvailabilityWelshId, baseFilled6048WelshSession) + .apply( + baseFilled6048WelshSession + ) shouldBe controllers.aboutyouandtheproperty.routes.CompletedCommercialLettingsWelshController + .show() + } + + "return a function that goes to CYA page when letting conditions not fulfilled for England " in { + + val answers = baseFilled6048Session.copy( + aboutYouAndThePropertyPartTwo = Option( + AboutYouAndThePropertyPartTwo( + commercialLetAvailability = Option(12), + completedCommercialLettings = Option(12) + ) + ) + ) + aboutYouAndThePropertyNavigator + .nextPage(CompletedCommercialLettingsId, answers) + .apply( + answers + ) shouldBe controllers.aboutyouandtheproperty.routes.CheckYourAnswersAboutThePropertyController.show() + } + + "return a function that goes to CYA page when letting conditions not fulfilled for Wales " in { + + val answers = baseFilled6048Session.copy( + aboutYouAndThePropertyPartTwo = Option( + AboutYouAndThePropertyPartTwo( + commercialLetAvailabilityWelsh = Option( + Seq( + LettingAvailability(LocalDate.of(2024, 3, 31), 10), + LettingAvailability(LocalDate.of(2023, 3, 31), 20), + LettingAvailability(LocalDate.of(2022, 3, 31), 15) + ) + ), + completedCommercialLettingsWelsh = Option( + Seq( + CompletedLettings(LocalDate.of(2024, 3, 31), 10), + CompletedLettings(LocalDate.of(2023, 3, 31), 20), + CompletedLettings(LocalDate.of(2022, 3, 31), 15) + ) + ) + ) + ) + ) + aboutYouAndThePropertyNavigator + .nextPage(CompletedCommercialLettingsWelshId, answers) + .apply( + answers + ) shouldBe controllers.aboutyouandtheproperty.routes.CheckYourAnswersAboutThePropertyController.show() + } + + "return a function that goes to unavailable parts page when letting conditions fulfilled for England " in { + + val answers = baseFilled6048Session.copy( + aboutYouAndThePropertyPartTwo = Option( + AboutYouAndThePropertyPartTwo( + commercialLetAvailability = Option(200), + completedCommercialLettings = Option(200) + ) + ) + ) + aboutYouAndThePropertyNavigator + .nextPage(CompletedCommercialLettingsId, answers) + .apply( + answers + ) shouldBe controllers.aboutyouandtheproperty.routes.PartsUnavailableController.show() + } + + "return a function that goes to unavailable parts page when letting conditions fulfilled for Wales " in { + + val answers = baseFilled6048Session.copy( + aboutYouAndThePropertyPartTwo = Option( + AboutYouAndThePropertyPartTwo( + commercialLetAvailabilityWelsh = Option( + Seq( + LettingAvailability(LocalDate.of(2024, 3, 31), 100), + LettingAvailability(LocalDate.of(2023, 3, 31), 200), + LettingAvailability(LocalDate.of(2022, 3, 31), 150) + ) + ), + completedCommercialLettingsWelsh = Option( + Seq( + CompletedLettings(LocalDate.of(2024, 3, 31), 100), + CompletedLettings(LocalDate.of(2023, 3, 31), 200), + CompletedLettings(LocalDate.of(2022, 3, 31), 150) + ) + ) + ) + ) + ) + aboutYouAndThePropertyNavigator + .nextPage(CompletedCommercialLettingsWelshId, answers) + .apply( + answers + ) shouldBe controllers.aboutyouandtheproperty.routes.PartsUnavailableController.show() + } + + "return a function that goes to CYA when parts unavailable completed with no" in { + + val answers = baseFilled6048Session.copy( + aboutYouAndThePropertyPartTwo = Option(AboutYouAndThePropertyPartTwo(partsUnavailable = Option(AnswerNo))) + ) + aboutYouAndThePropertyNavigator + .nextPage(PartsUnavailableId, answers) + .apply( + answers + ) shouldBe controllers.aboutyouandtheproperty.routes.CheckYourAnswersAboutThePropertyController.show() + } + + "return a function that goes to occupiers details when parts unavailable completed with yes" in { + + val answers = baseFilled6048Session.copy( + aboutYouAndThePropertyPartTwo = Option(AboutYouAndThePropertyPartTwo(partsUnavailable = Option(AnswerYes))) + ) + aboutYouAndThePropertyNavigator + .nextPage(PartsUnavailableId, answers) + .apply( + answers + ) shouldBe controllers.routes.TaskListController.show() // TODO !!! + } + } +} diff --git a/test/navigation/identifiers/AboutYouAndThePropertyIdentifiersSpec.scala b/test/navigation/identifiers/AboutYouAndThePropertyIdentifiersSpec.scala index e7bb77767..2f2f1cd26 100644 --- a/test/navigation/identifiers/AboutYouAndThePropertyIdentifiersSpec.scala +++ b/test/navigation/identifiers/AboutYouAndThePropertyIdentifiersSpec.scala @@ -128,6 +128,10 @@ class AboutYouAndThePropertyIdentifiersSpec extends TestBaseSpec { assert(CompletedCommercialLettingsWelshId.toString.equals("completedCommercialLettingsWelshPage")) } + "Identifier for parts unavailable page" in { + assert(PartsUnavailableId.toString.equals("partsUnavailablePage")) + } + "Identifier generator capacity page" in { assert(GeneratorCapacityId.toString.equals("generatorCapacityPage")) } diff --git a/test/utils/FakeViews.scala b/test/utils/FakeViews.scala index 616eadc51..209c89a9a 100644 --- a/test/utils/FakeViews.scala +++ b/test/utils/FakeViews.scala @@ -125,6 +125,7 @@ trait FakeViews { this: Injecting => lazy val completedCommercialLettingsView: completedCommercialLettings = inject[completedCommercialLettings] lazy val completedCommercialLettingsWelshView: completedCommercialLettingsWelsh = inject[completedCommercialLettingsWelsh] + lazy val partsUnavailableView: partsUnavailable = inject[partsUnavailable] // About your trading history lazy val aboutYourTradingHistoryView: aboutYourTradingHistory = inject[aboutYourTradingHistory]