From fd184a0882da0c7aa3b1bf3583986ab47d3d0235 Mon Sep 17 00:00:00 2001 From: Jamal Osman Date: Mon, 20 Feb 2023 21:52:42 +0000 Subject: [PATCH 1/2] CDSR-2174: add cross validation spec for c285 old vs new TIP05 mapping --- .../claim/SingleOverpaymentsClaim.scala | 2 +- .../C285MappingCrossValidationSpec.scala | 125 ++++++++++++++++++ 2 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 test/uk/gov/hmrc/cdsreimbursementclaim/services/tpi05/C285MappingCrossValidationSpec.scala diff --git a/app/uk/gov/hmrc/cdsreimbursementclaim/models/claim/SingleOverpaymentsClaim.scala b/app/uk/gov/hmrc/cdsreimbursementclaim/models/claim/SingleOverpaymentsClaim.scala index 8de2815f..775404ec 100644 --- a/app/uk/gov/hmrc/cdsreimbursementclaim/models/claim/SingleOverpaymentsClaim.scala +++ b/app/uk/gov/hmrc/cdsreimbursementclaim/models/claim/SingleOverpaymentsClaim.scala @@ -27,7 +27,7 @@ final case class SingleOverpaymentsClaim( claimantType: ClaimantType, claimantInformation: ClaimantInformation, basisOfClaim: BasisOfClaim, - whetherNorthernIreland: Boolean, + whetherNorthernIreland: Boolean, //Where is this used and why is it needed? additionalDetails: String, reimbursementClaims: Map[TaxCode, BigDecimal], reimbursementMethod: ReimbursementMethodAnswer, diff --git a/test/uk/gov/hmrc/cdsreimbursementclaim/services/tpi05/C285MappingCrossValidationSpec.scala b/test/uk/gov/hmrc/cdsreimbursementclaim/services/tpi05/C285MappingCrossValidationSpec.scala new file mode 100644 index 00000000..1992cc4f --- /dev/null +++ b/test/uk/gov/hmrc/cdsreimbursementclaim/services/tpi05/C285MappingCrossValidationSpec.scala @@ -0,0 +1,125 @@ +/* + * Copyright 2023 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 uk.gov.hmrc.cdsreimbursementclaim.services.tpi05 + +import org.scalactic.TypeCheckedTripleEquals +import org.scalatest.{Assertion, Assertions, Ignore, OptionValues} +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpec +import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks +import play.api.libs.json.Json +import uk.gov.hmrc.cdsreimbursementclaim.models.claim.{C285ClaimRequest, ClaimantInformation, ClaimantType, ClaimedReimbursement, DeclarantTypeAnswer, SingleOverpaymentsClaim, Street, TypeOfClaimAnswer} +import uk.gov.hmrc.cdsreimbursementclaim.models.eis.claim.{ContactInformation, EisSubmitClaimRequest} +import uk.gov.hmrc.cdsreimbursementclaim.models.eis.declaration.DisplayDeclaration +import uk.gov.hmrc.cdsreimbursementclaim.models.generators.C285ClaimGen._ +import uk.gov.hmrc.cdsreimbursementclaim.models.eis.declaration.response.NdrcDetails + +@Ignore +class C285MappingCrossValidationSpec + extends AnyWordSpec + with C285ClaimSupport + with ScalaCheckDrivenPropertyChecks + with Matchers + with OptionValues + with TypeCheckedTripleEquals { + + def toClaimantType(declarantType: DeclarantTypeAnswer): ClaimantType = + declarantType match { + case DeclarantTypeAnswer.Importer => ClaimantType.Consignee + case DeclarantTypeAnswer.AssociatedWithImporterCompany => ClaimantType.Declarant + case DeclarantTypeAnswer.AssociatedWithRepresentativeCompany => ClaimantType.User + } + + "The C285 claim old and new mappers " should { + + "produce the same TPI05 request for a single claim" in forAll { generatedRequest: C285ClaimRequest => + whenever(generatedRequest.claim.typeOfClaim === TypeOfClaimAnswer.Individual) { + val c285ClaimRequest = generatedRequest.copy(claim = generatedRequest.claim.copy(associatedMRNsAnswer = None)) + val tpi05RequestOld = c285ClaimToTPI05Mapper.map(c285ClaimRequest) + val declaration = c285ClaimRequest.claim.displayDeclaration.value + + val overpaymentsSingleRequest: (SingleOverpaymentsClaim, DisplayDeclaration, Option[DisplayDeclaration]) = ( + SingleOverpaymentsClaim( + movementReferenceNumber = c285ClaimRequest.claim.movementReferenceNumber, + duplicateMovementReferenceNumber = c285ClaimRequest.claim.duplicateMovementReferenceNumberAnswer, + claimantType = toClaimantType(c285ClaimRequest.claim.declarantTypeAnswer), + claimantInformation = ClaimantInformation( + c285ClaimRequest.signedInUserDetails.eori, + c285ClaimRequest.signedInUserDetails.contactName.value, + establishmentAddress = ContactInformation( + contactPerson = Some(c285ClaimRequest.claim.detailsRegisteredWithCdsAnswer.fullName), + addressLine1 = Some(c285ClaimRequest.claim.detailsRegisteredWithCdsAnswer.contactAddress.line1), + addressLine2 = c285ClaimRequest.claim.detailsRegisteredWithCdsAnswer.contactAddress.line2, + addressLine3 = c285ClaimRequest.claim.detailsRegisteredWithCdsAnswer.contactAddress.line3, + street = Street.fromLines( + Some(c285ClaimRequest.claim.detailsRegisteredWithCdsAnswer.contactAddress.line1), + c285ClaimRequest.claim.detailsRegisteredWithCdsAnswer.contactAddress.line2 + ), + city = Some(c285ClaimRequest.claim.detailsRegisteredWithCdsAnswer.contactAddress.line4), + countryCode = Some(c285ClaimRequest.claim.detailsRegisteredWithCdsAnswer.contactAddress.country.code), + postalCode = Some(c285ClaimRequest.claim.detailsRegisteredWithCdsAnswer.contactAddress.postcode.value), + telephoneNumber = None, + faxNumber = None, + emailAddress = Some(c285ClaimRequest.claim.detailsRegisteredWithCdsAnswer.emailAddress.value) + ), + contactInformation = c285ClaimRequest.claim.contactInformation + ), + basisOfClaim = c285ClaimRequest.claim.basisOfClaimAnswer, + whetherNorthernIreland = true, + additionalDetails = c285ClaimRequest.claim.additionalDetailsAnswer.value, + reimbursementClaims = + c285ClaimRequest.claim.claimedReimbursementsAnswer.map(c => (c.taxCode, c.claimAmount)).toList.toMap, + reimbursementMethod = c285ClaimRequest.claim.reimbursementMethodAnswer, + bankAccountDetails = c285ClaimRequest.claim.bankAccountDetailsAnswer, + supportingEvidences = c285ClaimRequest.claim.documents.toList.flatten + ), + declaration.copy( + declaration.displayResponseDetail.copy(ndrcDetails = + Some( + c285ClaimRequest.claim.claims + .map(x => + NdrcDetails(x.taxCode.value, x.paidAmount.toString(), x.paymentMethod, x.paymentReference, None) + ) + .toList + ) + ) + ), + c285ClaimRequest.claim.duplicateDisplayDeclaration.map(dup => + dup.copy( + dup.displayResponseDetail.copy(ndrcDetails = + Some( + c285ClaimRequest.claim.claims + .map(x => + NdrcDetails(x.taxCode.value, x.paidAmount.toString(), x.paymentMethod, x.paymentReference, None) + ) + .toList + ) + ) + ) + ) + ) + val tpi05RequestNew = overpaymentsSingleClaimToTPI05Mapper.map(overpaymentsSingleRequest) + + tpi05RequestOld.isRight shouldBe tpi05RequestNew.isRight + Json.toJson(tpi05RequestOld.toOption.value.postNewClaimsRequest.requestDetail) shouldBe Json.toJson( + tpi05RequestNew.toOption.value.postNewClaimsRequest.requestDetail + ) + } + } + + } +} From 981fb2e2280faa77621aa4c43515ec7e1f4b1194 Mon Sep 17 00:00:00 2001 From: Jamal Osman Date: Mon, 27 Feb 2023 13:37:13 +0000 Subject: [PATCH 2/2] CDSR-2174: update code to use same email and claimant name as legacy --- .../controllers/SubmitClaimController.scala | 2 +- .../actions/AuthenticateWithUserActions.scala | 21 ++-- .../models/eis/claim/EORIInformation.scala | 34 +++--- .../services/ClaimService.scala | 16 ++- ...OverpaymentsSingleClaimToEmailMapper.scala | 7 +- ...rpaymentsScheduledClaimToTPI05Mapper.scala | 5 +- ...OverpaymentsSingleClaimToTPI05Mapper.scala | 32 +++--- .../gov/hmrc/cdsreimbursementclaim/Fake.scala | 4 +- .../SubmitClaimControllerSpec.scala | 6 +- .../generators/OverpaymentsClaimGen.scala | 24 +++-- .../services/ClaimServiceSpec.scala | 13 +-- .../C285MappingCrossValidationSpec.scala | 101 +++++------------- .../OverpaymentsSingleClaimMappingSpec.scala | 8 +- 13 files changed, 133 insertions(+), 140 deletions(-) diff --git a/app/uk/gov/hmrc/cdsreimbursementclaim/controllers/SubmitClaimController.scala b/app/uk/gov/hmrc/cdsreimbursementclaim/controllers/SubmitClaimController.scala index 301488b1..1e464b20 100644 --- a/app/uk/gov/hmrc/cdsreimbursementclaim/controllers/SubmitClaimController.scala +++ b/app/uk/gov/hmrc/cdsreimbursementclaim/controllers/SubmitClaimController.scala @@ -57,7 +57,7 @@ class SubmitClaimController @Inject() ( final val submitSingleOverpaymentsClaim: Action[JsValue] = authenticate(parse.json).async { implicit request => withJsonBody[SingleOverpaymentsClaimRequest] { uploadDocumentsOnce { - claimService.submitSingleOverpaymentsClaim(_) + claimService.submitSingleOverpaymentsClaim(_, request.user) } } } diff --git a/app/uk/gov/hmrc/cdsreimbursementclaim/controllers/actions/AuthenticateWithUserActions.scala b/app/uk/gov/hmrc/cdsreimbursementclaim/controllers/actions/AuthenticateWithUserActions.scala index 11ec6205..9fade4e0 100644 --- a/app/uk/gov/hmrc/cdsreimbursementclaim/controllers/actions/AuthenticateWithUserActions.scala +++ b/app/uk/gov/hmrc/cdsreimbursementclaim/controllers/actions/AuthenticateWithUserActions.scala @@ -16,6 +16,7 @@ package uk.gov.hmrc.cdsreimbursementclaim.controllers.actions +import cats.implicits.catsSyntaxTuple2Semigroupal import com.google.inject.ImplementedBy import play.api.mvc._ import uk.gov.hmrc.auth.core.AuthProvider.GovernmentGateway @@ -23,12 +24,12 @@ import uk.gov.hmrc.auth.core._ import uk.gov.hmrc.auth.core.retrieve._ import uk.gov.hmrc.http.HeaderCarrier import uk.gov.hmrc.play.bootstrap.backend.controller.BackendHeaderCarrierProvider - +import uk.gov.hmrc.cdsreimbursementclaim.models.email.{Email => CdsEmail} import java.time.LocalDateTime import javax.inject.Inject import scala.concurrent.{ExecutionContext, Future} -final case class AuthenticatedUser(ggCredId: String) +final case class AuthenticatedUser(ggCredId: String, name: Option[String], email: Option[CdsEmail]) class AuthenticatedUserRequest[+A]( val user: AuthenticatedUser, val timestamp: LocalDateTime, @@ -54,10 +55,18 @@ class AuthenticateWithUserActionBuilder @Inject() ( val forbidden = Results.Forbidden("Forbidden") val carrier = hc(request) authorised(AuthProviders(GovernmentGateway)) - .retrieve(v2.Retrievals.credentials) { - case Some(credentials) => - val user = AuthenticatedUser(credentials.providerId) - block(new AuthenticatedUserRequest[A](user, LocalDateTime.now(), carrier, request)) + .retrieve(v2.Retrievals.credentials and v2.Retrievals.name and v2.Retrievals.email) { + case Some(credentials) ~ name ~ email => + val user = AuthenticatedUser( + credentials.providerId, + name.flatMap(x => (x.name, x.lastName).mapN((name, lastName) => s"$name $lastName")), + email.map(CdsEmail.apply) + ) + block(new AuthenticatedUserRequest[A]( + user, + LocalDateTime.now(), + carrier, + request)) case _ => Future.successful(forbidden) }(carrier, executionContext) .recover { case _: NoActiveSession => diff --git a/app/uk/gov/hmrc/cdsreimbursementclaim/models/eis/claim/EORIInformation.scala b/app/uk/gov/hmrc/cdsreimbursementclaim/models/eis/claim/EORIInformation.scala index a71691a7..cdc7e9c8 100644 --- a/app/uk/gov/hmrc/cdsreimbursementclaim/models/eis/claim/EORIInformation.scala +++ b/app/uk/gov/hmrc/cdsreimbursementclaim/models/eis/claim/EORIInformation.scala @@ -19,6 +19,7 @@ package uk.gov.hmrc.cdsreimbursementclaim.models.eis.claim import play.api.libs.json.{Json, OFormat} import uk.gov.hmrc.cdsreimbursementclaim.models.claim.{Country, Street} import uk.gov.hmrc.cdsreimbursementclaim.models.eis.declaration.response.{ConsigneeDetails, ContactDetails, DeclarantDetails} +import uk.gov.hmrc.cdsreimbursementclaim.models.email.Email import uk.gov.hmrc.cdsreimbursementclaim.models.{Error => CdsError} import uk.gov.hmrc.cdsreimbursementclaim.models.ids.Eori @@ -135,29 +136,26 @@ object EORIInformation { def forDeclarant( declarantDetails: DeclarantDetails, - contactInformation: Option[ContactInformation] - ): Either[CdsError, EORIInformation] = - for { - countryCode <- declarantDetails.contactDetails - .flatMap(_.countryCode) - .toRight(CdsError("Country code not present in ACC14 response")) - } yield EORIInformation( + contactInformation: Option[ContactInformation], + verifiedEmail: Option[Email] + ): EORIInformation = + EORIInformation( EORINumber = declarantDetails.EORI, CDSFullName = declarantDetails.legalName, CDSEstablishmentAddress = Address( - contactPerson = declarantDetails.contactDetails.flatMap(_.contactName), - addressLine1 = declarantDetails.contactDetails.flatMap(_.addressLine1), - addressLine2 = declarantDetails.contactDetails.flatMap(_.addressLine2), - addressLine3 = declarantDetails.contactDetails.flatMap(_.addressLine3), + contactPerson = Some(declarantDetails.legalName), + addressLine1 = Some(declarantDetails.establishmentAddress.addressLine1), + addressLine2 = declarantDetails.establishmentAddress.addressLine2, + addressLine3 = None, street = Street.fromLines( - declarantDetails.contactDetails.flatMap(_.addressLine1), - declarantDetails.contactDetails.flatMap(_.addressLine2) + Some(declarantDetails.establishmentAddress.addressLine1), + declarantDetails.establishmentAddress.addressLine2 ), - city = declarantDetails.contactDetails.flatMap(_.addressLine4), - postalCode = declarantDetails.contactDetails.flatMap(_.postalCode), - countryCode = countryCode, - telephoneNumber = None, // declarantDetails.contactDetails.flatMap(_.telephone), - emailAddress = declarantDetails.contactDetails.flatMap(_.emailAddress) + city = declarantDetails.establishmentAddress.addressLine3, + postalCode = declarantDetails.establishmentAddress.postalCode, + countryCode = declarantDetails.establishmentAddress.countryCode, + telephoneNumber = None, + emailAddress = verifiedEmail.map(_.value) ), contactInformation = contactInformation ) diff --git a/app/uk/gov/hmrc/cdsreimbursementclaim/services/ClaimService.scala b/app/uk/gov/hmrc/cdsreimbursementclaim/services/ClaimService.scala index ca88b5d1..ddfdb7bb 100644 --- a/app/uk/gov/hmrc/cdsreimbursementclaim/services/ClaimService.scala +++ b/app/uk/gov/hmrc/cdsreimbursementclaim/services/ClaimService.scala @@ -28,6 +28,7 @@ import play.api.libs.json.Format import play.api.libs.json.Json import play.api.mvc.Request import uk.gov.hmrc.cdsreimbursementclaim.connectors.ClaimConnector +import uk.gov.hmrc.cdsreimbursementclaim.controllers.actions.AuthenticatedUser import uk.gov.hmrc.cdsreimbursementclaim.metrics.Metrics import uk.gov.hmrc.cdsreimbursementclaim.models.Error import uk.gov.hmrc.cdsreimbursementclaim.models.claim.{C285ClaimRequest, ClaimSubmitResponse, MultipleOverpaymentsClaimRequest, MultipleRejectedGoodsClaim, RejectedGoodsClaim, RejectedGoodsClaimRequest, ScheduledOverpaymentsClaimRequest, ScheduledRejectedGoodsClaim, SecuritiesClaim, SecuritiesClaimRequest, SingleOverpaymentsClaimRequest} @@ -39,7 +40,7 @@ import uk.gov.hmrc.cdsreimbursementclaim.models.eis.declaration.DisplayDeclarati import uk.gov.hmrc.cdsreimbursementclaim.models.ids.MRN import uk.gov.hmrc.cdsreimbursementclaim.services.audit.AuditService import uk.gov.hmrc.cdsreimbursementclaim.services.email.{ClaimToEmailMapper, OverpaymentsMultipleClaimToEmailMapper, OverpaymentsScheduledClaimToEmailMapper, OverpaymentsSingleClaimToEmailMapper} -import uk.gov.hmrc.cdsreimbursementclaim.services.tpi05.{ClaimToTPI05Mapper, OverpaymentsMultipleClaimToTPI05Mapper, OverpaymentsScheduledClaimToTPI05Mapper, OverpaymentsSingleClaimToTPI05Mapper} +import uk.gov.hmrc.cdsreimbursementclaim.services.tpi05.{ClaimToTPI05Mapper, OverpaymentsMultipleClaimToTPI05Mapper, OverpaymentsScheduledClaimToTPI05Mapper, OverpaymentsSingleClaimData, OverpaymentsSingleClaimToTPI05Mapper} import uk.gov.hmrc.cdsreimbursementclaim.utils.HttpResponseOps.HttpResponseOps import uk.gov.hmrc.cdsreimbursementclaim.utils.Logging import uk.gov.hmrc.http.HeaderCarrier @@ -65,7 +66,8 @@ trait ClaimService { ): EitherT[Future, Error, ClaimSubmitResponse] def submitSingleOverpaymentsClaim( - singleOverpaymentsClaim: SingleOverpaymentsClaimRequest + singleOverpaymentsClaim: SingleOverpaymentsClaimRequest, + user: AuthenticatedUser )(implicit hc: HeaderCarrier, request: Request[_], @@ -148,7 +150,8 @@ class DefaultClaimService @Inject() ( proceed(c285ClaimRequest, c285ClaimRequest) def submitSingleOverpaymentsClaim( - claimRequest: SingleOverpaymentsClaimRequest + claimRequest: SingleOverpaymentsClaimRequest, + user: AuthenticatedUser )(implicit hc: HeaderCarrier, request: Request[_], @@ -169,7 +172,12 @@ class DefaultClaimService @Inject() ( .map(_.some) ) } - result <- proceed((claimRequest.claim, declaration, maybeDuplicateDeclaratiion), claimRequest) + result <- proceed(OverpaymentsSingleClaimData( + claimRequest.claim, + declaration, + maybeDuplicateDeclaratiion, + user + ), claimRequest) } yield result def submitMultipleOverpaymentsClaim( diff --git a/app/uk/gov/hmrc/cdsreimbursementclaim/services/email/OverpaymentsSingleClaimToEmailMapper.scala b/app/uk/gov/hmrc/cdsreimbursementclaim/services/email/OverpaymentsSingleClaimToEmailMapper.scala index c4c0ee2d..b5941dda 100644 --- a/app/uk/gov/hmrc/cdsreimbursementclaim/services/email/OverpaymentsSingleClaimToEmailMapper.scala +++ b/app/uk/gov/hmrc/cdsreimbursementclaim/services/email/OverpaymentsSingleClaimToEmailMapper.scala @@ -20,13 +20,14 @@ import uk.gov.hmrc.cdsreimbursementclaim.models.claim.SingleOverpaymentsClaim import uk.gov.hmrc.cdsreimbursementclaim.models.eis.declaration.DisplayDeclaration import uk.gov.hmrc.cdsreimbursementclaim.models.email.{Email, EmailRequest} import uk.gov.hmrc.cdsreimbursementclaim.models.{Error => CdsError} +import uk.gov.hmrc.cdsreimbursementclaim.services.tpi05.OverpaymentsSingleClaimData class OverpaymentsSingleClaimToEmailMapper - extends ClaimToEmailMapper[(SingleOverpaymentsClaim, DisplayDeclaration, Option[DisplayDeclaration])] { + extends ClaimToEmailMapper[OverpaymentsSingleClaimData] { override def map( - claim: (SingleOverpaymentsClaim, DisplayDeclaration, Option[DisplayDeclaration]) + claim: OverpaymentsSingleClaimData ): Either[CdsError, EmailRequest] = { - val (overpaymentsClaim, _, _) = claim + val OverpaymentsSingleClaimData(overpaymentsClaim, _, _, _) = claim for { email <- overpaymentsClaim.claimantInformation.contactInformation.emailAddress.toRight( CdsError("no email address provided with claim") diff --git a/app/uk/gov/hmrc/cdsreimbursementclaim/services/tpi05/OverpaymentsScheduledClaimToTPI05Mapper.scala b/app/uk/gov/hmrc/cdsreimbursementclaim/services/tpi05/OverpaymentsScheduledClaimToTPI05Mapper.scala index 470b8f39..a483b50a 100644 --- a/app/uk/gov/hmrc/cdsreimbursementclaim/services/tpi05/OverpaymentsScheduledClaimToTPI05Mapper.scala +++ b/app/uk/gov/hmrc/cdsreimbursementclaim/services/tpi05/OverpaymentsScheduledClaimToTPI05Mapper.scala @@ -45,9 +45,10 @@ class OverpaymentsScheduledClaimToTPI05Mapper importerEori <- declaration.displayResponseDetail.consigneeDetails .map(EORIInformation.forConsignee) .toRight(CdsError("Could not deduce consignee EORI information")) - agentEori <- EORIInformation.forDeclarant( + agentEori = EORIInformation.forDeclarant( declaration.displayResponseDetail.declarantDetails, - Some(claim.claimantInformation.contactInformation) + Some(claim.claimantInformation.contactInformation), + Some(Email("")) ) eoriDetails = EoriDetails( importerEORIDetails = importerEori, diff --git a/app/uk/gov/hmrc/cdsreimbursementclaim/services/tpi05/OverpaymentsSingleClaimToTPI05Mapper.scala b/app/uk/gov/hmrc/cdsreimbursementclaim/services/tpi05/OverpaymentsSingleClaimToTPI05Mapper.scala index 07f3bffc..ae073fd2 100644 --- a/app/uk/gov/hmrc/cdsreimbursementclaim/services/tpi05/OverpaymentsSingleClaimToTPI05Mapper.scala +++ b/app/uk/gov/hmrc/cdsreimbursementclaim/services/tpi05/OverpaymentsSingleClaimToTPI05Mapper.scala @@ -17,11 +17,9 @@ package uk.gov.hmrc.cdsreimbursementclaim.services.tpi05 import cats.implicits.catsSyntaxEq -import uk.gov.hmrc.cdsreimbursementclaim.models.claim.ClaimantType -import uk.gov.hmrc.cdsreimbursementclaim.models.claim.SingleOverpaymentsClaim -import uk.gov.hmrc.cdsreimbursementclaim.models.claim.TaxCode -import uk.gov.hmrc.cdsreimbursementclaim.models.claim.TypeOfClaimAnswer -import uk.gov.hmrc.cdsreimbursementclaim.models.eis.claim._ +import uk.gov.hmrc.cdsreimbursementclaim.controllers.actions.AuthenticatedUser +import uk.gov.hmrc.cdsreimbursementclaim.models.claim.{ClaimantType, SingleOverpaymentsClaim, TaxCode, TypeOfClaimAnswer} +import uk.gov.hmrc.cdsreimbursementclaim.models.eis.claim.{EisSubmitClaimRequest, _} import uk.gov.hmrc.cdsreimbursementclaim.models.eis.claim.enums.CaseType import uk.gov.hmrc.cdsreimbursementclaim.models.eis.claim.enums.ClaimType.C285 import uk.gov.hmrc.cdsreimbursementclaim.models.eis.claim.enums.Claimant @@ -35,15 +33,22 @@ import uk.gov.hmrc.cdsreimbursementclaim.models.{Error => CdsError} import uk.gov.hmrc.cdsreimbursementclaim.utils.BigDecimalOps // todo CDSR-1795 TPI05 creation and validation - factor out common code +case class OverpaymentsSingleClaimData( + claim: SingleOverpaymentsClaim, + declaration: DisplayDeclaration, + duplicateDeclaration: Option[DisplayDeclaration], + user: AuthenticatedUser +) + class OverpaymentsSingleClaimToTPI05Mapper - extends ClaimToTPI05Mapper[(SingleOverpaymentsClaim, DisplayDeclaration, Option[DisplayDeclaration])] { + extends ClaimToTPI05Mapper[OverpaymentsSingleClaimData] { @SuppressWarnings(Array("org.wartremover.warts.Option2Iterable")) override def map( - details: (SingleOverpaymentsClaim, DisplayDeclaration, Option[DisplayDeclaration]) + claimData: OverpaymentsSingleClaimData ): Either[CdsError, EisSubmitClaimRequest] = { - val (claim, declaration, duplicateDeclaration) = details - val contactInfo = claim.claimantInformation.contactInformation + val OverpaymentsSingleClaimData(claim, declaration, duplicateDeclaration, user) = claimData + val contactInfo = claim.claimantInformation.contactInformation (for { claimantEmail <- contactInfo.emailAddress.toRight( @@ -55,9 +60,10 @@ class OverpaymentsSingleClaimToTPI05Mapper importerEori <- declaration.displayResponseDetail.consigneeDetails .map(EORIInformation.forConsignee) .toRight(CdsError("Could not deduce consignee EORI information")) - agentEori <- EORIInformation.forDeclarant( + agentEori = EORIInformation.forDeclarant( declaration.displayResponseDetail.declarantDetails, - Some(claim.claimantInformation.contactInformation) + Some(claim.claimantInformation.contactInformation), + user.email//TODO: get signedInUserDetails.verifiedEmail ) eoriDetails = EoriDetails( importerEORIDetails = importerEori, @@ -66,8 +72,8 @@ class OverpaymentsSingleClaimToTPI05Mapper } yield TPI05 .request( claimantEORI = claim.claimantInformation.eori, - claimantEmailAddress = Email(claimantEmail), - claimantName = contactPerson + claimantEmailAddress = Email(""), //signedInUserDetails.verifiedEmail, + claimantName = "" //signedInUserDetails.contactName.value ) .forClaimOfType(Some(C285)) .withClaimant(Claimant.basedOn(claim.claimantType)) diff --git a/test/uk/gov/hmrc/cdsreimbursementclaim/Fake.scala b/test/uk/gov/hmrc/cdsreimbursementclaim/Fake.scala index 33fc4852..ed970e9a 100644 --- a/test/uk/gov/hmrc/cdsreimbursementclaim/Fake.scala +++ b/test/uk/gov/hmrc/cdsreimbursementclaim/Fake.scala @@ -20,7 +20,7 @@ import play.api.mvc._ import play.api.test.Helpers import uk.gov.hmrc.cdsreimbursementclaim.controllers.actions.{AuthenticateWithUserActions, AuthenticatedUser, AuthenticatedUserRequest} import uk.gov.hmrc.http.HeaderCarrier - +import uk.gov.hmrc.cdsreimbursementclaim.models.email.Email import java.time.LocalDateTime import scala.concurrent.{ExecutionContext, Future} import uk.gov.hmrc.cdsreimbursementclaim.models.ids.Eori @@ -46,7 +46,7 @@ object Fake { override protected def executionContext: ExecutionContext = ExecutionContext.global } - val user: AuthenticatedUser = AuthenticatedUser("ggCredId") + val user: AuthenticatedUser = AuthenticatedUser("ggCredId", Some("name"), Some(Email("email@example.com"))) def login(eori: Eori): AuthorisedActions = new AuthorisedActions { diff --git a/test/uk/gov/hmrc/cdsreimbursementclaim/controllers/SubmitClaimControllerSpec.scala b/test/uk/gov/hmrc/cdsreimbursementclaim/controllers/SubmitClaimControllerSpec.scala index 59001032..4bee34c2 100644 --- a/test/uk/gov/hmrc/cdsreimbursementclaim/controllers/SubmitClaimControllerSpec.scala +++ b/test/uk/gov/hmrc/cdsreimbursementclaim/controllers/SubmitClaimControllerSpec.scala @@ -23,7 +23,7 @@ import play.api.mvc.{Headers, Request} import play.api.test.Helpers._ import play.api.test._ import uk.gov.hmrc.cdsreimbursementclaim.Fake -import uk.gov.hmrc.cdsreimbursementclaim.controllers.actions.AuthenticatedUserRequest +import uk.gov.hmrc.cdsreimbursementclaim.controllers.actions.{AuthenticatedUser, AuthenticatedUserRequest} import uk.gov.hmrc.cdsreimbursementclaim.models.Error import uk.gov.hmrc.cdsreimbursementclaim.models.claim._ import uk.gov.hmrc.cdsreimbursementclaim.models.eis.declaration.DisplayDeclaration @@ -93,14 +93,14 @@ class SubmitClaimControllerSpec extends ControllerSpec with ScalaCheckPropertyCh ) = ( mockClaimService - .submitSingleOverpaymentsClaim(_: SingleOverpaymentsClaimRequest)( + .submitSingleOverpaymentsClaim(_: SingleOverpaymentsClaimRequest, _: AuthenticatedUser)( _: HeaderCarrier, _: Request[_], _: OverpaymentsSingleClaimToTPI05Mapper, _: OverpaymentsSingleClaimToEmailMapper ) ) - .expects(request, *, *, *, *) + .expects(request, *, *, *, *, *) .returning(EitherT.fromEither[Future](response)) private def mockMultipleOverpaymentsClaimSubmission(request: MultipleOverpaymentsClaimRequest)( diff --git a/test/uk/gov/hmrc/cdsreimbursementclaim/models/generators/OverpaymentsClaimGen.scala b/test/uk/gov/hmrc/cdsreimbursementclaim/models/generators/OverpaymentsClaimGen.scala index 922da863..4fab7bb0 100644 --- a/test/uk/gov/hmrc/cdsreimbursementclaim/models/generators/OverpaymentsClaimGen.scala +++ b/test/uk/gov/hmrc/cdsreimbursementclaim/models/generators/OverpaymentsClaimGen.scala @@ -19,16 +19,19 @@ package uk.gov.hmrc.cdsreimbursementclaim.models.generators import cats.implicits.catsSyntaxEq import org.scalacheck.magnolia.Typeclass import org.scalacheck.{Arbitrary, Gen} +import uk.gov.hmrc.cdsreimbursementclaim.controllers.actions.AuthenticatedUser import uk.gov.hmrc.cdsreimbursementclaim.models.claim.BasisOfClaim.DuplicateEntry import uk.gov.hmrc.cdsreimbursementclaim.models.claim._ import uk.gov.hmrc.cdsreimbursementclaim.models.eis.declaration.DisplayDeclaration import uk.gov.hmrc.cdsreimbursementclaim.models.eis.declaration.response.NdrcDetails import uk.gov.hmrc.cdsreimbursementclaim.models.generators.Acc14DeclarationGen.genDisplayDeclaration import uk.gov.hmrc.cdsreimbursementclaim.models.generators.BankAccountDetailsGen.genBankAccountDetails +import uk.gov.hmrc.cdsreimbursementclaim.models.generators.ContactDetailsGen.genEmail import uk.gov.hmrc.cdsreimbursementclaim.models.generators.IdGen.{genEori, genMRN} import uk.gov.hmrc.cdsreimbursementclaim.models.generators.TPI05RequestGen.genContactInformation import uk.gov.hmrc.cdsreimbursementclaim.models.generators.TaxCodesGen.genTaxCode import uk.gov.hmrc.cdsreimbursementclaim.models.ids.MRN +import uk.gov.hmrc.cdsreimbursementclaim.services.tpi05.OverpaymentsSingleClaimData import java.net.URL import scala.jdk.CollectionConverters.asScalaBufferConverter @@ -107,7 +110,7 @@ object OverpaymentsClaimGen { documentType = documentType ) - lazy val genOverpaymentsSingleClaim: Gen[(SingleOverpaymentsClaim, DisplayDeclaration, Option[DisplayDeclaration])] = + lazy val genOverpaymentsSingleClaim: Gen[OverpaymentsSingleClaimData] = for { mrn <- genMRN claimantType <- Gen.oneOf(ClaimantType.values) @@ -126,7 +129,11 @@ object OverpaymentsClaimGen { evidences <- Gen.nonEmptyListOf(genEvidences) whetherInNorthernIreland <- Gen.oneOf(true, false) additionalDetails <- genRandomString - } yield ( + userEmail <- Gen.some(genEmail) + firstName <- genStringWithMaxSizeOfN(15) + lastName <- genStringWithMaxSizeOfN(15) + ggCredId <- genStringWithMaxSizeOfN(15) + } yield OverpaymentsSingleClaimData( SingleOverpaymentsClaim( movementReferenceNumber = mrn, duplicateMovementReferenceNumber = duplicateMrn, @@ -141,7 +148,12 @@ object OverpaymentsClaimGen { supportingEvidences = evidences ), declaration, - duplicateDeclaration + duplicateDeclaration, + AuthenticatedUser( + ggCredId, + Some(s"$firstName $lastName"), + userEmail + ) ) lazy val genOverpaymentsMultipleClaim: Gen[(MultipleOverpaymentsClaim, List[DisplayDeclaration])] = @@ -236,7 +248,7 @@ object OverpaymentsClaimGen { } yield (MRN(displayDeclaration.displayResponseDetail.declarationId), claimAmount) implicit lazy val arbitrarySingleOverpaymentsRequest: Typeclass[SingleOverpaymentsClaimRequest] = - Arbitrary(genOverpaymentsSingleClaim.map { case (claim, _, _) => SingleOverpaymentsClaimRequest(claim) }) + Arbitrary(genOverpaymentsSingleClaim.map { case OverpaymentsSingleClaimData(claim, _, _, _) => SingleOverpaymentsClaimRequest(claim) }) implicit lazy val arbitraryMultipleOverpaymentsRequest: Typeclass[MultipleOverpaymentsClaimRequest] = Arbitrary(genOverpaymentsMultipleClaim.map { case (claim, _) => MultipleOverpaymentsClaimRequest(claim) }) @@ -245,13 +257,13 @@ object OverpaymentsClaimGen { Arbitrary(genOverpaymentsScheduledClaim.map { case (claim, _) => ScheduledOverpaymentsClaimRequest(claim) }) implicit lazy val arbitrarySingleOverpaymentsClaimDetails - : Typeclass[(SingleOverpaymentsClaim, DisplayDeclaration, Option[DisplayDeclaration])] = + : Typeclass[OverpaymentsSingleClaimData] = Arbitrary(genOverpaymentsSingleClaim) implicit lazy val arbitraryOverpaymentsSingleClaim: Typeclass[SingleOverpaymentsClaim] = Arbitrary( for { - (claim, _, _) <- genOverpaymentsSingleClaim + OverpaymentsSingleClaimData(claim, _, _, _) <- genOverpaymentsSingleClaim } yield claim ) diff --git a/test/uk/gov/hmrc/cdsreimbursementclaim/services/ClaimServiceSpec.scala b/test/uk/gov/hmrc/cdsreimbursementclaim/services/ClaimServiceSpec.scala index 9fcc6f23..60c5e550 100644 --- a/test/uk/gov/hmrc/cdsreimbursementclaim/services/ClaimServiceSpec.scala +++ b/test/uk/gov/hmrc/cdsreimbursementclaim/services/ClaimServiceSpec.scala @@ -29,6 +29,7 @@ import play.api.mvc.Request import play.api.test.FakeRequest import play.api.test.Helpers._ import uk.gov.hmrc.cdsreimbursementclaim.connectors.ClaimConnector +import uk.gov.hmrc.cdsreimbursementclaim.controllers.actions.AuthenticatedUser import uk.gov.hmrc.cdsreimbursementclaim.metrics.MockMetrics import uk.gov.hmrc.cdsreimbursementclaim.models import uk.gov.hmrc.cdsreimbursementclaim.models.Error @@ -45,7 +46,7 @@ import uk.gov.hmrc.cdsreimbursementclaim.models.generators.TPI05RequestGen._ import uk.gov.hmrc.cdsreimbursementclaim.models.ids.MRN import uk.gov.hmrc.cdsreimbursementclaim.services.audit.AuditService import uk.gov.hmrc.cdsreimbursementclaim.services.email.{ClaimToEmailMapper, OverpaymentsMultipleClaimToEmailMapper, OverpaymentsScheduledClaimToEmailMapper, OverpaymentsSingleClaimToEmailMapper} -import uk.gov.hmrc.cdsreimbursementclaim.services.tpi05.{ClaimToTPI05Mapper, OverpaymentsMultipleClaimToTPI05Mapper, OverpaymentsScheduledClaimToTPI05Mapper, OverpaymentsSingleClaimToTPI05Mapper} +import uk.gov.hmrc.cdsreimbursementclaim.services.tpi05.{ClaimToTPI05Mapper, OverpaymentsMultipleClaimToTPI05Mapper, OverpaymentsScheduledClaimToTPI05Mapper, OverpaymentsSingleClaimData, OverpaymentsSingleClaimToTPI05Mapper} import uk.gov.hmrc.http.{HeaderCarrier, HttpResponse} import scala.concurrent.ExecutionContext.Implicits.global @@ -269,10 +270,10 @@ class ClaimServiceSpec "successfully submit a Single Overpayments claim" in forAll(genOverpaymentsSingleClaim, genC285EisRequest) { ( - singleOverpaymentsClaimData: (SingleOverpaymentsClaim, DisplayDeclaration, Option[DisplayDeclaration]), + singleOverpaymentsClaimData: OverpaymentsSingleClaimData, eisRequest: EisSubmitClaimRequest ) => - val (claim, declaration, duplicateDeclaration) = singleOverpaymentsClaimData + val OverpaymentsSingleClaimData(claim, declaration, duplicateDeclaration, user) = singleOverpaymentsClaimData val responseJsonBody = Json.parse( """ |{ @@ -298,8 +299,8 @@ class ClaimServiceSpec inSequence { mockDeclarationRetrieving(claim.movementReferenceNumber)(declaration) (overpaymentsSingleClaimMapper - .map(_: (SingleOverpaymentsClaim, DisplayDeclaration, Option[DisplayDeclaration]))) - .expects((claim, declaration, duplicateDeclaration)) + .map(_: OverpaymentsSingleClaimData)) + .expects(OverpaymentsSingleClaimData(claim, declaration, duplicateDeclaration, user)) .returning(Right(eisRequest)) (claim.duplicateMovementReferenceNumber, duplicateDeclaration).mapN( mockDeclarationRetrieving(_)(_) @@ -319,7 +320,7 @@ class ClaimServiceSpec } await( - claimService.submitSingleOverpaymentsClaim(SingleOverpaymentsClaimRequest(claim)).value + claimService.submitSingleOverpaymentsClaim(SingleOverpaymentsClaimRequest(claim), user).value ) shouldBe Right(submitClaimResponse) } diff --git a/test/uk/gov/hmrc/cdsreimbursementclaim/services/tpi05/C285MappingCrossValidationSpec.scala b/test/uk/gov/hmrc/cdsreimbursementclaim/services/tpi05/C285MappingCrossValidationSpec.scala index 1992cc4f..41962a71 100644 --- a/test/uk/gov/hmrc/cdsreimbursementclaim/services/tpi05/C285MappingCrossValidationSpec.scala +++ b/test/uk/gov/hmrc/cdsreimbursementclaim/services/tpi05/C285MappingCrossValidationSpec.scala @@ -21,14 +21,15 @@ import org.scalatest.{Assertion, Assertions, Ignore, OptionValues} import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks +import play.api.i18n.Lang.logger import play.api.libs.json.Json +import uk.gov.hmrc.cdsreimbursementclaim.Fake import uk.gov.hmrc.cdsreimbursementclaim.models.claim.{C285ClaimRequest, ClaimantInformation, ClaimantType, ClaimedReimbursement, DeclarantTypeAnswer, SingleOverpaymentsClaim, Street, TypeOfClaimAnswer} import uk.gov.hmrc.cdsreimbursementclaim.models.eis.claim.{ContactInformation, EisSubmitClaimRequest} import uk.gov.hmrc.cdsreimbursementclaim.models.eis.declaration.DisplayDeclaration import uk.gov.hmrc.cdsreimbursementclaim.models.generators.C285ClaimGen._ import uk.gov.hmrc.cdsreimbursementclaim.models.eis.declaration.response.NdrcDetails -@Ignore class C285MappingCrossValidationSpec extends AnyWordSpec with C285ClaimSupport @@ -44,81 +45,37 @@ class C285MappingCrossValidationSpec case DeclarantTypeAnswer.AssociatedWithRepresentativeCompany => ClaimantType.User } + val legacyC285RequestJson = + "{\"id\":\"d1d56496-7840-4df7-bcca-04ed2d32adcf\",\"claim\":{\"id\":\"d1d56496-7840-4df7-bcca-04ed2d32adcf\",\"typeOfClaim\":{\"Individual\":{}},\"movementReferenceNumber\":\"01AAAAAAAAAAAAAAA1\",\"declarantTypeAnswer\":{\"Importer\":{}},\"detailsRegisteredWithCdsAnswer\":{\"fullName\":\"IT Solutions LTD\",\"emailAddress\":\"someemail@mail.com\",\"contactAddress\":{\"line1\":\"19 Bricks Road\",\"line4\":\"Newcastle\",\"postcode\":\"NE12 5BT\",\"country\":{\"code\":\"GB\"}},\"addCompanyDetails\":false},\"mrnContactDetailsAnswer\":{\"fullName\":\"Online Sales LTD\",\"emailAddress\":\"someemail@mail.com\",\"phoneNumber\":\"+4420723934397\"},\"mrnContactAddressAnswer\":{\"line1\":\"11 Mount Road\",\"line4\":\"London\",\"postcode\":\"E10 7PP\",\"country\":{\"code\":\"GB\"}},\"basisOfClaimAnswer\":{\"PersonalEffects\":{}},\"documents\":[{\"checksum\":\"2ff223d3f2fe41d24dba195178f94baac4ec1a0a89853b96987493a34be8b99a\",\"downloadUrl\":\"http://localhost:9570/upscan/download/c934183d-b889-40fb-b573-469d5088f83c\",\"fileName\":\"ACC14-1.3.0-OverpaymentDeclarationDisplay.pdf\",\"fileMimeType\":\"application/binary\",\"size\":1628473,\"uploadedOn\":\"2023-02-22T13:52:17.272927\",\"documentType\":\"AirWayBill\"}],\"additionalDetailsAnswer\":{\"value\":\"the quick brown fox jumps over the lazy dog\"},\"displayDeclaration\":{\"displayResponseDetail\":{\"declarationId\":\"01AAAAAAAAAAAAAAA1\",\"acceptanceDate\":\"12 February 2021\",\"procedureCode\":\"2\",\"declarantDetails\":{\"declarantEORI\":\"GB000000000000001\",\"legalName\":\"Foxpro Central LTD\",\"establishmentAddress\":{\"addressLine1\":\"12 Skybricks Road\",\"addressLine3\":\"Coventry\",\"postalCode\":\"CV3 6EA\",\"countryCode\":\"GB\"},\"contactDetails\":{\"addressLine1\":\"45 Church Road\",\"addressLine3\":\"Leeds\",\"postalCode\":\"LS1 2HA\",\"contactName\":\"Info Tech LTD\",\"countryCode\":\"GB\"}},\"consigneeDetails\":{\"consigneeEORI\":\"GB000000000000001\",\"legalName\":\"IT Solutions LTD\",\"establishmentAddress\":{\"addressLine1\":\"19 Bricks Road\",\"addressLine3\":\"Newcastle\",\"postalCode\":\"NE12 5BT\",\"countryCode\":\"GB\"},\"contactDetails\":{\"addressLine1\":\"11 Mount Road\",\"emailAddress\":\"automation@gmail.com\",\"addressLine3\":\"London\",\"postalCode\":\"E10 7PP\",\"contactName\":\"Online Sales LTD\",\"countryCode\":\"GB\",\"telephone\":\"+4420723934397\"}},\"accountDetails\":[{\"accountType\":\"a\",\"accountNumber\":\"1\",\"eori\":\"GB000000000000001\",\"legalName\":\"a\",\"contactDetails\":{\"addressLine1\":\"a\",\"addressLine4\":\"a\",\"emailAddress\":\"a\",\"addressLine3\":\"a\",\"postalCode\":\"a\",\"contactName\":\"a\",\"countryCode\":\"GB\",\"addressLine2\":\"a\",\"telephone\":\"a\"}},{\"accountType\":\"b\",\"accountNumber\":\"2\",\"eori\":\"GB000000000000001\",\"legalName\":\"b\",\"contactDetails\":{\"addressLine1\":\"b\",\"addressLine4\":\"b\",\"emailAddress\":\"b\",\"addressLine3\":\"b\",\"postalCode\":\"b\",\"contactName\":\"b\",\"countryCode\":\"GB\",\"addressLine2\":\"b\",\"telephone\":\"b\"}}],\"bankDetails\":{\"consigneeBankDetails\":{\"accountHolderName\":\"CDS E2E To E2E Bank\",\"sortCode\":\"308844\",\"accountNumber\":\"12345678\"},\"declarantBankDetails\":{\"accountHolderName\":\"CDS E2E To E2E Bank\",\"sortCode\":\"308844\",\"accountNumber\":\"12345678\"}},\"maskedBankDetails\":{\"consigneeBankDetails\":{\"accountHolderName\":\"CDS E2E To E2E Bank\",\"sortCode\":\"Ending with 44\",\"accountNumber\":\"Ending with 5678\"},\"declarantBankDetails\":{\"accountHolderName\":\"CDS E2E To E2E Bank\",\"sortCode\":\"Ending with 44\",\"accountNumber\":\"Ending with 5678\"}},\"ndrcDetails\":[{\"taxType\":\"A80\",\"amount\":\"218.00\",\"paymentMethod\":\"001\",\"paymentReference\":\"GB201430007000\",\"cmaEligible\":\"0\"},{\"taxType\":\"A95\",\"amount\":\"211.00\",\"paymentMethod\":\"001\",\"paymentReference\":\"GB201430007000\",\"cmaEligible\":\"1\"},{\"taxType\":\"A90\",\"amount\":\"228.00\",\"paymentMethod\":\"001\",\"paymentReference\":\"GB201430007000\",\"cmaEligible\":\"1\"},{\"taxType\":\"A85\",\"amount\":\"171.00\",\"paymentMethod\":\"001\",\"paymentReference\":\"GB201430007000\",\"cmaEligible\":\"1\"}]}},\"claimedReimbursementsAnswer\":[{\"taxCode\":\"A80\",\"paidAmount\":218,\"claimAmount\":118,\"id\":\"4c78f163-d152-450f-aa58-7d83dca91c3d\",\"paymentMethod\":\"001\",\"paymentReference\":\"GB201430007000\",\"isFilled\":true},{\"taxCode\":\"A95\",\"paidAmount\":211,\"claimAmount\":61,\"id\":\"fcd9c5c2-a21b-40be-a52d-c6d344e82f79\",\"paymentMethod\":\"001\",\"paymentReference\":\"GB201430007000\",\"isFilled\":true},{\"taxCode\":\"A90\",\"paidAmount\":228,\"claimAmount\":58,\"id\":\"c2843e82-c9bd-41ef-9cad-b5738e723da0\",\"paymentMethod\":\"001\",\"paymentReference\":\"GB201430007000\",\"isFilled\":true},{\"taxCode\":\"A85\",\"paidAmount\":171,\"claimAmount\":81,\"id\":\"f7f44caa-e033-4b5d-91d2-525aeba4f774\",\"paymentMethod\":\"001\",\"paymentReference\":\"GB201430007000\",\"isFilled\":true}],\"reimbursementMethodAnswer\":\"BankAccountTransfer\"},\"signedInUserDetails\":{\"email\":\"event-agents-external-aaaadghuc4fueomsg3kpkvdmry@hmrcdigital.slack.com\",\"eori\":\"GB000000000000001\",\"verifiedEmail\":\"someemail@mail.com\",\"contactName\":\"Jayce\"}}" + val newC285RequestJson = + "{\"movementReferenceNumber\":\"01AAAAAAAAAAAAAAA1\",\"claimantType\":\"Consignee\",\"claimantInformation\":{\"eori\":\"GB000000000000001\",\"fullName\":\"IT Solutions LTD\",\"establishmentAddress\":{\"contactPerson\":\"IT Solutions LTD\",\"addressLine1\":\"19 Bricks Road\",\"street\":\"19 Bricks Road\",\"city\":\"Newcastle\",\"countryCode\":\"GB\",\"postalCode\":\"NE12 5BT\",\"emailAddress\":\"automation@gmail.com\"},\"contactInformation\":{\"contactPerson\":\"Online Sales LTD\",\"addressLine1\":\"19 Bricks Road\",\"street\":\"19 Bricks Road\",\"city\":\"Newcastle\",\"countryCode\":\"GB\",\"postalCode\":\"NE12 5BT\",\"telephoneNumber\":\"+4420723934397\",\"emailAddress\":\"automation@gmail.com\"}},\"basisOfClaim\":{\"PersonalEffects\":{}},\"whetherNorthernIreland\":false,\"additionalDetails\":\"the quick brown fox jumps over the lazy dog\",\"reimbursementClaims\":{\"A80\":\"118.00\",\"A95\":\"61.00\",\"A90\":\"58.00\",\"A85\":\"81.00\"},\"reimbursementMethod\":\"BankAccountTransfer\",\"bankAccountDetails\":{\"accountName\":\"CDS E2E To E2E Bank\",\"sortCode\":\"308844\",\"accountNumber\":\"12345678\"},\"supportingEvidences\":[{\"checksum\":\"2ff223d3f2fe41d24dba195178f94baac4ec1a0a89853b96987493a34be8b99a\",\"downloadUrl\":\"http://localhost:9570/upscan/download/f21aae22-fefb-448b-9703-0ffb1df84f09\",\"fileName\":\"ACC14-1.3.0-OverpaymentDeclarationDisplay.pdf\",\"fileMimeType\":\"application/binary\",\"size\":1628473,\"uploadedOn\":\"2023-02-22T14:01:54.47396\",\"documentType\":\"AirWayBill\"}]}" + val delcarationJson = + "{\"displayResponseDetail\":{\"declarationId\":\"01AAAAAAAAAAAAAAA1\",\"acceptanceDate\":\"12 February 2021\",\"procedureCode\":\"2\",\"declarantDetails\":{\"declarantEORI\":\"GB000000000000001\",\"legalName\":\"Foxpro Central LTD\",\"establishmentAddress\":{\"addressLine1\":\"12 Skybricks Road\",\"addressLine3\":\"Coventry\",\"postalCode\":\"CV3 6EA\",\"countryCode\":\"GB\"},\"contactDetails\":{\"addressLine1\":\"45 Church Road\",\"addressLine3\":\"Leeds\",\"postalCode\":\"LS1 2HA\",\"contactName\":\"Info Tech LTD\",\"countryCode\":\"GB\"}},\"consigneeDetails\":{\"consigneeEORI\":\"GB000000000000001\",\"legalName\":\"IT Solutions LTD\",\"establishmentAddress\":{\"addressLine1\":\"19 Bricks Road\",\"addressLine3\":\"Newcastle\",\"postalCode\":\"NE12 5BT\",\"countryCode\":\"GB\"},\"contactDetails\":{\"addressLine1\":\"11 Mount Road\",\"emailAddress\":\"automation@gmail.com\",\"addressLine3\":\"London\",\"postalCode\":\"E10 7PP\",\"contactName\":\"Online Sales LTD\",\"countryCode\":\"GB\",\"telephone\":\"+4420723934397\"}},\"accountDetails\":[{\"accountType\":\"a\",\"accountNumber\":\"1\",\"eori\":\"GB000000000000001\",\"legalName\":\"a\",\"contactDetails\":{\"addressLine1\":\"a\",\"addressLine4\":\"a\",\"emailAddress\":\"a\",\"addressLine3\":\"a\",\"postalCode\":\"a\",\"contactName\":\"a\",\"countryCode\":\"GB\",\"addressLine2\":\"a\",\"telephone\":\"a\"}},{\"accountType\":\"b\",\"accountNumber\":\"2\",\"eori\":\"GB000000000000001\",\"legalName\":\"b\",\"contactDetails\":{\"addressLine1\":\"b\",\"addressLine4\":\"b\",\"emailAddress\":\"b\",\"addressLine3\":\"b\",\"postalCode\":\"b\",\"contactName\":\"b\",\"countryCode\":\"GB\",\"addressLine2\":\"b\",\"telephone\":\"b\"}}],\"bankDetails\":{\"consigneeBankDetails\":{\"accountHolderName\":\"CDS E2E To E2E Bank\",\"sortCode\":\"308844\",\"accountNumber\":\"12345678\"},\"declarantBankDetails\":{\"accountHolderName\":\"CDS E2E To E2E Bank\",\"sortCode\":\"308844\",\"accountNumber\":\"12345678\"}},\"maskedBankDetails\":{\"consigneeBankDetails\":{\"accountHolderName\":\"CDS E2E To E2E Bank\",\"sortCode\":\"Ending with 44\",\"accountNumber\":\"Ending with 5678\"},\"declarantBankDetails\":{\"accountHolderName\":\"CDS E2E To E2E Bank\",\"sortCode\":\"Ending with 44\",\"accountNumber\":\"Ending with 5678\"}},\"ndrcDetails\":[{\"taxType\":\"A80\",\"amount\":\"218.00\",\"paymentMethod\":\"001\",\"paymentReference\":\"GB201430007000\",\"cmaEligible\":\"0\"},{\"taxType\":\"A95\",\"amount\":\"211.00\",\"paymentMethod\":\"001\",\"paymentReference\":\"GB201430007000\",\"cmaEligible\":\"1\"},{\"taxType\":\"A90\",\"amount\":\"228.00\",\"paymentMethod\":\"001\",\"paymentReference\":\"GB201430007000\",\"cmaEligible\":\"1\"},{\"taxType\":\"A85\",\"amount\":\"171.00\",\"paymentMethod\":\"001\",\"paymentReference\":\"GB201430007000\",\"cmaEligible\":\"1\"}]}}" + "The C285 claim old and new mappers " should { - "produce the same TPI05 request for a single claim" in forAll { generatedRequest: C285ClaimRequest => - whenever(generatedRequest.claim.typeOfClaim === TypeOfClaimAnswer.Individual) { - val c285ClaimRequest = generatedRequest.copy(claim = generatedRequest.claim.copy(associatedMRNsAnswer = None)) - val tpi05RequestOld = c285ClaimToTPI05Mapper.map(c285ClaimRequest) - val declaration = c285ClaimRequest.claim.displayDeclaration.value + "produce the same TPI05 request for a single claim" in { + val c285ClaimRequest = Json.fromJson[C285ClaimRequest](Json.parse(legacyC285RequestJson)).get + val declaration = Json.fromJson[DisplayDeclaration](Json.parse(delcarationJson)).get + + val overpaymentsSingleRequest: OverpaymentsSingleClaimData = OverpaymentsSingleClaimData( + Json.fromJson[SingleOverpaymentsClaim](Json.parse(newC285RequestJson)).get, + declaration, + None, + Fake.user + ) + val tpi05RequestOld = c285ClaimToTPI05Mapper.map(c285ClaimRequest) + val tpi05RequestNew = overpaymentsSingleClaimToTPI05Mapper.map(overpaymentsSingleRequest) + + tpi05RequestOld.isRight shouldBe tpi05RequestNew.isRight + + val oldResult = Json.toJson(tpi05RequestOld.toOption.value.postNewClaimsRequest.requestDetail) + val newResult = Json.toJson(tpi05RequestNew.toOption.value.postNewClaimsRequest.requestDetail) - val overpaymentsSingleRequest: (SingleOverpaymentsClaim, DisplayDeclaration, Option[DisplayDeclaration]) = ( - SingleOverpaymentsClaim( - movementReferenceNumber = c285ClaimRequest.claim.movementReferenceNumber, - duplicateMovementReferenceNumber = c285ClaimRequest.claim.duplicateMovementReferenceNumberAnswer, - claimantType = toClaimantType(c285ClaimRequest.claim.declarantTypeAnswer), - claimantInformation = ClaimantInformation( - c285ClaimRequest.signedInUserDetails.eori, - c285ClaimRequest.signedInUserDetails.contactName.value, - establishmentAddress = ContactInformation( - contactPerson = Some(c285ClaimRequest.claim.detailsRegisteredWithCdsAnswer.fullName), - addressLine1 = Some(c285ClaimRequest.claim.detailsRegisteredWithCdsAnswer.contactAddress.line1), - addressLine2 = c285ClaimRequest.claim.detailsRegisteredWithCdsAnswer.contactAddress.line2, - addressLine3 = c285ClaimRequest.claim.detailsRegisteredWithCdsAnswer.contactAddress.line3, - street = Street.fromLines( - Some(c285ClaimRequest.claim.detailsRegisteredWithCdsAnswer.contactAddress.line1), - c285ClaimRequest.claim.detailsRegisteredWithCdsAnswer.contactAddress.line2 - ), - city = Some(c285ClaimRequest.claim.detailsRegisteredWithCdsAnswer.contactAddress.line4), - countryCode = Some(c285ClaimRequest.claim.detailsRegisteredWithCdsAnswer.contactAddress.country.code), - postalCode = Some(c285ClaimRequest.claim.detailsRegisteredWithCdsAnswer.contactAddress.postcode.value), - telephoneNumber = None, - faxNumber = None, - emailAddress = Some(c285ClaimRequest.claim.detailsRegisteredWithCdsAnswer.emailAddress.value) - ), - contactInformation = c285ClaimRequest.claim.contactInformation - ), - basisOfClaim = c285ClaimRequest.claim.basisOfClaimAnswer, - whetherNorthernIreland = true, - additionalDetails = c285ClaimRequest.claim.additionalDetailsAnswer.value, - reimbursementClaims = - c285ClaimRequest.claim.claimedReimbursementsAnswer.map(c => (c.taxCode, c.claimAmount)).toList.toMap, - reimbursementMethod = c285ClaimRequest.claim.reimbursementMethodAnswer, - bankAccountDetails = c285ClaimRequest.claim.bankAccountDetailsAnswer, - supportingEvidences = c285ClaimRequest.claim.documents.toList.flatten - ), - declaration.copy( - declaration.displayResponseDetail.copy(ndrcDetails = - Some( - c285ClaimRequest.claim.claims - .map(x => - NdrcDetails(x.taxCode.value, x.paidAmount.toString(), x.paymentMethod, x.paymentReference, None) - ) - .toList - ) - ) - ), - c285ClaimRequest.claim.duplicateDisplayDeclaration.map(dup => - dup.copy( - dup.displayResponseDetail.copy(ndrcDetails = - Some( - c285ClaimRequest.claim.claims - .map(x => - NdrcDetails(x.taxCode.value, x.paidAmount.toString(), x.paymentMethod, x.paymentReference, None) - ) - .toList - ) - ) - ) - ) - ) - val tpi05RequestNew = overpaymentsSingleClaimToTPI05Mapper.map(overpaymentsSingleRequest) + logger.warn(s"OLD RESULT: $oldResult") + logger.warn(s"NEW RESULT: $newResult") - tpi05RequestOld.isRight shouldBe tpi05RequestNew.isRight - Json.toJson(tpi05RequestOld.toOption.value.postNewClaimsRequest.requestDetail) shouldBe Json.toJson( - tpi05RequestNew.toOption.value.postNewClaimsRequest.requestDetail - ) - } + oldResult shouldBe newResult } } diff --git a/test/uk/gov/hmrc/cdsreimbursementclaim/services/tpi05/OverpaymentsSingleClaimMappingSpec.scala b/test/uk/gov/hmrc/cdsreimbursementclaim/services/tpi05/OverpaymentsSingleClaimMappingSpec.scala index b5c28ad6..da4f5241 100644 --- a/test/uk/gov/hmrc/cdsreimbursementclaim/services/tpi05/OverpaymentsSingleClaimMappingSpec.scala +++ b/test/uk/gov/hmrc/cdsreimbursementclaim/services/tpi05/OverpaymentsSingleClaimMappingSpec.scala @@ -51,12 +51,12 @@ class OverpaymentsSingleClaimMappingSpec "The OverpaymentsSingle claim mapper" should { "map a valid claim to TPI05 request" in forAll(genOverpaymentsSingleClaim) { - singleOverpaymentsData: (SingleOverpaymentsClaim, DisplayDeclaration, Option[DisplayDeclaration]) => + singleOverpaymentsData: OverpaymentsSingleClaimData => val tpi05Request = overpaymentsSingleClaimToTPI05Mapper map singleOverpaymentsData - val (claim, displayDeclaration, duplicateDeclaration) = singleOverpaymentsData - val declarant = displayDeclaration.displayResponseDetail.declarantDetails - val nrdcDetailsMap = displayDeclaration.displayResponseDetail.ndrcDetails.toList.flatten + val OverpaymentsSingleClaimData(claim, displayDeclaration, duplicateDeclaration, user) = singleOverpaymentsData + val declarant = displayDeclaration.displayResponseDetail.declarantDetails + val nrdcDetailsMap = displayDeclaration.displayResponseDetail.ndrcDetails.toList.flatten .groupBy(_.taxType) .mapValues(_.sortBy(_.taxType).headOption.value) .mapValues(ndrc => ndrc.copy(amount = BigDecimal(ndrc.amount).roundToTwoDecimalPlaces.toString()))