Skip to content

Commit

Permalink
CDSR-2174: update code to use same email and claimant name as legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
jamalosman committed Feb 27, 2023
1 parent fd184a0 commit 981fb2e
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@

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
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,
Expand All @@ -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 =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
)
Expand Down
16 changes: 12 additions & 4 deletions app/uk/gov/hmrc/cdsreimbursementclaim/services/ClaimService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand All @@ -65,7 +66,8 @@ trait ClaimService {
): EitherT[Future, Error, ClaimSubmitResponse]

def submitSingleOverpaymentsClaim(
singleOverpaymentsClaim: SingleOverpaymentsClaimRequest
singleOverpaymentsClaim: SingleOverpaymentsClaimRequest,
user: AuthenticatedUser
)(implicit
hc: HeaderCarrier,
request: Request[_],
Expand Down Expand Up @@ -148,7 +150,8 @@ class DefaultClaimService @Inject() (
proceed(c285ClaimRequest, c285ClaimRequest)

def submitSingleOverpaymentsClaim(
claimRequest: SingleOverpaymentsClaimRequest
claimRequest: SingleOverpaymentsClaimRequest,
user: AuthenticatedUser
)(implicit
hc: HeaderCarrier,
request: Request[_],
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions test/uk/gov/hmrc/cdsreimbursementclaim/Fake.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 protected]")))

def login(eori: Eori): AuthorisedActions =
new AuthorisedActions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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])] =
Expand Down Expand Up @@ -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) })
Expand All @@ -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
)

Expand Down
Loading

0 comments on commit 981fb2e

Please sign in to comment.