diff --git a/app/viewmodels/tasklist/LandTaskList.scala b/app/viewmodels/tasklist/LandTaskList.scala index dca847e9d..259509429 100644 --- a/app/viewmodels/tasklist/LandTaskList.scala +++ b/app/viewmodels/tasklist/LandTaskList.scala @@ -47,6 +47,16 @@ object LandTaskList { land.mineralRights.isDefined ) + private def prelimFieldsDefinedOnly(land: Land): Seq[Boolean] = + Seq( + land.address1.isDefined, + land.propertyType.isEmpty, + land.interestCreatedTransferred.isEmpty, + land.localAuthorityNumber.isEmpty, + land.willSendPlanByPost.isEmpty, + land.mineralRights.isEmpty + ) + def isLandComplete(land: Land): Boolean = mandatoryFieldsDefined(land).forall(identity) @@ -62,6 +72,18 @@ object LandTaskList { else all.flatMap(land => mandatoryFieldsDefined(land)) } + def isPrelimLand(fullReturn: FullReturn): Boolean = { + if (lands(fullReturn).size == 1) { + val land = lands(fullReturn).head + val mainLandId: Option[String] = fullReturn.returnInfo.flatMap(_.mainLandID) + val isMainLand = land.landID.exists(landId => mainLandId.contains(landId)) + if isMainLand && prelimFieldsDefinedOnly(land).forall(identity) then true + else false + } else { + false + } + } + def isLandComplete(fullReturn: FullReturn): Boolean = { val all = lands(fullReturn) all.nonEmpty && all.forall(land => isLandComplete(land)) @@ -73,6 +95,8 @@ object LandTaskList { val defaultUrl = if (isLandComplete(fullReturn)) controllers.land.routes.LandOverviewController.onPageLoad().url + else if (isPrelimLand(fullReturn)) + controllers.land.routes.LandBeforeYouStartController.onPageLoad().url else if (incompleteLands(fullReturn).nonEmpty) controllers.land.routes.LandIncompleteOverviewController.onPageLoad().url else diff --git a/app/viewmodels/tasklist/PurchaserTaskList.scala b/app/viewmodels/tasklist/PurchaserTaskList.scala index cb8891f60..33b686ea6 100644 --- a/app/viewmodels/tasklist/PurchaserTaskList.scala +++ b/app/viewmodels/tasklist/PurchaserTaskList.scala @@ -43,6 +43,25 @@ object PurchaserTaskList { purchaser.isConnectedToVendor.isDefined ) + private def prelimFieldsDefinedOnly(purchaser: Purchaser, companyDetails: Option[CompanyDetails]): Seq[Boolean] = { + val isCompany = purchaser.isCompany.exists(_.equalsIgnoreCase("YES")) + Seq( + purchaser.isCompany.isDefined, + if isCompany then purchaser.companyName.isDefined else purchaser.surname.isDefined, + purchaser.nino.isEmpty, + purchaser.dateOfBirth.isEmpty, + purchaser.registrationNumber.isEmpty, + purchaser.placeOfRegistration.isEmpty, + if (isCompany) { + companyDetails.exists(cd => + cd.VATReference.isEmpty && cd.UTR.isEmpty + ) + } else companyDetails.isEmpty, + purchaser.isTrustee.isEmpty, + purchaser.isConnectedToVendor.isEmpty + ) + } + def mainSpecificFieldsDefined(purchaser: Purchaser, companyDetails: Option[CompanyDetails]): Seq[Boolean] = { val isPurchaserCompany = purchaser.isCompany.exists(_.equalsIgnoreCase("yes")) val isCompanyDetailsDefined = companyDetails.isDefined @@ -74,6 +93,16 @@ object PurchaserTaskList { if (isMainPurchaser) commonFieldsDefined(purchaser) ++ mainSpecificFieldsDefined(purchaser, companyDetails) else commonFieldsDefined(purchaser) + def isPrelimPurchaser(fullReturn: FullReturn): Boolean = { + if (purchasers(fullReturn).size == 1) { + val purchaser = purchasers(fullReturn).head + if isMainPurchaser(purchaser, fullReturn) && prelimFieldsDefinedOnly(purchaser, fullReturn.companyDetails).forall(identity) then true + else false + } else { + false + } + } + def isPurchaserComplete(purchaser: Purchaser, isMainPurchaser: Boolean, companyDetails: Option[CompanyDetails]): Boolean = mandatoryFieldsDefined(purchaser, isMainPurchaser, companyDetails).forall(identity) @@ -108,6 +137,8 @@ object PurchaserTaskList { val url = if (isPurchaserComplete(fullReturn)) controllers.purchaser.routes.PurchaserOverviewController.onPageLoad().url + else if (isPrelimPurchaser(fullReturn)) + controllers.purchaser.routes.PurchaserBeforeYouStartController.onPageLoad().url else if (incompletePurchasers(fullReturn).nonEmpty) controllers.purchaser.routes.PurchaserIncompleteOverviewController.onPageLoad().url else diff --git a/test/viewmodels/tasklist/LandTaskListSpec.scala b/test/viewmodels/tasklist/LandTaskListSpec.scala index 4f54a76c6..1750993a9 100644 --- a/test/viewmodels/tasklist/LandTaskListSpec.scala +++ b/test/viewmodels/tasklist/LandTaskListSpec.scala @@ -19,6 +19,7 @@ package viewmodels.tasklist import base.SpecBase import config.FrontendAppConfig import constants.FullReturnConstants.* +import models.Land import play.api.i18n.Messages import play.api.test.Helpers.running import services.crossflow.{ReturnSection, SectionStatus} @@ -39,6 +40,13 @@ class LandTaskListSpec extends SpecBase { willSendPlanByPost = None, mineralRights = None, )))) + private val fullReturnPrelimLand = fullReturnComplete.copy( + land = Some(Seq(Land( + landID = Some("LND001"), + returnID = Some("RET123456789"), + landResourceRef = Some("LND-REF-001"), + address1 = Some("123 Fake Street") + )))) private val fullReturnSomeMandatoryFieldsMissing = fullReturnComplete.copy( land = Some(Seq(completeLand.copy( propertyType = None, @@ -357,6 +365,20 @@ class LandTaskListSpec extends SpecBase { } } + "must have Before You Start url and show 'In Progress' status when only land data from prelim is present" in { + val application = applicationBuilder().build() + + running(application) { + implicit val appConfig: FrontendAppConfig = application.injector.instanceOf[FrontendAppConfig] + + val result = LandTaskList.buildLandRow(fullReturnPrelimLand, noFailuresStatus) + + result.url mustBe controllers.land.routes.LandBeforeYouStartController.onPageLoad().url + + result.status mustBe TLInProgress + } + } + "must have Land Incomplete url and show 'In progress' status when some mandatory fields are missing from main land" in { val application = applicationBuilder().build() diff --git a/test/viewmodels/tasklist/PurchaserTaskListSpec.scala b/test/viewmodels/tasklist/PurchaserTaskListSpec.scala index ef4b0508d..47a7da461 100644 --- a/test/viewmodels/tasklist/PurchaserTaskListSpec.scala +++ b/test/viewmodels/tasklist/PurchaserTaskListSpec.scala @@ -49,6 +49,34 @@ class PurchaserTaskListSpec extends SpecBase { dateOfBirth = None, ), completePurchaser2, completePurchaser3))) + private val fullReturnPrelimPurchaserCompany = fullReturnComplete.copy( + purchaser = Some(Seq(Purchaser( + isCompany = Some("YES"), + address1 = Some("123 Fake Street"), + companyName = Some("Company name"), + purchaserID = Some("PUR001"), + returnID = Some("RET123456789"), + purchaserResourceRef = Some("PUR-REF-001") + ))), + companyDetails = Some(CompanyDetails( + companyDetailsID = Some("CD001"), + returnID = Some("RET123456789"), + purchaserID = Some("PUR001") + )) + ) + + private val fullReturnPrelimPurchaserIndividual = fullReturnComplete.copy( + purchaser = Some(Seq(Purchaser( + isCompany = Some("NO"), + address1 = Some("123 Fake Street"), + surname = Some("Smith"), + purchaserID = Some("PUR001"), + returnID = Some("RET123456789"), + purchaserResourceRef = Some("PUR-REF-001") + ))), + companyDetails = None + ) + private val fullReturnSomeMandatoryFieldsMissingOther = fullReturnComplete.copy( purchaser = Some(Seq(completePurchaser1, completePurchaser2, completePurchaser3.copy( address1 = None @@ -420,6 +448,32 @@ class PurchaserTaskListSpec extends SpecBase { } } + "must have Before You Start url and show 'In Progress' status when only prelim fields are present in main purchaser for individual" in { + val application = applicationBuilder().build() + + running(application) { + implicit val appConfig: FrontendAppConfig = application.injector.instanceOf[FrontendAppConfig] + + val result = PurchaserTaskList.buildPurchaserRow(fullReturnPrelimPurchaserIndividual) + result.url mustBe controllers.purchaser.routes.PurchaserBeforeYouStartController.onPageLoad().url + + result.status mustBe TLInProgress + } + } + + "must have Before You Start url and show 'In Progress' status when only prelim fields are present in main purchaser for company" in { + val application = applicationBuilder().build() + + running(application) { + implicit val appConfig: FrontendAppConfig = application.injector.instanceOf[FrontendAppConfig] + + val result = PurchaserTaskList.buildPurchaserRow(fullReturnPrelimPurchaserCompany) + result.url mustBe controllers.purchaser.routes.PurchaserBeforeYouStartController.onPageLoad().url + + result.status mustBe TLInProgress + } + } + "must have Purchaser Incomplete Overview url and show 'In Progress' status when no mandatory fields are present in other purchaser" in { val application = applicationBuilder().build()