From 2a899040c4c5e53e3cbf4089ff33dc4ed24a809e Mon Sep 17 00:00:00 2001 From: gastonracui Date: Fri, 26 Apr 2024 15:09:57 +0100 Subject: [PATCH] DDCE-4995 Remove quicklens (#522) --- .../controllers/GoodsOriginController.scala | 6 +- .../controllers/GoodsVatRateController.scala | 6 +- .../SearchGoodsCountryController.scala | 6 +- .../merchandiseinbaggage/CoreTestData.scala | 39 ++--- .../CheckYourAnswersNewHandlerSpec.scala | 5 +- .../controllers/NavigatorSpec.scala | 19 ++- .../ReviewGoodsControllerSpec.scala | 3 +- .../model/core/CalculationResultsSpec.scala | 8 +- .../model/core/DeclarationSpec.scala | 14 +- .../model/core/ThresholdAllowanceSpec.scala | 34 ++-- .../service/MibServiceSpec.scala | 24 +-- .../view/ViewUtilsSpec.scala | 161 ++++++++++-------- 12 files changed, 180 insertions(+), 145 deletions(-) diff --git a/app/uk/gov/hmrc/merchandiseinbaggage/controllers/GoodsOriginController.scala b/app/uk/gov/hmrc/merchandiseinbaggage/controllers/GoodsOriginController.scala index a279da077..87fcb0073 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggage/controllers/GoodsOriginController.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggage/controllers/GoodsOriginController.scala @@ -25,7 +25,6 @@ import uk.gov.hmrc.merchandiseinbaggage.model.core.{ExportGoodsEntry, ImportGood import uk.gov.hmrc.merchandiseinbaggage.navigation._ import uk.gov.hmrc.merchandiseinbaggage.repositories.DeclarationJourneyRepository import uk.gov.hmrc.merchandiseinbaggage.views.html.GoodsOriginView -import com.softwaremill.quicklens._ import scala.concurrent.{ExecutionContext, Future} @@ -65,7 +64,10 @@ class GoodsOriginController @Inject() ( .nextPage( GoodsOriginRequest( request.declarationJourney, - request.goodsEntry.modify(_.when[ImportGoodsEntry].maybeProducedInEu).setTo(Some(producedInEu)), + request.goodsEntry match { + case entry: ImportGoodsEntry => entry.copy(maybeProducedInEu = Some(producedInEu)) + case _ => request.goodsEntry + }, idx, repo.upsert ) diff --git a/app/uk/gov/hmrc/merchandiseinbaggage/controllers/GoodsVatRateController.scala b/app/uk/gov/hmrc/merchandiseinbaggage/controllers/GoodsVatRateController.scala index 8bebb3e06..b8ed5c556 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggage/controllers/GoodsVatRateController.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggage/controllers/GoodsVatRateController.scala @@ -16,7 +16,6 @@ package uk.gov.hmrc.merchandiseinbaggage.controllers -import com.softwaremill.quicklens._ import javax.inject.{Inject, Singleton} import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} import uk.gov.hmrc.merchandiseinbaggage.config.AppConfig @@ -67,7 +66,10 @@ class GoodsVatRateController @Inject() ( .nextPage( GoodsVatRateRequest( request.declarationJourney, - request.goodsEntry.modify(_.when[ImportGoodsEntry].maybeGoodsVatRate).setTo(Some(goodsVatRate)), + request.goodsEntry match { + case entry: ImportGoodsEntry => entry.copy(maybeGoodsVatRate = Some(goodsVatRate)) + case _ => request.goodsEntry + }, idx, repo.upsert ) diff --git a/app/uk/gov/hmrc/merchandiseinbaggage/controllers/SearchGoodsCountryController.scala b/app/uk/gov/hmrc/merchandiseinbaggage/controllers/SearchGoodsCountryController.scala index f32d60e61..91efbf16e 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggage/controllers/SearchGoodsCountryController.scala +++ b/app/uk/gov/hmrc/merchandiseinbaggage/controllers/SearchGoodsCountryController.scala @@ -26,7 +26,6 @@ import uk.gov.hmrc.merchandiseinbaggage.navigation._ import uk.gov.hmrc.merchandiseinbaggage.repositories.DeclarationJourneyRepository import uk.gov.hmrc.merchandiseinbaggage.service.CountryService import uk.gov.hmrc.merchandiseinbaggage.views.html.SearchGoodsCountryView -import com.softwaremill.quicklens._ import scala.concurrent.{ExecutionContext, Future} @@ -70,7 +69,10 @@ class SearchGoodsCountryController @Inject() ( .nextPage( SearchGoodsCountryRequest( request.declarationJourney, - request.goodsEntry.modify(_.when[ExportGoodsEntry].maybeDestination).setTo(Some(country)), + request.goodsEntry match { + case entry: ExportGoodsEntry => entry.copy(maybeDestination = Some(country)) + case _ => request.goodsEntry + }, idx, repo.upsert ) diff --git a/test/uk/gov/hmrc/merchandiseinbaggage/CoreTestData.scala b/test/uk/gov/hmrc/merchandiseinbaggage/CoreTestData.scala index 403249ae8..ff2599c0b 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggage/CoreTestData.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggage/CoreTestData.scala @@ -16,7 +16,6 @@ package uk.gov.hmrc.merchandiseinbaggage -import com.softwaremill.quicklens._ import play.api.Application import play.api.i18n.Messages import uk.gov.hmrc.merchandiseinbaggage.config.AppConfig @@ -160,7 +159,7 @@ trait CoreTestData { val doverJourneyEntry: JourneyDetailsEntry = JourneyDetailsEntry("DVR", journeyDate) val heathrowJourneyEntry: JourneyDetailsEntry = JourneyDetailsEntry("LHR", journeyDate) - val anAddress = + val anAddress: Address = Address(Seq("1 Agent Drive", "Agent Town"), Some("AG1 5NT"), AddressLookupCountry("GB", Some("United Kingdom"))) val sparseCompleteDeclarationJourney: DeclarationJourney = @@ -189,24 +188,20 @@ trait CoreTestData { CalculationResult(aImportGoods, AmountInPence(10L), AmountInPence(5), AmountInPence(7), Some(aConversionRatePeriod)) val aCalculationResultOverThousand: CalculationResult = aCalculationResult - .modify(_.goods.producedInEu) - .setTo(YesNoDontKnow.Yes) - .modify(_.duty.value) - .setTo(140000) - .modify(_.vat.value) - .setTo(140000) - .modify(_.gbpAmount.value) - .setTo(140000) + .copy( + goods = aCalculationResult.goods.copy(producedInEu = YesNoDontKnow.Yes), + duty = aCalculationResult.duty.copy(value = 140000), + vat = aCalculationResult.vat.copy(value = 140000), + gbpAmount = aCalculationResult.gbpAmount.copy(value = 140000) + ) val aCalculationResultWithNothingToPay: CalculationResult = aCalculationResult - .modify(_.goods.producedInEu) - .setTo(YesNoDontKnow.Yes) - .modify(_.duty.value) - .setTo(0) - .modify(_.vat.value) - .setTo(0) - .modify(_.gbpAmount.value) - .setTo(0) + .copy( + goods = aCalculationResult.goods.copy(producedInEu = YesNoDontKnow.Yes), + duty = aCalculationResult.duty.copy(value = 0), + vat = aCalculationResult.vat.copy(value = 0), + gbpAmount = aCalculationResult.gbpAmount.copy(value = 0) + ) val aCalculationResultWithNoTax: CalculationResult = CalculationResult(aImportGoods, AmountInPence(100), AmountInPence(0), AmountInPence(0), Some(aConversionRatePeriod)) @@ -226,7 +221,7 @@ trait CoreTestData { val aCheckResponse: CheckResponse = CheckResponse(aEoriNumber, valid = true, Some(aCompanyDetails)) - val aAmendment = Amendment( + val aAmendment: Amendment = Amendment( 1, LocalDateTime.now.truncatedTo(ChronoUnit.MILLIS), DeclarationGoods(aGoods.copy(category = "more cheese") :: Nil), @@ -243,12 +238,10 @@ trait CoreTestData { ) val aAmendmentPaid = aAmendment - .modify(_.paymentStatus) - .setTo(Some(Paid)) + .copy(paymentStatus = Some(Paid)) val aAmendmentNotRequired = aAmendment - .modify(_.paymentStatus) - .setTo(Some(NotRequired)) + .copy(paymentStatus = Some(NotRequired)) def aSuccessCheckResponse(eoriNumber: String = aEoriNumber): String = s"""{ diff --git a/test/uk/gov/hmrc/merchandiseinbaggage/controllers/CheckYourAnswersNewHandlerSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggage/controllers/CheckYourAnswersNewHandlerSpec.scala index 19638543a..4f5cae129 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggage/controllers/CheckYourAnswersNewHandlerSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggage/controllers/CheckYourAnswersNewHandlerSpec.scala @@ -16,7 +16,6 @@ package uk.gov.hmrc.merchandiseinbaggage.controllers -import com.softwaremill.quicklens._ import org.mockito.ArgumentMatchersSugar.{any, eqTo} import org.mockito.MockitoSugar.{mock, when} import play.api.mvc.{Request, Result} @@ -107,9 +106,7 @@ class CheckYourAnswersNewHandlerSpec extends DeclarationJourneyControllerSpec wi givenADeclarationJourneyIsPersisted(journey) - val overThresholdGoods = aCalculationResponse - .modify(_.thresholdCheck) - .setTo(OverThreshold) + val overThresholdGoods = aCalculationResponse.copy(thresholdCheck = OverThreshold) implicit val request: Request[_] = buildGet(CheckYourAnswersController.onPageLoad.url, sessionId) diff --git a/test/uk/gov/hmrc/merchandiseinbaggage/controllers/NavigatorSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggage/controllers/NavigatorSpec.scala index 7039173e9..976d9370e 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggage/controllers/NavigatorSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggage/controllers/NavigatorSpec.scala @@ -16,7 +16,6 @@ package uk.gov.hmrc.merchandiseinbaggage.controllers -import com.softwaremill.quicklens._ import play.api.mvc.Call import uk.gov.hmrc.merchandiseinbaggage.controllers.routes._ import uk.gov.hmrc.merchandiseinbaggage.generators.PropertyBaseTables @@ -422,10 +421,11 @@ class NavigatorSpec extends DeclarationJourneyControllerSpec with PropertyBaseTa } s"navigate to ${CheckYourAnswersController.onPageLoad} if over for $newOrAmend & $importOrExport Yes and entries > 1" in new Navigator { - val twoSizeEntries: GoodsEntries = + val goodsEntries: GoodsEntries = GoodsEntries(if (importOrExport == Import) completedImportGoods else completedExportGoods) - .modify(_.entries) - .using(e => e.+:(e.head)) + val twoSizeEntries: GoodsEntries = + goodsEntries + .copy(entries = goodsEntries.entries :+ goodsEntries.entries.head) val journey: DeclarationJourney = completedDeclarationJourney.copy( @@ -452,10 +452,11 @@ class NavigatorSpec extends DeclarationJourneyControllerSpec with PropertyBaseTa } } s"navigate to ${CheckYourAnswersController.onPageLoad} if over for $newOrAmend & $importOrExport No and completed" in new Navigator { - val twoSizeEntries: GoodsEntries = + val goodsEntries: GoodsEntries = GoodsEntries(if (importOrExport == Import) completedImportGoods else completedExportGoods) - .modify(_.entries) - .using(e => e.+:(e.head)) + val twoSizeEntries: GoodsEntries = + goodsEntries + .copy(entries = goodsEntries.entries :+ goodsEntries.entries.head) val journey: DeclarationJourney = completedDeclarationJourney.copy( @@ -489,7 +490,7 @@ class NavigatorSpec extends DeclarationJourneyControllerSpec with PropertyBaseTa completedDeclarationJourney.copy(declarationType = importOrExport, journeyType = newOrAmend) val result: Future[Call] = nextPage( RetrieveDeclarationRequest( - Some(journey.toDeclaration.modify(_.paymentStatus).setTo(Some(Paid))), + Some(journey.toDeclaration.copy(paymentStatus = Some(Paid))), journey, _ => Future.successful(journey) ) @@ -516,7 +517,7 @@ class NavigatorSpec extends DeclarationJourneyControllerSpec with PropertyBaseTa completedDeclarationJourney.copy(declarationType = importOrExport, journeyType = newOrAmend) val result: Future[Call] = nextPage( RetrieveDeclarationRequest( - Some(journey.toDeclaration.modify(_.paymentStatus).setTo(None)), + Some(journey.toDeclaration.copy(paymentStatus = None)), journey, _ => Future.successful(journey) ) diff --git a/test/uk/gov/hmrc/merchandiseinbaggage/controllers/ReviewGoodsControllerSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggage/controllers/ReviewGoodsControllerSpec.scala index 4aa30bc8c..b93393671 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggage/controllers/ReviewGoodsControllerSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggage/controllers/ReviewGoodsControllerSpec.scala @@ -17,7 +17,6 @@ package uk.gov.hmrc.merchandiseinbaggage.controllers import cats.data.OptionT -import com.softwaremill.quicklens._ import org.mockito.ArgumentMatchersSugar.any import org.mockito.MockitoSugar.{mock, when} import play.api.mvc.Result @@ -63,7 +62,7 @@ class ReviewGoodsControllerSpec extends DeclarationJourneyControllerSpec with Pr val request = buildGet(ReviewGoodsController.onPageLoad.url, aSessionId) val allowance = if (importOrExport == Export) { - aThresholdAllowance.modify(_.currentGoods).setTo(entries.declarationGoodsIfComplete.get) + aThresholdAllowance.copy(currentGoods = entries.declarationGoodsIfComplete.get) } else { aThresholdAllowance } diff --git a/test/uk/gov/hmrc/merchandiseinbaggage/model/core/CalculationResultsSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggage/model/core/CalculationResultsSpec.scala index 4990d8370..db8847acb 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggage/model/core/CalculationResultsSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggage/model/core/CalculationResultsSpec.scala @@ -16,7 +16,6 @@ package uk.gov.hmrc.merchandiseinbaggage.model.core -import com.softwaremill.quicklens._ import uk.gov.hmrc.merchandiseinbaggage.model.api.calculation.{CalculationResult, CalculationResults} import uk.gov.hmrc.merchandiseinbaggage.model.api.{AmountInPence, YesNoDontKnow} import uk.gov.hmrc.merchandiseinbaggage.utils.DataModelEnriched._ @@ -40,7 +39,7 @@ class CalculationResultsSpec extends BaseSpec with CoreTestData { val calculationResultUSA: CalculationResult = CalculationResult( - aGoods.modify(_.producedInEu).setTo(YesNoDontKnow.No), + aGoods.copy(producedInEu = YesNoDontKnow.No), AmountInPence(20L), AmountInPence(10), AmountInPence(30), @@ -49,10 +48,11 @@ class CalculationResultsSpec extends BaseSpec with CoreTestData { val calculations = CalculationResults(Seq(calculationResultEU, calculationResultUSA)) + val firstResult = calculations.calculationResults.head.copy(gbpAmount = AmountInPence(100000)) + calculations.proofOfOriginNeeded mustBe true calculations - .modify(_.calculationResults.index(0).gbpAmount.value) - .setTo(100000) + .copy(calculationResults = firstResult +: calculations.calculationResults.tail) .proofOfOriginNeeded mustBe false } } diff --git a/test/uk/gov/hmrc/merchandiseinbaggage/model/core/DeclarationSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggage/model/core/DeclarationSpec.scala index a82ce962e..429d47410 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggage/model/core/DeclarationSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggage/model/core/DeclarationSpec.scala @@ -16,7 +16,6 @@ package uk.gov.hmrc.merchandiseinbaggage.model.core -import com.softwaremill.quicklens._ import play.api.libs.json.Json.{parse, toJson} import uk.gov.hmrc.merchandiseinbaggage.model.api.Declaration._ import uk.gov.hmrc.merchandiseinbaggage.model.api.DeclarationType.Import @@ -134,7 +133,7 @@ class DeclarationSpec extends BaseSpecWithApplication with CoreTestData { "DeclarationJourney" should { "serialise and de-serialise" in { - val journey = completedDeclarationJourney.modify(_.createdAt).using(_.withNano(0)) + val journey = completedDeclarationJourney.copy(createdAt = completedDeclarationJourney.createdAt.withNano(0)) parse(toJson(journey).toString()).validate[DeclarationJourney].get mustBe journey } @@ -452,16 +451,15 @@ class DeclarationSpec extends BaseSpecWithApplication with CoreTestData { ) val latestAmendment = - aAmendment.modify(_.dateOfAmendment).setTo(LocalDateTime.now().truncatedTo(ChronoUnit.MILLIS).minusMinutes(10)) + aAmendment.copy(dateOfAmendment = LocalDateTime.now().truncatedTo(ChronoUnit.MILLIS).minusMinutes(10)) declarationWithGoods.latestGoods mustBe declarationWithGoods.declarationGoods.goods declarationWithGoods - .modify(_.amendments) - .setTo( + .copy(amendments = Seq( - aAmendment.modify(_.dateOfAmendment).setTo(LocalDateTime.now().truncatedTo(ChronoUnit.MILLIS)), - aAmendment.modify(_.dateOfAmendment).setTo(LocalDateTime.now().truncatedTo(ChronoUnit.MILLIS).minusDays(1)), - aAmendment.modify(_.dateOfAmendment).setTo(LocalDateTime.now().truncatedTo(ChronoUnit.MILLIS).plusMinutes(1)), + aAmendment.copy(dateOfAmendment = LocalDateTime.now().truncatedTo(ChronoUnit.MILLIS)), + aAmendment.copy(dateOfAmendment = LocalDateTime.now().truncatedTo(ChronoUnit.MILLIS).minusDays(1)), + aAmendment.copy(dateOfAmendment = LocalDateTime.now().truncatedTo(ChronoUnit.MILLIS).plusMinutes(1)), latestAmendment ) ) diff --git a/test/uk/gov/hmrc/merchandiseinbaggage/model/core/ThresholdAllowanceSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggage/model/core/ThresholdAllowanceSpec.scala index 3563bda7e..3bb72c160 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggage/model/core/ThresholdAllowanceSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggage/model/core/ThresholdAllowanceSpec.scala @@ -16,27 +16,41 @@ package uk.gov.hmrc.merchandiseinbaggage.model.core -import com.softwaremill.quicklens._ +import uk.gov.hmrc.merchandiseinbaggage.model.api.calculation.CalculationResults +import uk.gov.hmrc.merchandiseinbaggage.model.api.{AmountInPence, DeclarationGoods} import uk.gov.hmrc.merchandiseinbaggage.model.core.ThresholdAllowance._ import uk.gov.hmrc.merchandiseinbaggage.{BaseSpec, CoreTestData} class ThresholdAllowanceSpec extends BaseSpec with CoreTestData { "return threshold allowance left for import" in { - val allowance = - aThresholdAllowance.modify(_.calculationResponse.results.calculationResults.each.gbpAmount.value).setTo(7179) + val allowanceGbpAmountOne = + aThresholdAllowance.calculationResponse.results.calculationResults.map(_.copy(gbpAmount = AmountInPence(7179))) + val allowanceGbpAmountTwo = + aThresholdAllowance.calculationResponse.results.calculationResults.map(_.copy(gbpAmount = AmountInPence(7180))) + + val allowanceOne = + aThresholdAllowance.copy( + calculationResponse = aThresholdAllowance.calculationResponse.copy( + results = CalculationResults(allowanceGbpAmountOne) + ) + ) + val allowanceTwo = - aThresholdAllowance.modify(_.calculationResponse.results.calculationResults.each.gbpAmount.value).setTo(7180) - allowance.allowanceLeft mustBe 2428.21 + aThresholdAllowance.copy( + calculationResponse = aThresholdAllowance.calculationResponse.copy( + results = CalculationResults(allowanceGbpAmountTwo) + ) + ) + + allowanceOne.allowanceLeft mustBe 2428.21 allowanceTwo.allowanceLeft mustBe 2428.20 } "return threshold allowance left for export" in { - val goodOne = aExportGoods.modify(_.purchaseDetails.amount).setTo("71.75") - val goodTwo = aExportGoods.modify(_.purchaseDetails.amount).setTo("70.00") - val allowance = aThresholdAllowance - .modify(_.allGoods.goods) - .setTo(Seq(goodOne, goodTwo)) + val goodOne = aExportGoods.copy(purchaseDetails = aExportGoods.purchaseDetails.copy(amount = "71.75")) + val goodTwo = aExportGoods.copy(purchaseDetails = aExportGoods.purchaseDetails.copy(amount = "70.00")) + val allowance = aThresholdAllowance.copy(allGoods = DeclarationGoods(Seq(goodOne, goodTwo))) allowance.allowanceLeft mustBe 2358.25 } diff --git a/test/uk/gov/hmrc/merchandiseinbaggage/service/MibServiceSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggage/service/MibServiceSpec.scala index c72c228ce..60e0348c3 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggage/service/MibServiceSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggage/service/MibServiceSpec.scala @@ -16,7 +16,6 @@ package uk.gov.hmrc.merchandiseinbaggage.service -import com.softwaremill.quicklens._ import org.mockito.ArgumentMatchersSugar.{any, eqTo} import org.mockito.MockitoSugar.{mock, reset, when} import org.mockito.invocation.InvocationOnMock @@ -101,7 +100,8 @@ class MibServiceSpec extends BaseSpecWithApplication with CoreTestData with Opti "check threshold allowance including existing declaration for amends" in { val entries: GoodsEntries = completedGoodsEntries(Import) val declarationId = aDeclarationId - val existingDeclaration = declaration.modify(_.amendments.each.paymentStatus).setTo(Some(Paid)) + val existingDeclaration = + declaration.copy(amendments = declaration.amendments.map(_.copy(paymentStatus = Some(Paid)))) val calculationResponse: CalculationResponse = CalculationResponse(CalculationResults(Seq(stubbedResult)), WithinThreshold) @@ -125,12 +125,12 @@ class MibServiceSpec extends BaseSpecWithApplication with CoreTestData with Opti s"add only goods in $Paid or $NotRequired status" in { val declarationId = aDeclarationId - val unknown = completedAmendment(Import).modify(_.paymentStatus).setTo(None) + val unknown = completedAmendment(Import).copy(paymentStatus = None) val expectedGoods = Seq(aImportGoods) - val plusUnsetStatus = declaration - .copy(declarationId = declarationId) - .modify(_.amendments) - .using(_ ++ Seq(unknown)) + val plusUnsetStatus = declaration.copy( + declarationId = declarationId, + amendments = declaration.amendments ++ Seq(unknown) + ) when(mockConnector.findDeclaration(any[DeclarationId])(any[HeaderCarrier])) .thenReturn(Future.successful(Some(plusUnsetStatus))) @@ -142,7 +142,7 @@ class MibServiceSpec extends BaseSpecWithApplication with CoreTestData with Opti "send a request for calculation including declared goods plus amendments goods" in { val amendments: Seq[Amendment] = aAmendment :: aAmendmentPaid :: aAmendmentNotRequired :: Nil - val foundDeclaration: Declaration = declaration.modify(_.amendments).setTo(amendments) + val foundDeclaration: Declaration = declaration.copy(amendments = amendments) val expectedTotalGoods: Seq[Goods] = foundDeclaration.declarationGoods.goods ++ aAmendmentPaid.goods.goods ++ aAmendmentNotRequired.goods.goods @@ -164,10 +164,10 @@ class MibServiceSpec extends BaseSpecWithApplication with CoreTestData with Opti "send a request for calculation including declared goods plus amendments goods for export" in { val amendments: Seq[Amendment] = aAmendment :: aAmendmentPaid :: aAmendmentNotRequired :: Nil val foundDeclaration: Declaration = declaration - .modify(_.declarationType) - .setTo(Export) - .modify(_.amendments) - .setTo(amendments) + .copy( + declarationType = Export, + amendments = amendments + ) val expectedTotalGoods: Seq[Goods] = foundDeclaration.declarationGoods.goods ++ amendments.flatMap(_.goods.goods) when(mockConnector.calculatePayments(any[Seq[CalculationRequest]])(any[HeaderCarrier])) diff --git a/test/uk/gov/hmrc/merchandiseinbaggage/view/ViewUtilsSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggage/view/ViewUtilsSpec.scala index bbaa1b39c..f4624e21e 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggage/view/ViewUtilsSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggage/view/ViewUtilsSpec.scala @@ -16,9 +16,8 @@ package uk.gov.hmrc.merchandiseinbaggage.view -import com.softwaremill.quicklens._ import uk.gov.hmrc.merchandiseinbaggage.model.api.DeclarationType.Export -import uk.gov.hmrc.merchandiseinbaggage.model.api.{NotRequired, Paid} +import uk.gov.hmrc.merchandiseinbaggage.model.api.{Amendment, NotRequired, Paid} import uk.gov.hmrc.merchandiseinbaggage.views.ViewUtils.proofOfOriginNeeded import uk.gov.hmrc.merchandiseinbaggage.{BaseSpec, CoreTestData} @@ -26,101 +25,129 @@ class ViewUtilsSpec extends BaseSpec with CoreTestData { "proofOfOriginNeeded" should { "true if Declaration > £1000 paid and no Amendments" in { - val decl = declaration - .modify(_.paymentStatus) - .setTo(Some(Paid)) - .modify(_.maybeTotalCalculationResult) - .setTo(Some(calculationResultsOverLimit)) + val decl = declaration.copy( + paymentStatus = Some(Paid), + maybeTotalCalculationResult = Some(calculationResultsOverLimit) + ) proofOfOriginNeeded(decl) mustBe true } "false if Declaration < £1000 paid and no Amendments" in { - val decl = declaration - .modify(_.paymentStatus) - .setTo(Some(Paid)) - .modify(_.maybeTotalCalculationResult) - .setTo(Some(calculationResultsUnderLimit)) + val decl = declaration.copy( + paymentStatus = Some(Paid), + maybeTotalCalculationResult = Some(calculationResultsUnderLimit) + ) proofOfOriginNeeded(decl) mustBe false } "true if Declaration and Amendments > £1000" in { - val decl = declarationWithAmendment - .modify(_.paymentStatus) - .setTo(Some(Paid)) - .modify(_.maybeTotalCalculationResult) - .setTo(Some(calculationResultsUnderLimit)) - .modify(_.amendments.at(0).paymentStatus) - .setTo(Some(Paid)) - .modify(_.amendments.at(0).maybeTotalCalculationResult) - .setTo(Some(calculationResultsOverLimit)) + val firstAmendmentModified = declarationWithAmendment.amendments.head.copy( + maybeTotalCalculationResult = Some(calculationResultsOverLimit), + paymentStatus = Some(Paid) + ) + + val decl = declarationWithAmendment.copy( + paymentStatus = Some(Paid), + maybeTotalCalculationResult = Some(calculationResultsUnderLimit), + amendments = firstAmendmentModified +: declarationWithAmendment.amendments.tail + ) proofOfOriginNeeded(decl) mustBe true } "false if Declaration paid and Amendments > £1000 but UNPAID" in { - val decl = declarationWithAmendment - .modify(_.paymentStatus) - .setTo(Some(Paid)) - .modify(_.maybeTotalCalculationResult) - .setTo(Some(calculationResultsUnderLimit)) - .modify(_.amendments.at(0).paymentStatus) - .setTo(None) - .modify(_.amendments.at(0).maybeTotalCalculationResult) - .setTo(Some(calculationResultsUnderLimit)) + val firstAmendmentModified = declarationWithAmendment.amendments.head.copy( + maybeTotalCalculationResult = Some(calculationResultsUnderLimit), + paymentStatus = None + ) + + val decl = declarationWithAmendment.copy( + paymentStatus = Some(Paid), + maybeTotalCalculationResult = Some(calculationResultsUnderLimit), + amendments = firstAmendmentModified +: declarationWithAmendment.amendments.tail + ) proofOfOriginNeeded(decl) mustBe false } "true if Declaration paid and 3 Amendments last > £1000" in { - val decl = declarationWith3Amendment - .modify(_.paymentStatus) - .setTo(Some(Paid)) - .modify(_.maybeTotalCalculationResult) - .setTo(Some(calculationResultsUnderLimit)) - .modify(_.amendments.at(0).paymentStatus) - .setTo(None) - .modify(_.amendments.at(0).maybeTotalCalculationResult) - .setTo(Some(calculationResultsUnderLimit)) - .modify(_.amendments.at(1).paymentStatus) - .setTo(None) - .modify(_.amendments.at(1).maybeTotalCalculationResult) - .setTo(Some(calculationResultsUnderLimit)) - .modify(_.amendments.at(2).paymentStatus) - .setTo(Some(Paid)) - .modify(_.amendments.at(2).maybeTotalCalculationResult) - .setTo(Some(calculationResultsOverLimit)) + val amendmentsModified: Seq[Amendment] = declarationWith3Amendment.amendments + .updated( + 0, + declarationWith3Amendment.amendments.head.copy( + paymentStatus = None, + maybeTotalCalculationResult = Some(calculationResultsUnderLimit) + ) + ) + .updated( + 1, + declarationWith3Amendment + .amendments(1) + .copy( + paymentStatus = None, + maybeTotalCalculationResult = Some(calculationResultsUnderLimit) + ) + ) + .updated( + 2, + declarationWith3Amendment + .amendments(2) + .copy( + paymentStatus = Some(Paid), + maybeTotalCalculationResult = Some(calculationResultsOverLimit) + ) + ) + + val decl = declarationWith3Amendment.copy( + paymentStatus = Some(Paid), + maybeTotalCalculationResult = Some(calculationResultsUnderLimit), + amendments = amendmentsModified + ) proofOfOriginNeeded(decl) mustBe true } "false if Declaration paid and 3 Amendments last No payment" in { - val decl = declarationWith3Amendment - .modify(_.paymentStatus) - .setTo(Some(Paid)) - .modify(_.maybeTotalCalculationResult) - .setTo(Some(calculationResultsUnderLimit)) - .modify(_.amendments.at(0).paymentStatus) - .setTo(None) - .modify(_.amendments.at(0).maybeTotalCalculationResult) - .setTo(Some(calculationResultsUnderLimit)) - .modify(_.amendments.at(1).paymentStatus) - .setTo(Some(Paid)) - .modify(_.amendments.at(1).maybeTotalCalculationResult) - .setTo(Some(calculationResultsUnderLimit)) - .modify(_.amendments.at(2).paymentStatus) - .setTo(Some(NotRequired)) - .modify(_.amendments.at(2).maybeTotalCalculationResult) - .setTo(Some(calculationResultsUnderLimit)) + val amendmentsModified: Seq[Amendment] = declarationWith3Amendment.amendments + .updated( + 0, + declarationWith3Amendment.amendments.head.copy( + paymentStatus = None, + maybeTotalCalculationResult = Some(calculationResultsUnderLimit) + ) + ) + .updated( + 1, + declarationWith3Amendment + .amendments(1) + .copy( + paymentStatus = Some(Paid), + maybeTotalCalculationResult = Some(calculationResultsUnderLimit) + ) + ) + .updated( + 2, + declarationWith3Amendment + .amendments(2) + .copy( + paymentStatus = Some(NotRequired), + maybeTotalCalculationResult = Some(calculationResultsUnderLimit) + ) + ) + + val decl = declarationWith3Amendment.copy( + paymentStatus = Some(Paid), + maybeTotalCalculationResult = Some(calculationResultsUnderLimit), + amendments = amendmentsModified + ) proofOfOriginNeeded(decl) mustBe true } "false if Declaration is Export" in { - val decl = declaration - .modify(_.declarationType) - .setTo(Export) + val decl = declaration.copy(declarationType = Export) proofOfOriginNeeded(decl) mustBe false }