Skip to content

Commit

Permalink
Merge pull request #120 from hmrc/DAC6-3383
Browse files Browse the repository at this point in the history
DAC6-3383: Update country code to GB
  • Loading branch information
oarshad authored Oct 14, 2024
2 parents 4f07eaf + abbe48d commit 276d972
Show file tree
Hide file tree
Showing 17 changed files with 136 additions and 201 deletions.
1 change: 0 additions & 1 deletion app/controllers/DetailsUpdatedController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import utils.ContactHelper
import views.html.DetailsUpdatedView

import javax.inject.Inject
import scala.concurrent.Future

class DetailsUpdatedController @Inject() (
override val messagesApi: MessagesApi,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.google.inject.Inject
import controllers.actions._
import models.{CheckAnswers, UserAnswers}
import pages.Page
import play.api.i18n.Lang.logger
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import services.FinancialInstitutionsService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package controllers.addFinancialInstitution

import controllers.actions._
import forms.addFinancialInstitution.IsThisAddressFormProvider
import models.{AddressLookup, Mode}
import models.Mode
import navigation.Navigator
import pages.addFinancialInstitution.{AddressLookupPage, IsThisAddressPage, SelectedAddressLookupPage}
import play.api.i18n.{I18nSupport, MessagesApi}
Expand Down
2 changes: 1 addition & 1 deletion app/handlers/ErrorHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package handlers

import config.FrontendAppConfig
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Request, RequestHeader}
import play.api.mvc.RequestHeader
import play.twirl.api.Html
import uk.gov.hmrc.play.bootstrap.frontend.http.FrontendErrorHandler
import views.html.{PageNotFoundView, ThereIsAProblemView}
Expand Down
20 changes: 10 additions & 10 deletions app/models/AddressLookup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ case class AddressLookup(addressLine1: Option[String],
town: String,
county: Option[String],
postcode: String,
country: Option[String]
country: Option[Country]
) {

val toAddress: Address = {
Expand All @@ -42,10 +42,9 @@ case class AddressLookup(addressLine1: Option[String],
case (false, true) => Some(town)
case (_, _) => addressLine4
}
val safePostcode = Option(postcode)
val ctry: Country = Country("", "", country.getOrElse(""))
val safePostcode = Option(postcode)

Address(line1, line2, line3, line4, safePostcode, ctry)
Address(line1, line2, line3, line4, safePostcode, country.getOrElse(Country.GB))
}

}
Expand Down Expand Up @@ -76,11 +75,10 @@ object AddressLookup {
(JsPath \ "address" \ "town").read[String] and
(JsPath \ "address" \ "county").readNullable[String] and
(JsPath \ "address" \ "postcode").read[String] and
(
(JsPath \ "address" \ "country").readNullable[String] orElse
(JsPath \ "address" \ "country" \ "name").readNullable[String]
)) {
(lines, town, county, postcode, countryName) =>
(JsPath \ "address" \ "country" \ "code").readNullable[String] and
(JsPath \ "address" \ "country" \ "description").readNullable[String] and
(JsPath \ "address" \ "country" \ "name").readNullable[String]) {
(lines, town, county, postcode, countryCode, countryDescription, countryName) =>
val addressLines: (Option[String], Option[String], Option[String], Option[String]) =
lines.size match {
case 0 =>
Expand All @@ -101,7 +99,9 @@ object AddressLookup {
town,
county,
postcode,
countryName
countryCode.map(
code => Country("", code, countryDescription.orElse(countryName).getOrElse(code))
)
)
}

Expand Down
2 changes: 1 addition & 1 deletion app/models/Country.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ case class Country(state: String, code: String, description: String)

object Country {

val GB = Country("valid", "GB", "United Kingdom")
val GB = Country("", "GB", "United Kingdom")

implicit val format: OFormat[Country] = Json.format[Country]
}
2 changes: 1 addition & 1 deletion app/models/FinancialInstitutions/FIDetail.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final case class FIDetail(
IsFIUser: Boolean,
IsFATCAReporting: Boolean,
AddressDetails: AddressDetails,
PrimaryContactDetails: ContactDetails,
PrimaryContactDetails: Option[ContactDetails],
SecondaryContactDetails: Option[ContactDetails]
)

Expand Down
23 changes: 15 additions & 8 deletions app/services/FinancialInstitutionUpdateService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ class FinancialInstitutionUpdateService @Inject() (

private def setPrimaryContactDetails(userAnswers: UserAnswers, fiDetails: FIDetail)(implicit ec: ExecutionContext): Future[UserAnswers] = {
val primaryContact = fiDetails.PrimaryContactDetails
for {
a <- Future.fromTry(userAnswers.set(FirstContactNamePage, primaryContact.ContactName))
b <- Future.fromTry(a.set(FirstContactEmailPage, primaryContact.EmailAddress))
c <- setPhoneNumber(b, primaryContact, FirstContactHavePhonePage, FirstContactPhoneNumberPage)
} yield c
primaryContact map {
contact =>
for {
a <- Future.fromTry(userAnswers.set(FirstContactNamePage, contact.ContactName))
b <- Future.fromTry(a.set(FirstContactEmailPage, contact.EmailAddress))
c <- setPhoneNumber(b, contact, FirstContactHavePhonePage, FirstContactPhoneNumberPage)
} yield c
} getOrElse Future.successful(userAnswers)
}

private def setPhoneNumber(
Expand Down Expand Up @@ -192,9 +195,13 @@ class FinancialInstitutionUpdateService @Inject() (

private def checkPrimaryContactForChanges(userAnswers: UserAnswers, fiDetails: FIDetail): Boolean = {
val primaryContact = fiDetails.PrimaryContactDetails
userAnswers.get(FirstContactNamePage).exists(_ != primaryContact.ContactName) ||
userAnswers.get(FirstContactEmailPage).exists(_ != primaryContact.EmailAddress) ||
checkPhoneNumberForChanges(userAnswers, primaryContact, FirstContactHavePhonePage, FirstContactPhoneNumberPage)
primaryContact match {
case Some(contact) =>
userAnswers.get(FirstContactNamePage).exists(_ != contact.ContactName) ||
userAnswers.get(FirstContactEmailPage).exists(_ != contact.EmailAddress) ||
checkPhoneNumberForChanges(userAnswers, contact, FirstContactHavePhonePage, FirstContactPhoneNumberPage)
case _ => false
}
}

private def checkSecondaryContactForChanges(userAnswers: UserAnswers, fiDetails: FIDetail): Boolean =
Expand Down
22 changes: 4 additions & 18 deletions app/utils/AddressHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object AddressHelper {
address.town,
address.postcode,
address.county,
address.country
address.country.map(_.description)
)
.collect {
case s: String => s
Expand All @@ -40,14 +40,7 @@ object AddressHelper {
}

def formatAddress(address: Address): String = {
val lines = Seq(address.addressLine1,
address.addressLine2,
address.addressLine3,
address.addressLine4,
address.country,
address.postCode,
address.country.description
)
val lines = Seq(address.addressLine1, address.addressLine2, address.addressLine3, address.addressLine4, address.postCode, address.country.description)
.collect {
case s: String => s
case Some(s) => s
Expand All @@ -64,20 +57,13 @@ object AddressHelper {
address.town,
address.postcode,
address.county,
address.country
address.country.map(_.description)
)
toFormattedAddress(lines)
}

def formatAddressBlock(address: Address): HtmlContent = {
val lines = Seq(address.addressLine1,
address.addressLine2,
address.addressLine3,
address.addressLine4,
address.country,
address.postCode,
address.country.description
)
val lines = Seq(address.addressLine1, address.addressLine2, address.addressLine3, address.addressLine4, address.postCode, address.country.description)
toFormattedAddress(lines)
}

Expand Down
4 changes: 2 additions & 2 deletions test-utils/generators/ModelGenerators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ trait ModelGenerators extends RegexConstants with Generators {
postCode <- arbitrary[String]
town <- arbitrary[String]
county <- arbitrary[Option[String]]
country <- arbitrary[Option[String]]
country <- arbitrary[Option[Country]]
} yield AddressLookup(addressLine1, addressLine2, addressLine3, addressLine4, town, county, postCode, country)
}

Expand Down Expand Up @@ -137,7 +137,7 @@ trait ModelGenerators extends RegexConstants with Generators {
IsFIUser = isFIUser,
IsFATCAReporting = isFATCAReporting,
AddressDetails = addressDetails,
PrimaryContactDetails = primaryContactDetails,
PrimaryContactDetails = Some(primaryContactDetails),
SecondaryContactDetails = secondaryContactDetails
)
}
Expand Down
8 changes: 4 additions & 4 deletions test/base/SpecBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ trait SpecBase extends AnyFreeSpec with Matchers with TryValues with OptionValue
IsFIUser = true,
IsFATCAReporting = true,
AddressDetails("22", Some("High Street"), "Dawley", Some("Dawley"), Some("GB"), Some("TF22 2RE")),
ContactDetails("Jane Doe", "[email protected]", Some("0444458888")),
Some(ContactDetails("Jane Doe", "[email protected]", Some("0444458888"))),
Some(ContactDetails("John Doe", "[email protected]", Some("0333458888")))
)

Expand All @@ -114,7 +114,7 @@ trait SpecBase extends AnyFreeSpec with Matchers with TryValues with OptionValue
IsFIUser = true,
IsFATCAReporting = true,
AddressDetails("22", Some("High Street"), "Dawley", Some("Dawley"), Some("GB"), Some("TF22 2RE")),
ContactDetails("Jane Doe", "[email protected]", Some("0444458888")),
Some(ContactDetails("Jane Doe", "[email protected]", Some("0444458888"))),
Some(ContactDetails("John Doe", "[email protected]", Some("0333458888")))
),
FIDetail(
Expand All @@ -125,7 +125,7 @@ trait SpecBase extends AnyFreeSpec with Matchers with TryValues with OptionValue
IsFIUser = true,
IsFATCAReporting = true,
AddressDetails("22", Some("High Street"), "Dawley", Some("Dawley"), Some("GB"), Some("TF22 2RE")),
ContactDetails("Foo Bar", "[email protected]", Some("0223458888")),
Some(ContactDetails("Foo Bar", "[email protected]", Some("0223458888"))),
Some(ContactDetails("Foobar Baz", "[email protected]", Some("0123456789")))
)
)
Expand Down Expand Up @@ -207,7 +207,7 @@ trait SpecBase extends AnyFreeSpec with Matchers with TryValues with OptionValue

val testAddress: Address = Address("value 1", Some("value 2"), "value 3", Some("value 4"), Some("XX9 9XX"), Country.GB)
val testAddressResponse: AddressResponse = AddressResponse("value 1", Some("value 2"), Some("value 3"), Some("value 4"), Some("XX9 9XX"), Country.GB.code)
val testAddressLookup: AddressLookup = AddressLookup(Some("1 Address line 1"), None, None, None, "Town", None, "ZZ1 1ZZ", Some("United Kingdom"))
val testAddressLookup: AddressLookup = AddressLookup(Some("1 Address line 1"), None, None, None, "Town", None, "ZZ1 1ZZ", Some(Country.GB))

implicit val hc: HeaderCarrier = HeaderCarrier()
def emptyUserAnswers: UserAnswers = UserAnswers(userAnswersId)
Expand Down
Loading

0 comments on commit 276d972

Please sign in to comment.