diff --git a/app/models/subscription/BusinessSubscriptionDetailsModel.scala b/app/models/subscription/BusinessSubscriptionDetailsModel.scala index 252a320f..23c1e24b 100644 --- a/app/models/subscription/BusinessSubscriptionDetailsModel.scala +++ b/app/models/subscription/BusinessSubscriptionDetailsModel.scala @@ -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" } @@ -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"))), diff --git a/it/controllers/BusinessIncomeSourcesControllerISpec.scala b/it/controllers/BusinessIncomeSourcesControllerISpec.scala index 18997e03..2c8beb37 100644 --- a/it/controllers/BusinessIncomeSourcesControllerISpec.scala +++ b/it/controllers/BusinessIncomeSourcesControllerISpec.scala @@ -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")) )) ) ) diff --git a/test/controllers/BusinessIncomeSourcesControllerSpec.scala b/test/controllers/BusinessIncomeSourcesControllerSpec.scala index 026b4626..dfe43e1c 100644 --- a/test/controllers/BusinessIncomeSourcesControllerSpec.scala +++ b/test/controllers/BusinessIncomeSourcesControllerSpec.scala @@ -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")) )) ) ) diff --git a/test/models/monitoring/CompletedSignUpAuditSpec.scala b/test/models/monitoring/CompletedSignUpAuditSpec.scala index 371c4d9a..29bf3ef3 100644 --- a/test/models/monitoring/CompletedSignUpAuditSpec.scala +++ b/test/models/monitoring/CompletedSignUpAuditSpec.scala @@ -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( @@ -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")) )) ) ) diff --git a/test/models/subscription/BusinessSubscriptionDetailsModelSpec.scala b/test/models/subscription/BusinessSubscriptionDetailsModelSpec.scala index 7d83868a..87128d5b 100644 --- a/test/models/subscription/BusinessSubscriptionDetailsModelSpec.scala +++ b/test/models/subscription/BusinessSubscriptionDetailsModelSpec.scala @@ -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), @@ -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), @@ -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")), @@ -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), diff --git a/test/models/subscription/CreateIncomeSourcesModelSpec.scala b/test/models/subscription/CreateIncomeSourcesModelSpec.scala index 1e6e70b8..8a47bdb2 100644 --- a/test/models/subscription/CreateIncomeSourcesModelSpec.scala +++ b/test/models/subscription/CreateIncomeSourcesModelSpec.scala @@ -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")) )) ) ) @@ -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"))))) } )) )