Skip to content

Commit

Permalink
merge [ITSASU-1109] Make postcode optional in read/write model #217
Browse files Browse the repository at this point in the history
…into main
  • Loading branch information
scullythornton1 committed Apr 22, 2022
2 parents da793a1 + ec18c3a commit 8096409
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object BusinessTradeNameModel {
implicit val format: OFormat[BusinessTradeNameModel] = Json.format[BusinessTradeNameModel]
}

case class Address(lines: Seq[String], postcode: String) {
case class Address(lines: Seq[String], postcode: Option[String]) {
override def toString: String = s"${lines.mkString(", ")}, $postcode"
}

Expand Down Expand Up @@ -142,7 +142,7 @@ object BusinessSubscriptionDetailsModel {
"addressLine2" -> data.businessAddress.map(model => if(model.address.lines.length > 1) model.address.lines(1) else ""),
"addressLine3" -> data.businessAddress.map(model => if(model.address.lines.length > 2) model.address.lines(2) else ""),
"addressLine4" -> data.businessAddress.map(model => if(model.address.lines.length > 3) model.address.lines(3) else ""),
"postalCode" -> data.businessAddress.map(_.address.postcode).getOrElse(throw new Exception("Missing postalCode parameter")),
"postalCode" -> data.businessAddress.map(_.address.postcode),
"countryCode" -> "GB"
).fields.filterNot(json => withoutValue(json._2))),
"typeOfBusiness" -> JsString(data.businessTradeName.map(_.businessTradeName).getOrElse(throw new Exception("Missing tradingName parameter"))),
Expand Down
2 changes: 1 addition & 1 deletion it/controllers/BusinessIncomeSourcesControllerISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BusinessIncomeSourcesControllerISpec extends ComponentSpecBase with Featur
businessTradeName = Some(BusinessTradeNameModel("testBusinessTrade")),
businessAddress = Some(BusinessAddressModel(
auditRef = "testAuditRef",
address = Address(lines = Seq("line 1", "line 2"), postcode = "testPostcode")
address = Address(lines = Seq("line 1", "line 2"), postcode = Some("testPostcode"))
))
)
)
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/BusinessIncomeSourcesControllerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class BusinessIncomeSourcesControllerSpec extends CommonSpec
businessTradeName = Some(BusinessTradeNameModel("testBusinessTrade")),
businessAddress = Some(BusinessAddressModel(
auditRef = "testAuditRef",
address = Address(lines = Seq("line 1", "line 2"), postcode = "testPostcode")
address = Address(lines = Seq("line 1", "line 2"), postcode = Some("testPostcode"))
))
)
)
Expand Down
4 changes: 2 additions & 2 deletions test/models/monitoring/CompletedSignUpAuditSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CompletedSignUpAuditSpec extends CommonSpec with Matchers {
businessTradeName = Some(BusinessTradeNameModel("testBusinessTrade")),
businessAddress = Some(BusinessAddressModel(
auditRef = "testAuditRef",
address = Address(lines = Seq("line 1", "line 2"), postcode = "testPostcode")
address = Address(lines = Seq("line 1", "line 2"), postcode = Some("testPostcode"))
))
)
private val testSoleTraderBusinesses = SoleTraderBusinesses(
Expand All @@ -50,7 +50,7 @@ class CompletedSignUpAuditSpec extends CommonSpec with Matchers {
businessTradeName = Some(BusinessTradeNameModel("testBusinessTrade")),
businessAddress = Some(BusinessAddressModel(
auditRef = "testAuditRef",
address = Address(lines = Seq("line 1", "line 2"), postcode = "testPostcode")
address = Address(lines = Seq("line 1", "line 2"), postcode = Some("testPostcode"))
))
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BusinessSubscriptionDetailsModelSpec extends CommonSpec {
businessStartDate = Some(BusinessStartDate(DateModel("1", "1", "2017"))),
businessName = Some(BusinessNameModel("ABC Limited")),
businessTradeName = Some(BusinessTradeNameModel("Plumbing")),
businessAddress = Some(BusinessAddressModel("12345", Address(Seq("line1", "line2", "line3", "line4"), "TF3 4NT")))
businessAddress = Some(BusinessAddressModel("12345", Address(Seq("line1", "line2", "line3", "line4"), Some("TF3 4NT"))))
))),
accountingMethod = Some(Cash),
incomeSource = FeIncomeSourceModel(true, true, true),
Expand Down Expand Up @@ -67,7 +67,7 @@ class BusinessSubscriptionDetailsModelSpec extends CommonSpec {
businessStartDate = Some(BusinessStartDate(DateModel("1", "1", "2017"))),
businessName = Some(BusinessNameModel("ABC Limited")),
businessTradeName = Some(BusinessTradeNameModel("Plumbing")),
businessAddress = Some(BusinessAddressModel("12345", Address(Seq("line1", "line2", "line3"), "TF3 4NT")))
businessAddress = Some(BusinessAddressModel("12345", Address(Seq("line1", "line2", "line3"), Some("TF3 4NT"))))
))),
nino = "AA111111A",
accountingMethod = Some(Cash),
Expand All @@ -90,6 +90,37 @@ class BusinessSubscriptionDetailsModelSpec extends CommonSpec {
}
}

"Creating a model for a subscription request with all values except foreign property, address line4 and postcode" should {
val businessDetailsModel = BusinessSubscriptionDetailsModel(
accountingPeriod = AccountingPeriodModel(DateModel("6", "4", "2018"), DateModel("5", "4", "2019")),
selfEmploymentsData = Some(Seq(SelfEmploymentData(
id = "id1",
businessStartDate = Some(BusinessStartDate(DateModel("1", "1", "2017"))),
businessName = Some(BusinessNameModel("ABC Limited")),
businessTradeName = Some(BusinessTradeNameModel("Plumbing")),
businessAddress = Some(BusinessAddressModel("12345", Address(Seq("line1", "line2", "line3"), None)))
))),
nino = "AA111111A",
accountingMethod = Some(Cash),
incomeSource = FeIncomeSourceModel(true, true, false),
propertyStartDate = Some(PropertyStartDateModel(DateModel("6", "7", "2018"))),
propertyAccountingMethod = Some(AccountingMethodPropertyModel(Accruals))
)

val json = Json.obj("businessDetails" -> Json.arr(
Json.obj("accountingPeriodStartDate" -> "2018-04-06", "cashOrAccrualsFlag" -> "CASH", "typeOfBusiness" -> "Plumbing",
"addressDetails" -> Json.obj("addressLine1" -> "line1", "addressLine2" ->"line2", "addressLine3" -> "line3",
"countryCode" -> "GB"),
"tradingName" -> "ABC Limited", "tradingStartDate" -> "2017-01-01", "accountingPeriodEndDate" -> "2019-04-05")),
"ukPropertyDetails" -> Json.obj("tradingStartDate" -> "2018-07-06","cashOrAccrualsFlag" -> "ACCRUALS",
"startDate" -> "2018-04-06"))


"write from Json correctly" in {
Json.toJson(businessDetailsModel) mustBe json
}
}

"Creating a model for a subscription request with mandatory fields missing" should {
val businessDetailsModel = BusinessSubscriptionDetailsModel(
accountingPeriod = AccountingPeriodModel(DateModel("6", "4", "2018"), DateModel("5", "4", "2019")),
Expand All @@ -98,7 +129,7 @@ class BusinessSubscriptionDetailsModelSpec extends CommonSpec {
businessStartDate = None,
businessName = Some(BusinessNameModel("ABC Limited")),
businessTradeName = Some(BusinessTradeNameModel("Plumbing")),
businessAddress = Some(BusinessAddressModel("12345", Address(Seq("line1", "line2", "line3"), "TF3 4NT")))
businessAddress = Some(BusinessAddressModel("12345", Address(Seq("line1", "line2", "line3"), Some("TF3 4NT"))))
))),
nino = "AA111111A",
accountingMethod = Some(Cash),
Expand Down
4 changes: 2 additions & 2 deletions test/models/subscription/CreateIncomeSourcesModelSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class CreateIncomeSourcesModelSpec extends PlaySpec with MustMatchers {
businessTradeName = Some(BusinessTradeNameModel("testBusinessTrade")),
businessAddress = Some(BusinessAddressModel(
auditRef = "testAuditRef",
address = Address(lines = Seq("line 1", "line 2"), postcode = "testPostcode")
address = Address(lines = Seq("line 1", "line 2"), postcode = Some("testPostcode"))
))
)
)
Expand Down Expand Up @@ -221,7 +221,7 @@ class CreateIncomeSourcesModelSpec extends PlaySpec with MustMatchers {
val missingAddressLineModel = fullCreateIncomeSourcesModel.copy(
soleTraderBusinesses = Some(fullSoleTraderBusinesses.copy(
businesses = fullSoleTraderBusinesses.businesses.map { business =>
business.copy(businessAddress = business.businessAddress.map(_.copy(address = Address(lines = Nil, postcode = "testPostcode"))))
business.copy(businessAddress = business.businessAddress.map(_.copy(address = Address(lines = Nil, postcode = Some("testPostcode")))))
}
))
)
Expand Down

0 comments on commit 8096409

Please sign in to comment.