Skip to content

Commit

Permalink
PSR-1510_Check-Status | Amend after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
ccatosdevelopment committed Dec 11, 2024
1 parent 86f15e3 commit 6afafec
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 75 deletions.
13 changes: 5 additions & 8 deletions app/utils/nonsipp/TaskListStatusUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -468,14 +468,11 @@ object TaskListStatusUtils {
.url
)

val ifNeedsChecking = answersMissingLandOrPropertySection(userAnswers, srn)

(wereLandOrPropertiesHeld, numRecorded, ifNeedsChecking) match {
case (_, _, true) => (Check, listPageUrl) // TODO: navigate to new list page
case (None, _, false) => (NotStarted, firstQuestionPageUrl)
case (Some(false), _, false) => (Recorded(0, ""), firstQuestionPageUrl)
case (Some(true), 0, false) => (InProgress, inProgressCalculatedUrl)
case (Some(true), _, false) => (Recorded(numRecorded, "landOrProperties"), listPageUrl)
(wereLandOrPropertiesHeld, numRecorded) match {
case (None, _) => (NotStarted, firstQuestionPageUrl)
case (Some(false), _) => (Recorded(0, ""), firstQuestionPageUrl)
case (Some(true), 0) => (InProgress, inProgressCalculatedUrl)
case (Some(true), _) => (Recorded(numRecorded, "landOrProperties"), listPageUrl)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import eu.timepit.refined.refineMV
import pages.nonsipp.{CompilationOrSubmissionDatePage, FbVersionPage}
import forms.YesNoPageFormProvider
import models._
import pages.nonsipp.common.{IdentityTypePage, OtherRecipientDetailsPage}
import models.IdentitySubject.LandOrPropertySeller
import viewmodels.models.SectionCompleted
import eu.timepit.refined.api.Refined
import org.mockito.ArgumentMatchers.any
Expand All @@ -54,48 +52,45 @@ class LandOrPropertyListControllerSpec extends ControllerBaseSpec {
)

private val completedUserAnswers = defaultUserAnswers
.unsafeSet(LandOrPropertyHeldPage(srn), true)
// LOP 1 - Completed
.unsafeSet(LandPropertyInUKPage(srn, indexOne), true)
.unsafeSet(LandOrPropertyChosenAddressPage(srn, indexOne), address1)
.unsafeSet(LandRegistryTitleNumberPage(srn, indexOne), ConditionalYesNo.yes[String, String]("some-number"))
.unsafeSet(WhyDoesSchemeHoldLandPropertyPage(srn, indexOne), SchemeHoldLandProperty.Transfer)
.unsafeSet(LandOrPropertyTotalCostPage(srn, indexOne), money)
.unsafeSet(IsLandOrPropertyResidentialPage(srn, indexOne), true)
.unsafeSet(IsLandPropertyLeasedPage(srn, indexOne), true)
.unsafeSet(LandOrPropertySellerConnectedPartyPage(srn, indexOne), true)
.unsafeSet(LandOrPropertyLeaseDetailsPage(srn, indexOne), (leaseName, money, localDate))
.unsafeSet(IsLesseeConnectedPartyPage(srn, indexOne), true)
.unsafeSet(LandOrPropertyTotalIncomePage(srn, indexOne), money)
.unsafeSet(LandOrPropertyCompleted(srn, indexOne), SectionCompleted)
// LOP 2 - Completed then Removed
.unsafeSet(LandPropertyInUKPage(srn, indexTwo), true)
.unsafeSet(LandOrPropertyChosenAddressPage(srn, indexTwo), address2)
.unsafeSet(LandRegistryTitleNumberPage(srn, indexTwo), ConditionalYesNo.yes[String, String]("some-number"))
.unsafeSet(WhyDoesSchemeHoldLandPropertyPage(srn, indexTwo), SchemeHoldLandProperty.Transfer)
.unsafeSet(LandOrPropertyTotalCostPage(srn, indexTwo), money)
.unsafeSet(IsLandOrPropertyResidentialPage(srn, indexTwo), true)
.unsafeSet(IsLandPropertyLeasedPage(srn, indexTwo), true)
.unsafeSet(LandOrPropertySellerConnectedPartyPage(srn, indexTwo), true)
.unsafeSet(LandOrPropertyLeaseDetailsPage(srn, indexTwo), (leaseName, money, localDate))
.unsafeSet(IsLesseeConnectedPartyPage(srn, indexTwo), true)
.unsafeSet(LandOrPropertyTotalIncomePage(srn, indexTwo), money)
.unsafeSet(LandOrPropertyCompleted(srn, indexTwo), SectionCompleted)
.unsafeSet(RemovePropertyPage(srn, indexTwo), true)
.unsafeSet(LandOrPropertyHeldPage(srn), true)

private val completedUserAnswersToCheck = completedUserAnswers
.unsafeSet(LandPropertyInUKPage(srn, indexThree), true)
.unsafeSet(LandOrPropertyChosenAddressPage(srn, indexThree), address3)
.unsafeSet(LandRegistryTitleNumberPage(srn, indexThree), ConditionalYesNo.yes[String, String]("some-number"))
.unsafeSet(WhyDoesSchemeHoldLandPropertyPage(srn, indexThree), SchemeHoldLandProperty.Transfer)
.unsafeSet(LandOrPropertyTotalCostPage(srn, indexThree), money)
.unsafeSet(IdentityTypePage(srn, indexThree, LandOrPropertySeller), IdentityType.Other)
.unsafeSet(OtherRecipientDetailsPage(srn, indexThree, LandOrPropertySeller), otherRecipientDetails)

private val noUserAnswers = defaultUserAnswers
.unsafeSet(LandOrPropertyHeldPage(srn), false)
.unsafeSet(FbVersionPage(srn), "002")
.unsafeSet(CompilationOrSubmissionDatePage(srn), submissionDateTwo)

private val checkUserAnswers = completedUserAnswers.unsafeRemove(LandOrPropertyCompleted(srn, indexOne))

private val inProgressUserAnswers = defaultUserAnswers.unsafeSet(LandOrPropertyHeldPage(srn), true)

private lazy val onPageLoad = routes.LandOrPropertyListController.onPageLoad(srn, page = 1, NormalMode)
Expand Down Expand Up @@ -141,7 +136,7 @@ class LandOrPropertyListControllerSpec extends ControllerBaseSpec {
isPrePop = false
)
)
}.withName("Completed Journey"))
}.withName("Completed Journey - 1 added record"))

act.like(renderViewWithPrePopSession(onPageLoad, completedUserAnswersToCheck) { implicit app => implicit request =>
injected[ListView].apply(
Expand All @@ -157,28 +152,14 @@ class LandOrPropertyListControllerSpec extends ControllerBaseSpec {
isPrePop = true
)
)
}.withName("Completed PrePop Journey"))

act.like(renderView(onPageLoad, checkUserAnswers) { implicit app => implicit request =>
injected[ListView].apply(
form(new YesNoPageFormProvider()),
viewModel(
srn,
1,
NormalMode,
addresses,
schemeName,
showBackLink = true
)
)
}.withName("Check Journey"))
}.withName("PrePop Journey - 1 added record, 1 PrePop record to Check"))

act.like(
redirectToPage(
onPageLoad,
controllers.nonsipp.landorproperty.routes.LandOrPropertyHeldController.onPageLoad(srn, NormalMode),
inProgressUserAnswers
).withName("In Progress Journey")
).withName("In Progress Journey - 0 added records")
)

act.like(
Expand Down
59 changes: 18 additions & 41 deletions test/utils/nonsipp/TaskListStatusUtilsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,16 @@ class TaskListStatusUtilsSpec extends AnyFreeSpec with Matchers with OptionValue
TaskListStatusUtils.getLandOrPropertyTaskListStatusAndLink(customUserAnswers, srn, isPrePop = false)
result mustBe (InProgress, firstQuestionPageUrl)
}

"when landOrPropertyHeldPage true and only first page is present" in {
val customUserAnswers = defaultUserAnswers
.unsafeSet(LandOrPropertyHeldPage(srn), true)
.unsafeSet(LandPropertyInUKPages(srn), Map("0" -> true))

val result =
TaskListStatusUtils.getLandOrPropertyTaskListStatusAndLink(customUserAnswers, srn, isPrePop = false)
result mustBe (InProgress, secondQuestionPageUrl(index1of5000))
}
}

"should be Recorded" - {
Expand All @@ -374,55 +384,22 @@ class TaskListStatusUtilsSpec extends AnyFreeSpec with Matchers with OptionValue
"when landOrPropertyHeldPage true and equal number of first pages and last pages are present" in {
val customUserAnswers = currentUA

val result = TaskListStatusUtils.getLandOrPropertyTaskListStatusAndLink(customUserAnswers, srn)
val result =
TaskListStatusUtils.getLandOrPropertyTaskListStatusAndLink(customUserAnswers, srn, isPrePop = false)
result mustBe (Recorded(1, "landOrProperties"), listPageUrl)
}
}

"should be Check" - {
"when landOrPropertyHeldPage true and only first page is present" in {
"when at least 1 record requires checking and isPrePop" in {
val customUserAnswers = defaultUserAnswers
.unsafeSet(LandOrPropertyHeldPage(srn), true)
.unsafeSet(LandPropertyInUKPage(srn, refineMV(1)), true)
.unsafeSet(LandOrPropertyCompleted(srn, index1of5000), SectionCompleted)
.unsafeSet(LandPropertyInUKPage(srn, refineMV(2)), true)
.unsafeSet(LandOrPropertyCompleted(srn, index2of5000), SectionCompleted)

val result =
TaskListStatusUtils.getLandOrPropertyTaskListStatusAndLink(customUserAnswers, srn, isPrePop = false)
result mustBe (Check, listPageUrl)
}

"when landOrPropertyHeldPage true and more first pages than last pages is present - index 2 is missing" in {
val customUserAnswers = defaultUserAnswers
.unsafeSet(LandOrPropertyHeldPage(srn), true)
.unsafeSet(LandPropertyInUKPage(srn, refineMV(1)), true)
.unsafeSet(LandOrPropertyCompleted(srn, index1of5000), SectionCompleted)
.unsafeSet(LandPropertyInUKPage(srn, refineMV(2)), true)

val result =
TaskListStatusUtils.getLandOrPropertyTaskListStatusAndLink(customUserAnswers, srn, isPrePop = false)
result mustBe (Check, listPageUrl)
}

"when landOrPropertyHeldPage true and more first pages than last pages is present - index 1 is missing" in {
val customUserAnswers = defaultUserAnswers
.unsafeSet(LandOrPropertyHeldPage(srn), true)
.unsafeSet(LandPropertyInUKPage(srn, index1of5000), true)
// missing here
.unsafeSet(LandPropertyInUKPage(srn, index2of5000), true)
.unsafeSet(LandOrPropertyChosenAddressPage(srn, index2of5000), address)
.unsafeSet(LandRegistryTitleNumberPage(srn, index2of5000), ConditionalYesNo.no[String, String](reason))
.unsafeSet(WhyDoesSchemeHoldLandPropertyPage(srn, index2of5000), SchemeHoldLandProperty.Transfer)
.unsafeSet(LandOrPropertyTotalCostPage(srn, index2of5000), money)
.unsafeSet(IsLandOrPropertyResidentialPage(srn, index2of5000), false)
.unsafeSet(IsLandPropertyLeasedPage(srn, index2of5000), false)
.unsafeSet(LandOrPropertyTotalIncomePage(srn, index2of5000), money)
.unsafeSet(LandOrPropertyCompleted(srn, index2of5000), SectionCompleted)
.unsafeSet(LandPropertyIndependentValuationPage(srn, index2of5000), false)
.unsafeSet(LandOrPropertyChosenAddressPage(srn, index1of5000), address)
.unsafeSet(LandRegistryTitleNumberPage(srn, index1of5000), ConditionalYesNo.no[String, String](reason))
.unsafeSet(WhyDoesSchemeHoldLandPropertyPage(srn, index1of5000), SchemeHoldLandProperty.Transfer)
.unsafeSet(LandOrPropertyTotalCostPage(srn, index1of5000), money)

val result =
TaskListStatusUtils.getLandOrPropertyTaskListStatusAndLink(customUserAnswers, srn, isPrePop = false)
val result = TaskListStatusUtils.getLandOrPropertyTaskListStatusAndLink(customUserAnswers, srn, isPrePop = true)
result mustBe (Check, listPageUrl)
}
}
Expand Down

0 comments on commit 6afafec

Please sign in to comment.