diff --git a/app/controllers/nonsipp/otherassetsheld/OtherAssetsCYAController.scala b/app/controllers/nonsipp/otherassetsheld/OtherAssetsCYAController.scala index d5248ca74..04c028c43 100644 --- a/app/controllers/nonsipp/otherassetsheld/OtherAssetsCYAController.scala +++ b/app/controllers/nonsipp/otherassetsheld/OtherAssetsCYAController.scala @@ -205,10 +205,12 @@ class OtherAssetsCYAController @Inject()( def onSubmit(srn: Srn, index: Max5000, mode: Mode): Action[AnyContent] = identifyAndRequireData(srn).async { implicit request => + val prePopulated = request.userAnswers.get(OtherAssetsPrePopulated(srn, index)) for { updatedUserAnswers <- Future.fromTry( request.userAnswers .set(OtherAssetsHeldPage(srn), true) + .setWhen(prePopulated.isDefined)(OtherAssetsPrePopulated(srn, index), true) .set(OtherAssetsCompleted(srn, index), SectionCompleted) ) _ <- saveService.save(updatedUserAnswers) diff --git a/app/controllers/nonsipp/otherassetsheld/OtherAssetsListController.scala b/app/controllers/nonsipp/otherassetsheld/OtherAssetsListController.scala index c584690df..7ca34adc2 100644 --- a/app/controllers/nonsipp/otherassetsheld/OtherAssetsListController.scala +++ b/app/controllers/nonsipp/otherassetsheld/OtherAssetsListController.scala @@ -225,7 +225,8 @@ class OtherAssetsListController @Inject()( def buildOtherAssets(index: Max5000): Either[Result, OtherAssetsData] = for { nameOfOtherAsset <- requiredPage(WhatIsOtherAssetPage(srn, index)) - } yield OtherAssetsData(index, nameOfOtherAsset) + canRemove = request.userAnswers.get(OtherAssetsPrePopulated(srn, index)).isEmpty + } yield OtherAssetsData(index, nameOfOtherAsset, canRemove) if (isPrePopulation) { for { @@ -278,7 +279,7 @@ object OtherAssetsListController { List() case (list, _) => list.map { - case OtherAssetsData(index, nameOfOtherAssets) => + case OtherAssetsData(index, nameOfOtherAssets, canRemove) => val otherAssetsMessage = Message("otherAssets.list.row", nameOfOtherAssets) (mode, viewOnlyViewModel) match { case (ViewOnlyMode, Some(ViewOnlyViewModel(_, year, current, previous, _))) => @@ -293,7 +294,7 @@ object OtherAssetsListController { url = routes.OtherAssetsCheckAndUpdateController.onPageLoad(srn, index).url, hiddenText = Message("site.check.param", Message("loansList.row", otherAssetsMessage)) ) - case _ => + case _ if canRemove => ListRow( text = otherAssetsMessage, changeUrl = routes.OtherAssetsCYAController.onPageLoad(srn, index, CheckMode).url, @@ -301,6 +302,12 @@ object OtherAssetsListController { removeUrl = routes.RemoveOtherAssetController.onPageLoad(srn, index, NormalMode).url, removeHiddenText = Message("otherAssets.list.row.remove.hiddenText", otherAssetsMessage) ) + case _ => + ListRow( + text = otherAssetsMessage, + changeUrl = routes.OtherAssetsCYAController.onPageLoad(srn, index, CheckMode).url, + changeHiddenText = Message("otherAssets.list.row.change.hiddenText", otherAssetsMessage) + ) } } } @@ -465,6 +472,7 @@ object OtherAssetsListController { case class OtherAssetsData( index: Max5000, - nameOfOtherAssets: String + nameOfOtherAssets: String, + canRemove: Boolean ) } diff --git a/app/controllers/nonsipp/otherassetsheld/RemoveOtherAssetController.scala b/app/controllers/nonsipp/otherassetsheld/RemoveOtherAssetController.scala index 2cea0ed5e..f896f3f6e 100644 --- a/app/controllers/nonsipp/otherassetsheld/RemoveOtherAssetController.scala +++ b/app/controllers/nonsipp/otherassetsheld/RemoveOtherAssetController.scala @@ -19,7 +19,7 @@ package controllers.nonsipp.otherassetsheld import services.{PsrSubmissionService, SaveService} import viewmodels.implicits._ import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} -import pages.nonsipp.otherassetsheld.{RemoveOtherAssetPage, WhatIsOtherAssetPage} +import pages.nonsipp.otherassetsheld.{OtherAssetsPrePopulated, RemoveOtherAssetPage, WhatIsOtherAssetPage} import controllers.actions._ import navigation.Navigator import forms.YesNoPageFormProvider @@ -54,21 +54,25 @@ class RemoveOtherAssetController @Inject()( def onPageLoad(srn: Srn, index: Max5000, mode: Mode): Action[AnyContent] = identifyAndRequireData(srn) { implicit request => - ( - for { - whatIsOtherAsset <- request.userAnswers.get(WhatIsOtherAssetPage(srn, index)).getOrRedirectToTaskList(srn) - } yield { - val preparedForm = - request.userAnswers.fillForm(RemoveOtherAssetPage(srn, index), form) - Ok( - view( - preparedForm, - RemoveOtherAssetController - .viewModel(srn, index, whatIsOtherAsset, mode) + if (request.userAnswers.get(OtherAssetsPrePopulated(srn, index)).isDefined) { + Redirect(controllers.routes.UnauthorisedController.onPageLoad()) + } else { + ( + for { + whatIsOtherAsset <- request.userAnswers.get(WhatIsOtherAssetPage(srn, index)).getOrRedirectToTaskList(srn) + } yield { + val preparedForm = + request.userAnswers.fillForm(RemoveOtherAssetPage(srn, index), form) + Ok( + view( + preparedForm, + RemoveOtherAssetController + .viewModel(srn, index, whatIsOtherAsset, mode) + ) ) - ) - } - ).merge + } + ).merge + } } def onSubmit(srn: Srn, index: Max5000, mode: Mode): Action[AnyContent] = diff --git a/app/pages/nonsipp/memberdetails/MemberDetailsPrePopulated.scala b/app/pages/nonsipp/memberdetails/MemberDetailsPrePopulated.scala new file mode 100644 index 000000000..068360fb7 --- /dev/null +++ b/app/pages/nonsipp/memberdetails/MemberDetailsPrePopulated.scala @@ -0,0 +1,3 @@ +package pages.nonsipp.memberdetails class MemberDetailsPrePopulated { + +} diff --git a/app/pages/nonsipp/otherassetsheld/OtherAssetsPrePopulated.scala b/app/pages/nonsipp/otherassetsheld/OtherAssetsPrePopulated.scala new file mode 100644 index 000000000..313153e84 --- /dev/null +++ b/app/pages/nonsipp/otherassetsheld/OtherAssetsPrePopulated.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 pages.nonsipp.otherassetsheld + +import utils.RefinedUtils.RefinedIntOps +import pages.QuestionPage +import config.RefinedTypes.Max5000 +import models.SchemeId.Srn +import play.api.libs.json.JsPath + +case class OtherAssetsPrePopulated(srn: Srn, index: Max5000) extends QuestionPage[Boolean] { + override def path: JsPath = Paths.otherAssets \ toString \ index.arrayIndex.toString + override def toString: String = "otherAssetsPrePopulated" +} diff --git a/app/prepop/OtherAssetsPrePopulationProcessor.scala b/app/prepop/OtherAssetsPrePopulationProcessor.scala index a0fb4c942..0cc385608 100644 --- a/app/prepop/OtherAssetsPrePopulationProcessor.scala +++ b/app/prepop/OtherAssetsPrePopulationProcessor.scala @@ -18,16 +18,17 @@ package prepop import pages.nonsipp.otherassetsdisposal.{OtherAssetsDisposalPage, OtherAssetsDisposalProgress} import pages.nonsipp.otherassetsheld._ -import models.UserAnswers.SensitiveJsObject -import config.RefinedTypes.OneTo5000 +import config.RefinedTypes.{Max5000, OneTo5000} import models.SchemeId.Srn import pages.nonsipp.otherassetsdisposal.Paths.assetsDisposed import eu.timepit.refined.refineV import models.UserAnswers +import utils.ListUtils.ListOps +import models.UserAnswers.SensitiveJsObject import pages.nonsipp.otherassetsheld.Paths.otherAssets import play.api.libs.json.{JsObject, JsSuccess} -import scala.util.{Success, Try} +import scala.util.Try import javax.inject.{Inject, Singleton} @@ -52,7 +53,23 @@ class OtherAssetsPrePopulationProcessor @Inject()() { .flatMap(_.transform((Paths.otherAssetsTransactions \ "movableSchedule29A").prune(_))) .flatMap(_.transform((Paths.otherAssetsTransactions \ "totalIncomeOrReceipts").prune(_))) match { case JsSuccess(value, _) => - Success(currentUA.copy(data = SensitiveJsObject(value.deepMerge(currentUA.data.decryptedValue)))) + val uaWithOtherAssetsData = + currentUA.copy(data = SensitiveJsObject(value.deepMerge(currentUA.data.decryptedValue))) + + val updatedUA = uaWithOtherAssetsData + .get(WhatIsOtherAssetPages(srn)) + .map(_.keys.toList) + .toList + .flatten + .refine[Max5000.Refined] + .map(index => OtherAssetsPrePopulated(srn, index)) + .foldLeft(Try(uaWithOtherAssetsData)) { + case (ua, otherAssetsPrePopulated) => { + ua.flatMap(_.set(otherAssetsPrePopulated, false)) + } + } + + updatedUA case _ => Try(currentUA) } diff --git a/app/transformations/OtherAssetsTransformer.scala b/app/transformations/OtherAssetsTransformer.scala index 7017c8d67..8a2fa82c9 100644 --- a/app/transformations/OtherAssetsTransformer.scala +++ b/app/transformations/OtherAssetsTransformer.scala @@ -83,6 +83,7 @@ class OtherAssetsTransformer @Inject() extends Transformer { assetDescription <- request.userAnswers.get(WhatIsOtherAssetPage(srn, index)) methodOfHolding <- request.userAnswers.get(WhyDoesSchemeHoldAssetsPage(srn, index)) costOfAsset <- request.userAnswers.get(CostOfOtherAssetPage(srn, index)) + prePopulated = request.userAnswers.get(OtherAssetsPrePopulated(srn, index)) } yield { val optNoneTransferRelatedDetails = buildOptNoneTransferRelatedDetails(methodOfHolding, srn, index) @@ -91,7 +92,7 @@ class OtherAssetsTransformer @Inject() extends Transformer { val optTotalIncomeOrReceipts = request.userAnswers.get(IncomeFromAssetPage(srn, index)) OtherAssetTransaction( - prePopulated = None, + prePopulated = prePopulated, assetDescription = assetDescription, methodOfHolding = methodOfHolding, optDateOfAcqOrContrib = optNoneTransferRelatedDetails.map(_._2), @@ -544,6 +545,16 @@ class OtherAssetsTransformer @Inject() extends Transformer { val otherAssetsCompleted = OtherAssetsCompleted(srn, index) -> SectionCompleted + val otherAssetsPrePopulated = indexes + .filter( + index => { + otherAssetTransactions(index.value - 1).prePopulated.nonEmpty + } + ) + .map( + index => OtherAssetsPrePopulated(srn, index) -> otherAssetTransactions(index.value - 1).prePopulated.get + ) + val triedUA = for { ua0 <- ua ua1 <- ua0.set(assetDescription._1, assetDescription._2) @@ -563,11 +574,14 @@ class OtherAssetsTransformer @Inject() extends Transformer { ua15 <- optUKPartnershipTuple.map(t => ua14.set(t._2._1, t._2._2)).getOrElse(Try(ua14)) ua16 <- optOther.map(t => ua15.set(t._1, t._2)).getOrElse(Try(ua15)) ua17 <- ua16.set(otherAssetsCompleted._1, otherAssetsCompleted._2) + ua18 <- otherAssetsPrePopulated.foldLeft(Try(ua17)) { + case (ua, (page, value)) => ua.flatMap(_.set(page, value)) + } } yield { buildOptDisposedOtherAssetsUA( index, srn, - ua17, + ua18, otherAssetTransaction.optOtherAssetDisposed ) } diff --git a/app/utils/nonsipp/check/OtherAssetsCheckStatusUtils.scala b/app/utils/nonsipp/check/OtherAssetsCheckStatusUtils.scala index dd8aba0d7..8e3eba0e7 100644 --- a/app/utils/nonsipp/check/OtherAssetsCheckStatusUtils.scala +++ b/app/utils/nonsipp/check/OtherAssetsCheckStatusUtils.scala @@ -59,8 +59,8 @@ object OtherAssetsCheckStatusUtils { } /** - * This method determines whether or not a Other Assets record needs to be checked. A record needs checking if any of - * the pre-populated-then-cleared answers are missing & all of the other answers are present. + * This method determines whether or not a Other Assets record needs to be checked. A record only needs to be checked + * if its OtherAssetsPrePopulated field is false. * @param userAnswers the answers provided by the user, from which we get the Other Assets record * @param srn the Scheme Reference Number, used for the .get calls * @param recordIndex the index of the record being checked @@ -70,6 +70,15 @@ object OtherAssetsCheckStatusUtils { userAnswers: UserAnswers, srn: Srn, recordIndex: Max5000 + ): Boolean = + userAnswers.get(OtherAssetsPrePopulated(srn, recordIndex)) match { + case Some(checked) => !checked + case None => checkotherAssetsRecordLegacy(userAnswers, srn, recordIndex) // non-pre-pop + } + def checkotherAssetsRecordLegacy( + userAnswers: UserAnswers, + srn: Srn, + recordIndex: Max5000 ): Boolean = { val anyPrePopClearedAnswersMissing: Boolean = ( userAnswers.get(IsAssetTangibleMoveablePropertyPage(srn, recordIndex)), diff --git a/test/controllers/nonsipp/otherassetsheld/OtherAssetsListControllerSpec.scala b/test/controllers/nonsipp/otherassetsheld/OtherAssetsListControllerSpec.scala index 1683ab67a..c711b5a0d 100644 --- a/test/controllers/nonsipp/otherassetsheld/OtherAssetsListControllerSpec.scala +++ b/test/controllers/nonsipp/otherassetsheld/OtherAssetsListControllerSpec.scala @@ -64,6 +64,14 @@ class OtherAssetsListControllerSpec extends ControllerBaseSpec { .unsafeSet(WhyDoesSchemeHoldAssetsPage(srn, index3of5000), Transfer) .unsafeSet(CostOfOtherAssetPage(srn, index3of5000), money) .unsafeSet(OtherAssetsCompleted(srn, index3of5000), SectionCompleted) + .unsafeSet(OtherAssetsPrePopulated(srn, index3of5000), false) + + private val userAnswersChecked = completedUserAnswers + .unsafeSet(WhatIsOtherAssetPage(srn, index3of5000), "otherAssetsChecked") + .unsafeSet(WhyDoesSchemeHoldAssetsPage(srn, index3of5000), Transfer) + .unsafeSet(CostOfOtherAssetPage(srn, index3of5000), money) + .unsafeSet(OtherAssetsCompleted(srn, index3of5000), SectionCompleted) + .unsafeSet(OtherAssetsPrePopulated(srn, index3of5000), true) private val page = 1 @@ -76,29 +84,42 @@ class OtherAssetsListControllerSpec extends ControllerBaseSpec { private val otherAssetsData: List[OtherAssetsData] = List( OtherAssetsData( index1of5000, - "nameOfOtherAsset1" + "nameOfOtherAsset1", + true ), OtherAssetsData( index2of5000, - "nameOfOtherAsset2" + "nameOfOtherAsset2", + true ) ) private val otherAssetsDataToCheck: List[OtherAssetsData] = List( OtherAssetsData( index3of5000, - "nameOfOtherAsset3" + "nameOfOtherAsset3", + false ) ) private val otherAssetsDataChanged: List[OtherAssetsData] = List( OtherAssetsData( index1of5000, - "changedNameOfOtherAsset" + "changedNameOfOtherAsset", + true ), OtherAssetsData( index2of5000, - "nameOfOtherAsset2" + "nameOfOtherAsset2", + true + ) + ) + + private val otherAssetsDataChecked: List[OtherAssetsData] = List( + OtherAssetsData( + index3of5000, + "otherAssetsChecked", + false ) ) @@ -187,7 +208,24 @@ class OtherAssetsListControllerSpec extends ControllerBaseSpec { isPrePop = true ) ) - }.withName("PrePop Journey")) + }.withName("PrePop Journey Not Checked")) + + act.like(renderViewWithPrePopSession(onPageLoad, userAnswersChecked) { implicit app => implicit request => + injected[ListView].apply( + form(new YesNoPageFormProvider()), + viewModel( + srn = srn, + page = page, + mode = NormalMode, + otherAssets = otherAssetsData ++ otherAssetsDataChecked, + otherAssetsToCheck = Nil, + schemeName = schemeName, + viewOnlyViewModel = None, + showBackLink = true, + isPrePop = true + ) + ) + }.withName("PrePop Journey Checked")) act.like( renderPrePopView(onPageLoad, OtherAssetsListPage(srn), true, completedUserAnswers) { diff --git a/test/controllers/nonsipp/otherassetsheld/RemoveOtherAssetControllerSpec.scala b/test/controllers/nonsipp/otherassetsheld/RemoveOtherAssetControllerSpec.scala index 830384844..4cdfb28ad 100644 --- a/test/controllers/nonsipp/otherassetsheld/RemoveOtherAssetControllerSpec.scala +++ b/test/controllers/nonsipp/otherassetsheld/RemoveOtherAssetControllerSpec.scala @@ -17,13 +17,13 @@ package controllers.nonsipp.otherassetsheld import services.PsrSubmissionService -import pages.nonsipp.otherassetsheld.WhatIsOtherAssetPage +import pages.nonsipp.otherassetsheld.{OtherAssetsPrePopulated, WhatIsOtherAssetPage} import controllers.nonsipp.otherassetsheld.RemoveOtherAssetController._ import play.api.inject.bind import views.html.YesNoPageView import eu.timepit.refined.refineMV import forms.YesNoPageFormProvider -import models.NormalMode +import models.{NormalMode, UserAnswers} import org.mockito.ArgumentMatchers.any import play.api.inject.guice.GuiceableModule import org.mockito.Mockito._ @@ -46,6 +46,9 @@ class RemoveOtherAssetControllerSpec extends ControllerBaseSpec { bind[PsrSubmissionService].toInstance(mockPsrSubmissionService) ) + val prePopUserAnswersChecked: UserAnswers = userAnswers.unsafeSet(OtherAssetsPrePopulated(srn, refineMV(1)), true) + val prePopUserAnswersNotChecked: UserAnswers = userAnswers.unsafeSet(OtherAssetsPrePopulated(srn, refineMV(1)), false) + override protected def beforeEach(): Unit = reset(mockPsrSubmissionService) @@ -77,5 +80,15 @@ class RemoveOtherAssetControllerSpec extends ControllerBaseSpec { act.like(journeyRecoveryPage(onSubmit).updateName("onSubmit" + _)) + act.like( + redirectToPage(onPageLoad, controllers.routes.UnauthorisedController.onPageLoad(), prePopUserAnswersChecked) + .updateName(_ + " - Block removing checked Pre-pop other assets") + ) + + act.like( + redirectToPage(onPageLoad, controllers.routes.UnauthorisedController.onPageLoad(), prePopUserAnswersNotChecked) + .updateName(_ + " - Block removing unchecked Pre-pop other assets") + ) + } } diff --git a/test/prepop/OtherAssetsPrePopulationProcessorSpec.scala b/test/prepop/OtherAssetsPrePopulationProcessorSpec.scala index 653d2e862..34d7abb56 100644 --- a/test/prepop/OtherAssetsPrePopulationProcessorSpec.scala +++ b/test/prepop/OtherAssetsPrePopulationProcessorSpec.scala @@ -40,6 +40,7 @@ class OtherAssetsPrePopulationProcessorSpec extends BaseSpec with TestValues { currentUA = currentUa )(srn) + result.get.data.decryptedValue mustBe cleanedSomeDisposalsData.as[JsObject] result mustBe Success( currentUa.copy(data = SensitiveJsObject(cleanedSomeDisposalsData.as[JsObject])) ) @@ -203,6 +204,7 @@ object OtherAssetsPrePopulationProcessorSpec { |{ | "assets": { | "otherAssets": { + | "otherAssetsPrePopulated":{"0":false,"1":false}, | "otherAssetTransactions": { | "assetDescription": { | "1": "100kg Gold bars" @@ -320,6 +322,7 @@ object OtherAssetsPrePopulationProcessorSpec { |{ | "assets": { | "otherAssets": { + | "otherAssetsPrePopulated":{"0":false,"1":false}, | "otherAssetTransactions": { | "assetDescription": { | "0": "Bag of matches", diff --git a/test/utils/nonsipp/check/OtherAssetsCheckStatusUtilsSpec.scala b/test/utils/nonsipp/check/OtherAssetsCheckStatusUtilsSpec.scala index 055b92b4b..243b0b6b0 100644 --- a/test/utils/nonsipp/check/OtherAssetsCheckStatusUtilsSpec.scala +++ b/test/utils/nonsipp/check/OtherAssetsCheckStatusUtilsSpec.scala @@ -29,8 +29,8 @@ import controllers.ControllerBaseSpec class OtherAssetsCheckStatusUtilsSpec extends ControllerBaseSpec with Matchers with OptionValues { - private val otherAssetsHeldTrue = defaultUserAnswers.unsafeSet(OtherAssetsHeldPage(srn), true) - private val otherAssetsHeldFalse = defaultUserAnswers.unsafeSet(OtherAssetsHeldPage(srn), false) + private val otherAssetsHeldTrueLegacy = defaultUserAnswers.unsafeSet(OtherAssetsHeldPage(srn), true) + private val otherAssetsHeldFalseLegacy = defaultUserAnswers.unsafeSet(OtherAssetsHeldPage(srn), false) private def addOtherAssetsBaseAnswers(index: Max5000, userAnswers: UserAnswers): UserAnswers = userAnswers @@ -94,7 +94,7 @@ class OtherAssetsCheckStatusUtilsSpec extends ControllerBaseSpec with Matchers w index1of5000, addOtherAssetsContributionAnswers( index1of5000, - otherAssetsHeldTrue + otherAssetsHeldTrueLegacy ) ) @@ -113,7 +113,7 @@ class OtherAssetsCheckStatusUtilsSpec extends ControllerBaseSpec with Matchers w index2of5000, addOtherAssetsPrePopAnswers( index2of5000, - otherAssetsHeldTrue + otherAssetsHeldTrueLegacy ) ) ) @@ -162,13 +162,13 @@ class OtherAssetsCheckStatusUtilsSpec extends ControllerBaseSpec with Matchers w "must be false" - { "when otherAssetsHeld is Some(false)" in { - val userAnswers = otherAssetsHeldFalse + val userAnswers = otherAssetsHeldFalseLegacy checkOtherAssetsSection(userAnswers, srn) mustBe false } "when otherAssetsHeld is Some(true) & no records are present" in { - val userAnswers = otherAssetsHeldTrue + val userAnswers = otherAssetsHeldTrueLegacy checkOtherAssetsSection(userAnswers, srn) mustBe false } @@ -181,7 +181,7 @@ class OtherAssetsCheckStatusUtilsSpec extends ControllerBaseSpec with Matchers w index1of5000, addOtherAssetsPrePopAnswers( index1of5000, - otherAssetsHeldTrue + otherAssetsHeldTrueLegacy ) ) ) @@ -227,7 +227,7 @@ class OtherAssetsCheckStatusUtilsSpec extends ControllerBaseSpec with Matchers w index1of5000, addOtherAssetsIndividualAnswers( index1of5000, - otherAssetsHeldTrue + otherAssetsHeldTrueLegacy ) ) ) @@ -243,7 +243,7 @@ class OtherAssetsCheckStatusUtilsSpec extends ControllerBaseSpec with Matchers w index1of5000, addOtherAssetsUKCompanyAnswers( index1of5000, - otherAssetsHeldTrue + otherAssetsHeldTrueLegacy ) ) ) @@ -259,7 +259,7 @@ class OtherAssetsCheckStatusUtilsSpec extends ControllerBaseSpec with Matchers w index1of5000, addOtherAssetsUKPartnershipAnswers( index1of5000, - otherAssetsHeldTrue + otherAssetsHeldTrueLegacy ) ) ) @@ -275,7 +275,7 @@ class OtherAssetsCheckStatusUtilsSpec extends ControllerBaseSpec with Matchers w index1of5000, addOtherAssetsOtherAnswers( index1of5000, - otherAssetsHeldTrue + otherAssetsHeldTrueLegacy ) ) ) @@ -289,7 +289,7 @@ class OtherAssetsCheckStatusUtilsSpec extends ControllerBaseSpec with Matchers w index1of5000, addOtherAssetsContributionAnswers( index1of5000, - otherAssetsHeldTrue + otherAssetsHeldTrueLegacy ) ) @@ -302,7 +302,7 @@ class OtherAssetsCheckStatusUtilsSpec extends ControllerBaseSpec with Matchers w index1of5000, addOtherAssetsTransferAnswers( index1of5000, - otherAssetsHeldTrue + otherAssetsHeldTrueLegacy ) ) @@ -316,7 +316,7 @@ class OtherAssetsCheckStatusUtilsSpec extends ControllerBaseSpec with Matchers w index1of5000, addOtherAssetsContributionAnswers( index1of5000, - otherAssetsHeldTrue + otherAssetsHeldTrueLegacy ) ).unsafeSet(IsAssetTangibleMoveablePropertyPage(srn, index1of5000), true) @@ -340,7 +340,7 @@ class OtherAssetsCheckStatusUtilsSpec extends ControllerBaseSpec with Matchers w index1of5000, addOtherAssetsIndividualAnswers( index1of5000, - otherAssetsHeldTrue + otherAssetsHeldTrueLegacy ) ) ).unsafeRemove(IdentityTypePage(srn, index1of5000, OtherAssetSeller)) @@ -356,7 +356,7 @@ class OtherAssetsCheckStatusUtilsSpec extends ControllerBaseSpec with Matchers w index1of5000, addOtherAssetsPrePopAnswers( index1of5000, - otherAssetsHeldTrue + otherAssetsHeldTrueLegacy ) ) ) @@ -370,7 +370,7 @@ class OtherAssetsCheckStatusUtilsSpec extends ControllerBaseSpec with Matchers w index1of5000, addOtherAssetsAcquisitionAnswers( index1of5000, - otherAssetsHeldTrue + otherAssetsHeldTrueLegacy ) ).unsafeSet(IdentityTypePage(srn, index1of5000, OtherAssetSeller), Individual) @@ -383,7 +383,7 @@ class OtherAssetsCheckStatusUtilsSpec extends ControllerBaseSpec with Matchers w index1of5000, addOtherAssetsAcquisitionAnswers( index1of5000, - otherAssetsHeldTrue + otherAssetsHeldTrueLegacy ) ).unsafeSet(IdentityTypePage(srn, index1of5000, OtherAssetSeller), UKCompany) @@ -396,7 +396,7 @@ class OtherAssetsCheckStatusUtilsSpec extends ControllerBaseSpec with Matchers w index1of5000, addOtherAssetsAcquisitionAnswers( index1of5000, - otherAssetsHeldTrue + otherAssetsHeldTrueLegacy ) ).unsafeSet(IdentityTypePage(srn, index1of5000, OtherAssetSeller), UKPartnership) @@ -409,7 +409,7 @@ class OtherAssetsCheckStatusUtilsSpec extends ControllerBaseSpec with Matchers w index1of5000, addOtherAssetsAcquisitionAnswers( index1of5000, - otherAssetsHeldTrue + otherAssetsHeldTrueLegacy ) ).unsafeSet(IdentityTypePage(srn, index1of5000, OtherAssetSeller), Other) @@ -417,4 +417,116 @@ class OtherAssetsCheckStatusUtilsSpec extends ControllerBaseSpec with Matchers w } } } + + private val otherAssetsHeldTrue = defaultUserAnswers.unsafeSet(OtherAssetsHeldPage(srn), true) + private val otherAssetsHeldFalse = defaultUserAnswers.unsafeSet(OtherAssetsHeldPage(srn), false) + + private def addNonPrePopRecord(index: Max5000, userAnswers: UserAnswers): UserAnswers = + addOtherAssetsBaseAnswers(index, userAnswers) + .unsafeSet(WhyDoesSchemeHoldAssetsPage(srn, index), SchemeHoldAsset.Acquisition) + .unsafeSet(IdentityTypePage(srn, index, OtherAssetSeller), Individual) + + private def addUncheckedRecord(index: Max5000, userAnswers: UserAnswers): UserAnswers = + addOtherAssetsBaseAnswers(index, userAnswers) + .unsafeSet(WhyDoesSchemeHoldAssetsPage(srn, index), SchemeHoldAsset.Contribution) + .unsafeSet(IdentityTypePage(srn, index, OtherAssetSeller), UKCompany) + .unsafeSet(OtherAssetsPrePopulated(srn, index), false) + + private def addCheckedRecord(index: Max5000, userAnswers: UserAnswers): UserAnswers = + addOtherAssetsBaseAnswers(index, userAnswers) + .unsafeSet(WhyDoesSchemeHoldAssetsPage(srn, index), SchemeHoldAsset.Transfer) + .unsafeSet(IdentityTypePage(srn, index, OtherAssetSeller), UKPartnership) + .unsafeSet(OtherAssetsPrePopulated(srn, index), true) + + "checkOtherAssetsSectionPre-Pop" - { + + "must be true" - { + + "when schemeHadBonds is None & 1 record is present (unchecked)" in { + val userAnswers = addUncheckedRecord(index1of5000, defaultUserAnswers) + + checkOtherAssetsSection(userAnswers, srn) mustBe true + } + + "when schemeHadLoans is Some(true) & 2 records are present (checked and unchecked)" in { + val userAnswers = addCheckedRecord(index1of5000, addUncheckedRecord(index2of5000, otherAssetsHeldTrue)) + + checkOtherAssetsSection(userAnswers, srn) mustBe true + } + + "when schemeHadLoans is Some(true) & 2 records are present (unchecked and non-pre-pop)" in { + val userAnswers = addUncheckedRecord(index1of5000, addNonPrePopRecord(index2of5000, otherAssetsHeldTrue)) + + checkOtherAssetsSection(userAnswers, srn) mustBe true + } + } + + "must be false" - { + + "when schemeHadLoans is None & no records are present" in { + val userAnswers = defaultUserAnswers + + checkOtherAssetsSection(userAnswers, srn) mustBe false + } + + "when schemeHadLoans is Some(false) & no records are present" in { + val userAnswers = otherAssetsHeldFalse + + checkOtherAssetsSection(userAnswers, srn) mustBe false + } + + "when schemeHadLoans is Some(true) & no records are present" in { + val userAnswers = otherAssetsHeldTrue + + checkOtherAssetsSection(userAnswers, srn) mustBe false + } + + "when schemeHadLoans is Some(true) & 1 record is present (checked)" in { + val userAnswers = addCheckedRecord(index1of5000, otherAssetsHeldTrue) + + checkOtherAssetsSection(userAnswers, srn) mustBe false + } + + "when schemeHadLoans is Some(true) & 1 record is present (non-pre-pop)" in { + val userAnswers = addNonPrePopRecord(index1of5000, otherAssetsHeldTrue) + + checkOtherAssetsSection(userAnswers, srn) mustBe false + } + + "when schemeHadLoans is Some(true) & 2 records are present (checked and non-pre-pop)" in { + val userAnswers = addCheckedRecord(index1of5000, addNonPrePopRecord(index2of5000, otherAssetsHeldTrue)) + + checkOtherAssetsSection(userAnswers, srn) mustBe false + } + } + } + + "checkLoansRecord" - { + + "must be true" - { + + "when record is (unchecked)" in { + val userAnswers = addUncheckedRecord(index1of5000, defaultUserAnswers) + + checkOtherAssetsRecord(userAnswers, srn, index1of5000) mustBe true + } + } + + "must be false" - { + + "when record is (checked)" in { + val userAnswers = addCheckedRecord(index1of5000, defaultUserAnswers) + + checkOtherAssetsRecord(userAnswers, srn, index1of5000) mustBe false + } + + "when record is (non-pre-pop)" in { + val userAnswers = addNonPrePopRecord(index1of5000, defaultUserAnswers) + + checkOtherAssetsRecord(userAnswers, srn, index1of5000) mustBe false + } + } + + } + }