Skip to content

Commit

Permalink
DDCE-4995 Remove quicklens (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
gastonracui authored Apr 26, 2024
1 parent 913d4ba commit 2a89904
Show file tree
Hide file tree
Showing 12 changed files with 180 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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
)
Expand Down
39 changes: 16 additions & 23 deletions test/uk/gov/hmrc/merchandiseinbaggage/CoreTestData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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))
Expand All @@ -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),
Expand All @@ -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"""{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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)
)
Expand All @@ -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)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand All @@ -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),
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading

0 comments on commit 2a89904

Please sign in to comment.