Skip to content

Commit

Permalink
Merge pull request #271 from hmrc/ITSASU-3445
Browse files Browse the repository at this point in the history
Update pre-pop logic to handle optional business name rather than man…
  • Loading branch information
ymabdulahi authored Nov 14, 2024
2 parents 92fd304 + 4c7cc9e commit 9c82de4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
8 changes: 4 additions & 4 deletions app/models/PrePopData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ object PrePopData {

}

case class PrePopSelfEmployment(name: String,
case class PrePopSelfEmployment(name: Option[String],
trade: Option[String],
address: Option[Address],
startDate: Option[DateModel],
Expand All @@ -60,7 +60,7 @@ object PrePopSelfEmployment {
private val tradeMaxLength: Int = 35
private val tradeMinLetters: Int = 2

private def fromApi(name: String,
private def fromApi(name: Option[String],
trade: String,
addressFirstLine: Option[String],
addressPostcode: Option[String],
Expand All @@ -69,7 +69,7 @@ object PrePopSelfEmployment {

// Any characters not defined in this list will be matched on and replaced by single spaces
val notAllowedCharactersRegex: String = """[^ A-Za-z0-9&'/\\.,-]"""
val adjustedName = name.replaceAll(notAllowedCharactersRegex, " ").trim
val adjustedName = name.map(_.replaceAll(notAllowedCharactersRegex, " ").trim)
val adjustedTrade = trade.replaceAll(notAllowedCharactersRegex, " ").trim

PrePopSelfEmployment(
Expand All @@ -94,7 +94,7 @@ object PrePopSelfEmployment {
}

implicit val reads: Reads[PrePopSelfEmployment] = (
(__ \ "businessName").read[String] and
(__ \ "businessName").readNullable[String] and
(__ \ "businessDescription").read[String] and
(__ \ "businessAddressFirstLine").readNullable[String] and
(__ \ "businessAddressPostcode").readNullable[String] and
Expand Down
2 changes: 1 addition & 1 deletion it/test/connectors/PrePopConnectorISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class PrePopConnectorISpec extends ComponentSpecBase {

result.futureValue shouldBe Right(PrePopData(
selfEmployment = Some(Seq(
PrePopSelfEmployment(name = "ABC", trade = Some("Plumbing"), address = None, startDate = None, accountingMethod = Cash)
PrePopSelfEmployment(name = Some("ABC"), trade = Some("Plumbing"), address = None, startDate = None, accountingMethod = Cash)
)),
ukPropertyAccountingMethod = None,
foreignPropertyAccountingMethod = None
Expand Down
17 changes: 6 additions & 11 deletions test/models/PrePopDataSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PrePopDataSpec extends PlaySpec with Matchers {
"businessDescription" -> ("A" * 36),
"accountingMethod" -> "A"
)) mustBe JsSuccess(PrePopSelfEmployment(
name = "AB 123",
name = Some("AB 123"),
trade = None,
address = None,
startDate = None,
Expand All @@ -51,7 +51,7 @@ class PrePopDataSpec extends PlaySpec with Matchers {
"businessDescription" -> "P 383",
"accountingMethod" -> "A"
)) mustBe JsSuccess(PrePopSelfEmployment(
name = "AB 123",
name = Some("AB 123"),
trade = None,
address = None,
startDate = None,
Expand All @@ -64,7 +64,7 @@ class PrePopDataSpec extends PlaySpec with Matchers {
"businessDescription" -> """!@£$%^*()_+}{":?><~`#§± AZaz09&'/\.,-""",
"accountingMethod" -> "A"
)) mustBe JsSuccess(PrePopSelfEmployment(
name = "AB 123",
name = Some("AB 123"),
trade = Some("""AZaz09&'/\.,-"""),
address = None,
startDate = None,
Expand All @@ -77,7 +77,7 @@ class PrePopDataSpec extends PlaySpec with Matchers {
"businessDescription" -> "Plumbing",
"accountingMethod" -> "A"
)) mustBe JsSuccess(PrePopSelfEmployment(
name = """AZaz09&'/\.,-""",
name = Some("""AZaz09&'/\.,-"""),
trade = Some("Plumbing"),
address = None,
startDate = None,
Expand All @@ -86,9 +86,6 @@ class PrePopDataSpec extends PlaySpec with Matchers {
}
}
"fail to read from json" when {
"business name is missing" in {
Json.fromJson[PrePopSelfEmployment](selfEmploymentJsonFull - "businessName") mustBe JsError(__ \ "businessName", "error.path.missing")
}
"business description is missing" in {
Json.fromJson[PrePopSelfEmployment](selfEmploymentJsonFull - "businessDescription") mustBe JsError(__ \ "businessDescription", "error.path.missing")
}
Expand Down Expand Up @@ -132,7 +129,7 @@ class PrePopDataSpec extends PlaySpec with Matchers {
"accountingMethod" -> Accruals.stringValue
)
lazy val selfEmploymentModelFull: PrePopSelfEmployment = PrePopSelfEmployment(
name = "AB 123",
name = Some("AB 123"),
trade = Some("EL 987"),
address = Some(Address(
lines = Seq("1 long road"),
Expand All @@ -142,17 +139,15 @@ class PrePopDataSpec extends PlaySpec with Matchers {
accountingMethod = Accruals
)
lazy val selfEmploymentJsonMinimal: JsObject = Json.obj(
"businessName" -> "AB 123",
"businessDescription" -> "PL 567",
"accountingMethod" -> "C"
)
lazy val selfEmploymentJsonWriteMinimal: JsObject = Json.obj(
"name" -> "AB 123",
"trade" -> "PL 567",
"accountingMethod" -> Cash.stringValue
)
lazy val selfEmploymentModelMinimal: PrePopSelfEmployment = PrePopSelfEmployment(
name = "AB 123",
name = None,
trade = Some("PL 567"),
address = None,
startDate = None,
Expand Down
2 changes: 1 addition & 1 deletion test/parsers/PrePopParserSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PrePopParserSpec extends CommonSpec {
"valid json is returned" in {
read(OK, Json.obj("selfEmployment" -> Json.arr(selfEmploymentJson))) shouldBe Right(PrePopData(
Some(Seq(PrePopSelfEmployment(
"ABC",
Some("ABC"),
Some("Plumbing"),
Some(Address(Seq("123 Street"), Some("ZZ1 1ZZ"))),
Some(DateModel("01", "01", "1900")),
Expand Down

0 comments on commit 9c82de4

Please sign in to comment.