Skip to content

Commit 8446329

Browse files
[MG] [OPS-13580] Email content updates to remove if not in session (#34)
1 parent 07bb836 commit 8446329

File tree

5 files changed

+44
-16
lines changed

5 files changed

+44
-16
lines changed

app/uk/gov/hmrc/cardpaymentfrontend/controllers/CheckYourAnswersController.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ class CheckYourAnswersController @Inject() (
5353
val referenceRow: Option[CheckYourAnswersRow] = extendedOrigin.checkYourAnswersReferenceRow(journeyRequest)(appConfig.payFrontendBaseUrl)
5454
val additionalReferenceRow: Option[CheckYourAnswersRow] = extendedOrigin.checkYourAnswersAdditionalReferenceRow(journeyRequest)
5555
val amountRow: Option[CheckYourAnswersRow] = extendedOrigin.checkYourAnswersAmountSummaryRow(journeyRequest)(appConfig.payFrontendBaseUrl)
56-
val maybeEmailRow: Option[CheckYourAnswersRow] = extendedOrigin.checkYourAnswersEmailAddressRow(journeyRequest)
5756
val cardBillingAddressRow: Option[CheckYourAnswersRow] = extendedOrigin.checkYourAnswersCardBillingAddressRow(journeyRequest)
57+
// If no email is present in the session, no Email Row is shown
58+
val maybeEmailRow: Option[CheckYourAnswersRow] = extendedOrigin.checkYourAnswersEmailAddressRow(journeyRequest)
5859

5960
val summaryListRows: Seq[SummaryListRow] = Seq(
6061
paymentDate,

app/uk/gov/hmrc/cardpaymentfrontend/controllers/PaymentCompleteController.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class PaymentCompleteController @Inject() (
5050
val renderPage: Action[AnyContent] = actions.journeyAction { implicit journeyRequest: JourneyRequest[AnyContent] =>
5151

5252
val maybeEmailFromSession: Option[EmailAddress] =
53-
journeyRequest.readFromSession[EmailAddress](journeyRequest.journeyId, Keys.email).map(email => EmailAddress(email.value))
53+
journeyRequest.readFromSession[EmailAddress](journeyRequest.journeyId, Keys.email).filter(!_.value.isBlank).map(email => EmailAddress(email.value))
5454

5555
val langIsEnglish: Boolean = journeyRequest.lang.code =!= "cy"
5656

app/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedOrigin.scala

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,18 @@ trait ExtendedOrigin {
8686

8787
def checkYourAnswersEmailAddressRow(journeyRequest: JourneyRequest[AnyContent]): Option[CheckYourAnswersRow] = {
8888
val maybeEmail: Option[EmailAddress] = journeyRequest.readFromSession[EmailAddress](journeyRequest.journeyId, Keys.email)
89-
maybeEmail.map { email =>
90-
CheckYourAnswersRow(
91-
titleMessageKey = "check-your-details.email-address",
92-
value = Seq(email.value),
93-
changeLink = Some(Link(
94-
href = uk.gov.hmrc.cardpaymentfrontend.controllers.routes.EmailAddressController.renderPage,
95-
linkId = "check-your-details-email-address-change-link",
96-
messageKey = "check-your-details.change"
97-
))
98-
)
99-
}
89+
maybeEmail.filter(!_.value.isBlank)
90+
.map { email =>
91+
CheckYourAnswersRow(
92+
titleMessageKey = "check-your-details.email-address",
93+
value = Seq(email.value),
94+
changeLink = Some(Link(
95+
href = uk.gov.hmrc.cardpaymentfrontend.controllers.routes.EmailAddressController.renderPage,
96+
linkId = "check-your-details-email-address-change-link",
97+
messageKey = "check-your-details.change"
98+
))
99+
)
100+
}
100101
}
101102

102103
// TODO: Update tests to not include country - check doesn't show country

project/AppDependencies.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object AppDependencies {
1515

1616
val compile: Seq[ModuleID] = Seq[ModuleID](
1717
"uk.gov.hmrc" %% "bootstrap-frontend-play-30" % bootstrapVersion,
18-
"uk.gov.hmrc" %% "play-frontend-hmrc-play-30" % "12.0.0",
18+
"uk.gov.hmrc" %% "play-frontend-hmrc-play-30" % "12.1.0",
1919
"com.beachape" %% "enumeratum" % "1.7.6",
2020
"com.beachape" %% "enumeratum-play" % "1.8.2",
2121
"uk.gov.hmrc" %% "pay-api-cor-card-payment-journey" % payApiCorVersion excludeAll(payApiExclusionRules: _*)

test/uk/gov/hmrc/cardpaymentfrontend/models/extendedorigins/ExtendedOriginSpec.scala

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ import payapi.corcommon.model.{AmountInPence, FutureDatedPayment}
2020
import play.api.mvc.{AnyContent, Call}
2121
import play.api.test.FakeRequest
2222
import uk.gov.hmrc.cardpaymentfrontend.actions.JourneyRequest
23-
import uk.gov.hmrc.cardpaymentfrontend.models.CheckYourAnswersRow
23+
import uk.gov.hmrc.cardpaymentfrontend.models.{CheckYourAnswersRow, Link}
2424
import uk.gov.hmrc.cardpaymentfrontend.testsupport.ItSpec
2525
import uk.gov.hmrc.cardpaymentfrontend.testsupport.TestOps.FakeRequestOps
2626
import uk.gov.hmrc.cardpaymentfrontend.testsupport.stubs.PayApiStub
2727
import uk.gov.hmrc.cardpaymentfrontend.testsupport.testdata.TestJourneys
28-
import uk.gov.hmrc.cardpaymentfrontend.models.Link
2928

3029
import java.time.LocalDate
3130

3231
class ExtendedOriginSpec extends ItSpec {
3332
private val systemUnderTest = ExtendedBtaSa //ExtendedBtaSa is a concrete reification of the trait ExtendedOrigin, we use it as a substitute here.
3433
private val fakeGetRequest = FakeRequest("GET", "/cya0").withSessionId()
34+
3535
private val testJourney = TestJourneys.BtaSa.journeyBeforeBeginWebPayment
3636
private val testJourneyNoDueDate = TestJourneys.BtaSa.journeyBeforeBeginWebPayment.copy(journeySpecificData = testJourney.journeySpecificData.copy(dueDate = None))
3737
private val testJourneyOverdue = TestJourneys.BtaSa.journeyBeforeBeginWebPayment.copy(journeySpecificData = testJourneyNoDueDate.journeySpecificData.copy(dueDate = Some(LocalDate.of(2023, 12, 12))))
@@ -81,4 +81,30 @@ class ExtendedOriginSpec extends ItSpec {
8181
result shouldBe (None)
8282
}
8383
}
84+
85+
"checkYourAnswersEmailAddressRow" - {
86+
87+
val jsonSessionWithEmail =
88+
"""
89+
|{
90+
| "email" : "email@gmail.com"
91+
|}
92+
|""".stripMargin
93+
94+
val sessionMapWithEmail = ("TestJourneyId-44f9-ad7f-01e1d3d8f151", jsonSessionWithEmail)
95+
val fakeGetRequestWithEmail = FakeRequest("GET", "/cya0").withSession(sessionMapWithEmail)
96+
97+
"return Some[CheckYourAnswersRow] when showEmailAddress returns true" in {
98+
val fakeJourneyRequest: JourneyRequest[AnyContent] = new JourneyRequest(testJourney, fakeGetRequestWithEmail)
99+
val result: Option[CheckYourAnswersRow] = systemUnderTest.checkYourAnswersEmailAddressRow(fakeJourneyRequest)
100+
result shouldBe Some(CheckYourAnswersRow("check-your-details.email-address", List("email@gmail.com"), Some(Link(Call("GET", "/pay-by-card/email-address"), "check-your-details-email-address-change-link", "check-your-details.change", None))))
101+
102+
}
103+
"return None when showEmailAddress returns false" in {
104+
val testJourneyEmailAddress = TestJourneys.BtaSa.journeyAfterBeginWebPayment
105+
val fakeJourneyRequest: JourneyRequest[AnyContent] = new JourneyRequest(testJourneyEmailAddress, fakeGetRequest)
106+
val result: Option[CheckYourAnswersRow] = systemUnderTest.checkYourAnswersEmailAddressRow(fakeJourneyRequest)
107+
result shouldBe (None)
108+
}
109+
}
84110
}

0 commit comments

Comments
 (0)