Skip to content

Commit

Permalink
Merge pull request #278 from hmrc/ITSASU-3682
Browse files Browse the repository at this point in the history
ITSASU-3682 - Fixed missing postcode resolving as null in the submitt…
  • Loading branch information
ILee15 authored Feb 21, 2025
2 parents 25f9aa2 + be629b0 commit 5563abb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/models/subscription/CreateIncomeSourcesModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ object CreateIncomeSourcesModel {
def addressDetailsJson(businessAddressModel: BusinessAddressModel): JsObject = {
Json.obj(
"addressLine1" -> businessAddressModel.address.lines.headOption.getOrElse(throwError("addressLine1")),
"postalCode" -> businessAddressModel.address.postcode,
"countryCode" -> "GB"
) ++
businessAddressModel.address.postcode.map(value => Json.obj("postalCode" -> value)) ++
businessAddressModel.address.lines.lift(1).map(value => Json.obj("addressLine2" -> value)) ++
businessAddressModel.address.lines.lift(2).map(value => Json.obj("addressLine3" -> value)) ++
businessAddressModel.address.lines.lift(3).map(value => Json.obj("addressLine4" -> value))
Expand Down
2 changes: 1 addition & 1 deletion test/connectors/CreateIncomeSourceConnectorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CreateIncomeSourceConnectorSpec extends MockHttp with GuiceOneAppPerSuite
class Test(mtdbsaRef: String, expectedBody: JsValue, response: PostIncomeSourceResponse) {
val appConfig: AppConfig = app.injector.instanceOf[AppConfig]
val httpClient: HttpClient = mockHttpClient
val headers = Seq(
val headers: Seq[(String, String)] = Seq(
HeaderNames.authorisation -> appConfig.desAuthorisationToken,
appConfig.desEnvironmentHeader
)
Expand Down
55 changes: 54 additions & 1 deletion test/models/subscription/CreateIncomeSourcesModelSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package models.subscription

import models.DateModel
import models.subscription.business.{Accruals, Cash}
import org.scalatest.matchers.must.{Matchers => MustMatchers}
import org.scalatestplus.play.PlaySpec
import play.api.libs.json._
import uk.gov.hmrc.http.InternalServerException
import utils.TestConstants.testNino
import org.scalatest.matchers.must.{Matchers => MustMatchers}

import java.time.LocalDate

class CreateIncomeSourcesModelSpec extends PlaySpec with MustMatchers {
Expand Down Expand Up @@ -189,6 +190,34 @@ class CreateIncomeSourcesModelSpec extends PlaySpec with MustMatchers {
)
)

val fullCreateIncomeSourcesModelJsonWriteMinimal: JsObject = Json.obj(
"businessDetails" -> Json.arr(
Json.obj(
"accountingPeriodStartDate" -> desFormattedNow,
"accountingPeriodEndDate" -> desFormattedNow,
"tradingStartDate" -> desFormattedNow,
"tradingName" -> "testBusinessName",
"typeOfBusiness" -> "testBusinessTrade",
"cashOrAccrualsFlag" -> Cash.stringValue.toUpperCase,
"addressDetails" -> Json.obj(
"addressLine1" -> "line 1",
"addressLine2" -> "line 2",
"countryCode" -> "GB"
)
)
),
"ukPropertyDetails" -> Json.obj(
"tradingStartDate" -> desFormattedNow,
"cashOrAccrualsFlag" -> Accruals.stringValue.toUpperCase,
"startDate" -> desFormattedNow
),
"foreignPropertyDetails" -> Json.obj(
"tradingStartDate" -> desFormattedNow,
"cashOrAccrualsFlag" -> Cash.stringValue.toUpperCase,
"startDate" -> desFormattedNow
)
)

"CreateIncomeSourcesModel" must {
"read from json successfully" when {
"the json is complete and valid" in {
Expand All @@ -213,6 +242,30 @@ class CreateIncomeSourcesModelSpec extends PlaySpec with MustMatchers {
"all required fields are present in the model" in {
Json.toJson(fullCreateIncomeSourcesModel) mustBe fullCreateIncomeSourcesModelJsonWrite
}
"all income sources are present, but any optional fields are not present" in {
val minimalModel = CreateIncomeSourcesModel(
nino = testNino,
soleTraderBusinesses = Some(SoleTraderBusinesses(
accountingPeriod = AccountingPeriodModel(now, now),
accountingMethod = Cash,
businesses = Seq(
SelfEmploymentData(
id = "testBusinessId",
businessStartDate = Some(BusinessStartDate(now)),
businessName = Some(BusinessNameModel("testBusinessName")),
businessTradeName = Some(BusinessTradeNameModel("testBusinessTrade")),
businessAddress = Some(BusinessAddressModel(
address = Address(lines = Seq("line 1", "line 2"), postcode = None)
))
)
)
)),
ukProperty = Some(fullUkProperty),
overseasProperty = Some(fullOverseasProperty)
)

Json.toJson(minimalModel) mustBe fullCreateIncomeSourcesModelJsonWriteMinimal
}
}
"return an exception when writing to json" when {
"addressLine1 is missing in the model" in {
Expand Down

0 comments on commit 5563abb

Please # to comment.