diff --git a/app/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionConnector.scala b/app/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionConnector.scala index bff2e528..eb32b80b 100644 --- a/app/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionConnector.scala +++ b/app/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionConnector.scala @@ -33,16 +33,20 @@ class RetrieveAnnualSubmissionConnector @Inject() (val http: HttpClient, val app def retrieveAnnualSubmission(request: RetrieveAnnualSubmissionRequestData)(implicit hc: HeaderCarrier, ec: ExecutionContext, - correlationId: String): Future[DownstreamOutcome[RetrieveAnnualSubmissionResponse]] = { + correlationId: String + ): Future[DownstreamOutcome[RetrieveAnnualSubmissionResponse]] = { import request._ import schema._ val downstreamUri: DownstreamUri[DownstreamResp] = - if (taxYear.useTaxYearSpecificApi) - TaxYearSpecificIfsUri(s"income-tax/${taxYear.asTysDownstream}/$nino/self-employments/$businessId/annual-summaries") - else + if (taxYear.useTaxYearSpecificApi) { + TaxYearSpecificIfsUri( + s"income-tax/${taxYear.asTysDownstream}/$nino/self-employments/$businessId/annual-summaries" + ) + } else { IfsUri(s"income-tax/nino/$nino/self-employments/$businessId/annual-summaries/${taxYear.asDownstream}") + } get(downstreamUri) } diff --git a/app/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionSchema.scala b/app/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionSchema.scala index 1a603fe3..f614f47d 100644 --- a/app/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionSchema.scala +++ b/app/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionSchema.scala @@ -16,12 +16,17 @@ package v4.retrieveAnnualSubmission +import cats.data.Validated +import cats.data.Validated.Valid +import config.SeBusinessConfig import play.api.libs.json.Reads -import shared.controllers.validators.resolvers.ResolveTaxYear +import shared.controllers.validators.resolvers.ResolveTaxYearMinimum import shared.models.domain.TaxYear +import shared.models.errors.MtdError import shared.schema.DownstreamReadable import v4.retrieveAnnualSubmission.def1.model.response.Def1_RetrieveAnnualSubmissionResponse import v4.retrieveAnnualSubmission.def2.model.response.Def2_RetrieveAnnualSubmissionResponse +import v4.retrieveAnnualSubmission.def3.model.response.Def3_RetrieveAnnualSubmissionResponse import v4.retrieveAnnualSubmission.model.response.RetrieveAnnualSubmissionResponse import scala.math.Ordered.orderingToOrdered @@ -40,16 +45,20 @@ object RetrieveAnnualSubmissionSchema { val connectorReads: Reads[DownstreamResp] = Def2_RetrieveAnnualSubmissionResponse.reads } - private val latestSchema = Def2 + case object Def3 extends RetrieveAnnualSubmissionSchema { + type DownstreamResp = Def3_RetrieveAnnualSubmissionResponse + val connectorReads: Reads[DownstreamResp] = Def3_RetrieveAnnualSubmissionResponse.reads + } + + private val resolveTaxYear = + ResolveTaxYearMinimum(minimumTaxYear = SeBusinessConfig.minimumTaxYear) - def schemaFor(taxYear: String): RetrieveAnnualSubmissionSchema = - ResolveTaxYear(taxYear).toOption - .map(schemaFor) - .getOrElse(latestSchema) + def schemaFor(taxYear: String): Validated[Seq[MtdError], RetrieveAnnualSubmissionSchema] = + resolveTaxYear(taxYear) andThen schemaFor - def schemaFor(taxYear: TaxYear): RetrieveAnnualSubmissionSchema = - if (taxYear <= TaxYear.starting(2023)) Def1 - else if (taxYear == TaxYear.starting(2024)) Def2 - else latestSchema + def schemaFor(taxYear: TaxYear): Validated[Seq[MtdError], RetrieveAnnualSubmissionSchema] = + if (taxYear >= TaxYear.fromMtd("2025-26")) Valid(Def3) + else if (taxYear == TaxYear.fromMtd("2024-25")) Valid(Def2) + else Valid(Def1) } diff --git a/app/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionValidatorFactory.scala b/app/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionValidatorFactory.scala index 3de6fec1..04b96099 100644 --- a/app/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionValidatorFactory.scala +++ b/app/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionValidatorFactory.scala @@ -16,9 +16,13 @@ package v4.retrieveAnnualSubmission +import cats.data.Validated.{Invalid, Valid} import shared.controllers.validators.Validator +import shared.models.errors.MtdError +import v4.retrieveAnnualSubmission.RetrieveAnnualSubmissionSchema.{Def1, Def2, Def3} import v4.retrieveAnnualSubmission.def1.Def1_RetrieveAnnualSubmissionValidator import v4.retrieveAnnualSubmission.def2.Def2_RetrieveAnnualSubmissionValidator +import v4.retrieveAnnualSubmission.def3.Def3_RetrieveAnnualSubmissionValidator import v4.retrieveAnnualSubmission.model.request.RetrieveAnnualSubmissionRequestData import javax.inject.{Inject, Singleton} @@ -26,12 +30,12 @@ import javax.inject.{Inject, Singleton} @Singleton class RetrieveAnnualSubmissionValidatorFactory @Inject() { - def validator(nino: String, businessId: String, taxYear: String): Validator[RetrieveAnnualSubmissionRequestData] = { + def validator(nino: String, businessId: String, taxYear: String): Validator[RetrieveAnnualSubmissionRequestData] = RetrieveAnnualSubmissionSchema.schemaFor(taxYear) match { - case RetrieveAnnualSubmissionSchema.Def1 => new Def1_RetrieveAnnualSubmissionValidator(nino, businessId, taxYear) - case RetrieveAnnualSubmissionSchema.Def2 => new Def2_RetrieveAnnualSubmissionValidator(nino, businessId, taxYear) + case Valid(Def1) => new Def1_RetrieveAnnualSubmissionValidator(nino, businessId, taxYear) + case Valid(Def2) => new Def2_RetrieveAnnualSubmissionValidator(nino, businessId, taxYear) + case Valid(Def3) => new Def3_RetrieveAnnualSubmissionValidator(nino, businessId, taxYear) + case Invalid(errors: Seq[MtdError]) => Validator.returningErrors(errors) } - } - } diff --git a/app/v4/retrieveAnnualSubmission/def1/Def1_RetrieveAnnualSubmissionValidator.scala b/app/v4/retrieveAnnualSubmission/def1/Def1_RetrieveAnnualSubmissionValidator.scala index 3f53dec2..d17278bb 100644 --- a/app/v4/retrieveAnnualSubmission/def1/Def1_RetrieveAnnualSubmissionValidator.scala +++ b/app/v4/retrieveAnnualSubmission/def1/Def1_RetrieveAnnualSubmissionValidator.scala @@ -18,9 +18,8 @@ package v4.retrieveAnnualSubmission.def1 import cats.data.Validated import cats.implicits._ -import config.SeBusinessConfig import shared.controllers.validators.Validator -import shared.controllers.validators.resolvers.{ResolveBusinessId, ResolveNino, ResolveTaxYearMinimum} +import shared.controllers.validators.resolvers.{ResolveBusinessId, ResolveNino, ResolveTaxYear} import shared.models.errors.MtdError import v4.retrieveAnnualSubmission.def1.model.request.Def1_RetrieveAnnualSubmissionRequestData import v4.retrieveAnnualSubmission.model.request.RetrieveAnnualSubmissionRequestData @@ -31,14 +30,11 @@ class Def1_RetrieveAnnualSubmissionValidator( taxYear: String ) extends Validator[RetrieveAnnualSubmissionRequestData] { - private val resolveTaxYear = - ResolveTaxYearMinimum(minimumTaxYear = SeBusinessConfig.minimumTaxYear) - def validate: Validated[Seq[MtdError], RetrieveAnnualSubmissionRequestData] = ( ResolveNino(nino), ResolveBusinessId(businessId), - resolveTaxYear(taxYear) + ResolveTaxYear(taxYear) ).mapN(Def1_RetrieveAnnualSubmissionRequestData) } diff --git a/app/v4/retrieveAnnualSubmission/def1/model/response/Def1_RetrieveAnnualSubmissionResponse.scala b/app/v4/retrieveAnnualSubmission/def1/model/response/Def1_RetrieveAnnualSubmissionResponse.scala index d1d1f2b7..795daf85 100644 --- a/app/v4/retrieveAnnualSubmission/def1/model/response/Def1_RetrieveAnnualSubmissionResponse.scala +++ b/app/v4/retrieveAnnualSubmission/def1/model/response/Def1_RetrieveAnnualSubmissionResponse.scala @@ -21,17 +21,17 @@ import play.api.libs.json.{JsPath, Json, OWrites, Reads} import v4.retrieveAnnualSubmission.model.response.RetrieveAnnualSubmissionResponse case class Def1_RetrieveAnnualSubmissionResponse( - adjustments: Option[Retrieve_Adjustments], - allowances: Option[Retrieve_Allowances], - nonFinancials: Option[Retrieve_NonFinancials] + adjustments: Option[RetrieveAdjustments], + allowances: Option[RetrieveAllowances], + nonFinancials: Option[RetrieveNonFinancials] ) extends RetrieveAnnualSubmissionResponse object Def1_RetrieveAnnualSubmissionResponse { implicit val reads: Reads[Def1_RetrieveAnnualSubmissionResponse] = ( - (JsPath \ "annualAdjustments").readNullable[Retrieve_Adjustments] and - (JsPath \ "annualAllowances").readNullable[Retrieve_Allowances] and - (JsPath \ "annualNonFinancials").readNullable[Retrieve_NonFinancials] + (JsPath \ "annualAdjustments").readNullable[RetrieveAdjustments] and + (JsPath \ "annualAllowances").readNullable[RetrieveAllowances] and + (JsPath \ "annualNonFinancials").readNullable[RetrieveNonFinancials] )(Def1_RetrieveAnnualSubmissionResponse.apply _) implicit val writes: OWrites[Def1_RetrieveAnnualSubmissionResponse] = Json.writes[Def1_RetrieveAnnualSubmissionResponse] diff --git a/app/v4/retrieveAnnualSubmission/def1/model/response/RetrieveAdjustments.scala b/app/v4/retrieveAnnualSubmission/def1/model/response/RetrieveAdjustments.scala new file mode 100644 index 00000000..56defc95 --- /dev/null +++ b/app/v4/retrieveAnnualSubmission/def1/model/response/RetrieveAdjustments.scala @@ -0,0 +1,33 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def1.model.response + +import play.api.libs.json.{Format, Json} + +case class RetrieveAdjustments(includedNonTaxableProfits: Option[BigDecimal], + basisAdjustment: Option[BigDecimal], + overlapReliefUsed: Option[BigDecimal], + accountingAdjustment: Option[BigDecimal], + averagingAdjustment: Option[BigDecimal], + outstandingBusinessIncome: Option[BigDecimal], + balancingChargeBpra: Option[BigDecimal], + balancingChargeOther: Option[BigDecimal], + goodsAndServicesOwnUse: Option[BigDecimal]) + +object RetrieveAdjustments { + implicit val format: Format[RetrieveAdjustments] = Json.format[RetrieveAdjustments] +} diff --git a/app/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_Allowances.scala b/app/v4/retrieveAnnualSubmission/def1/model/response/RetrieveAllowances.scala similarity index 56% rename from app/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_Allowances.scala rename to app/v4/retrieveAnnualSubmission/def1/model/response/RetrieveAllowances.scala index 412c2228..352d6493 100644 --- a/app/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_Allowances.scala +++ b/app/v4/retrieveAnnualSubmission/def1/model/response/RetrieveAllowances.scala @@ -19,23 +19,23 @@ package v4.retrieveAnnualSubmission.def1.model.response import play.api.libs.functional.syntax._ import play.api.libs.json.{JsPath, Json, OWrites, Reads} -case class Retrieve_Allowances(annualInvestmentAllowance: Option[BigDecimal], - businessPremisesRenovationAllowance: Option[BigDecimal], - capitalAllowanceMainPool: Option[BigDecimal], - capitalAllowanceSpecialRatePool: Option[BigDecimal], - zeroEmissionsGoodsVehicleAllowance: Option[BigDecimal], - enhancedCapitalAllowance: Option[BigDecimal], - allowanceOnSales: Option[BigDecimal], - capitalAllowanceSingleAssetPool: Option[BigDecimal], - tradingIncomeAllowance: Option[BigDecimal], - electricChargePointAllowance: Option[BigDecimal], - zeroEmissionsCarAllowance: Option[BigDecimal], - structuredBuildingAllowance: Option[Seq[Retrieve_StructuredBuildingAllowance]], - enhancedStructuredBuildingAllowance: Option[Seq[Retrieve_StructuredBuildingAllowance]]) +case class RetrieveAllowances(annualInvestmentAllowance: Option[BigDecimal], + businessPremisesRenovationAllowance: Option[BigDecimal], + capitalAllowanceMainPool: Option[BigDecimal], + capitalAllowanceSpecialRatePool: Option[BigDecimal], + zeroEmissionsGoodsVehicleAllowance: Option[BigDecimal], + enhancedCapitalAllowance: Option[BigDecimal], + allowanceOnSales: Option[BigDecimal], + capitalAllowanceSingleAssetPool: Option[BigDecimal], + tradingIncomeAllowance: Option[BigDecimal], + electricChargePointAllowance: Option[BigDecimal], + zeroEmissionsCarAllowance: Option[BigDecimal], + structuredBuildingAllowance: Option[Seq[RetrieveStructuredBuildingAllowance]], + enhancedStructuredBuildingAllowance: Option[Seq[RetrieveStructuredBuildingAllowance]]) -object Retrieve_Allowances { +object RetrieveAllowances { - implicit val reads: Reads[Retrieve_Allowances] = ( + implicit val reads: Reads[RetrieveAllowances] = ( (JsPath \ "annualInvestmentAllowance").readNullable[BigDecimal] and (JsPath \ "businessPremisesRenovationAllowance").readNullable[BigDecimal] and (JsPath \ "capitalAllowanceMainPool").readNullable[BigDecimal] and @@ -47,10 +47,10 @@ object Retrieve_Allowances { (JsPath \ "tradingIncomeAllowance").readNullable[BigDecimal] and (JsPath \ "electricChargePointAllowance").readNullable[BigDecimal] and (JsPath \ "zeroEmissionsCarAllowance").readNullable[BigDecimal] and - (JsPath \ "structuredBuildingAllowance").readNullable[Seq[Retrieve_StructuredBuildingAllowance]] and - (JsPath \ "enhancedStructuredBuildingAllowance").readNullable[Seq[Retrieve_StructuredBuildingAllowance]] - )(Retrieve_Allowances.apply _) + (JsPath \ "structuredBuildingAllowance").readNullable[Seq[RetrieveStructuredBuildingAllowance]] and + (JsPath \ "enhancedStructuredBuildingAllowance").readNullable[Seq[RetrieveStructuredBuildingAllowance]] + )(RetrieveAllowances.apply _) - implicit val writes: OWrites[Retrieve_Allowances] = Json.writes[Retrieve_Allowances] + implicit val writes: OWrites[RetrieveAllowances] = Json.writes[RetrieveAllowances] } diff --git a/app/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_Building.scala b/app/v4/retrieveAnnualSubmission/def1/model/response/RetrieveBuilding.scala similarity index 76% rename from app/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_Building.scala rename to app/v4/retrieveAnnualSubmission/def1/model/response/RetrieveBuilding.scala index 3f6673c5..196c4358 100644 --- a/app/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_Building.scala +++ b/app/v4/retrieveAnnualSubmission/def1/model/response/RetrieveBuilding.scala @@ -19,15 +19,15 @@ package v4.retrieveAnnualSubmission.def1.model.response import play.api.libs.functional.syntax._ import play.api.libs.json.{JsPath, Json, OWrites, Reads} -case class Retrieve_Building(name: Option[String], number: Option[String], postcode: String) +case class RetrieveBuilding(name: Option[String], number: Option[String], postcode: String) -object Retrieve_Building { - implicit val writes: OWrites[Retrieve_Building] = Json.writes[Retrieve_Building] +object RetrieveBuilding { + implicit val writes: OWrites[RetrieveBuilding] = Json.writes[RetrieveBuilding] - implicit val reads: Reads[Retrieve_Building] = ( + implicit val reads: Reads[RetrieveBuilding] = ( (JsPath \ "name").readNullable[String] and (JsPath \ "number").readNullable[String] and (JsPath \ "postCode").read[String] - )(Retrieve_Building.apply _) + )(RetrieveBuilding.apply _) } diff --git a/app/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_FirstYear.scala b/app/v4/retrieveAnnualSubmission/def1/model/response/RetrieveFirstYear.scala similarity index 77% rename from app/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_FirstYear.scala rename to app/v4/retrieveAnnualSubmission/def1/model/response/RetrieveFirstYear.scala index 73299697..33fbaf99 100644 --- a/app/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_FirstYear.scala +++ b/app/v4/retrieveAnnualSubmission/def1/model/response/RetrieveFirstYear.scala @@ -18,8 +18,8 @@ package v4.retrieveAnnualSubmission.def1.model.response import play.api.libs.json.{Json, OFormat} -case class Retrieve_FirstYear(qualifyingDate: String, qualifyingAmountExpenditure: BigDecimal) +case class RetrieveFirstYear(qualifyingDate: String, qualifyingAmountExpenditure: BigDecimal) -object Retrieve_FirstYear { - implicit val format: OFormat[Retrieve_FirstYear] = Json.format[Retrieve_FirstYear] +object RetrieveFirstYear { + implicit val format: OFormat[RetrieveFirstYear] = Json.format[RetrieveFirstYear] } diff --git a/app/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_NonFinancials.scala b/app/v4/retrieveAnnualSubmission/def1/model/response/RetrieveNonFinancials.scala similarity index 74% rename from app/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_NonFinancials.scala rename to app/v4/retrieveAnnualSubmission/def1/model/response/RetrieveNonFinancials.scala index a0899589..04fe1fd1 100644 --- a/app/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_NonFinancials.scala +++ b/app/v4/retrieveAnnualSubmission/def1/model/response/RetrieveNonFinancials.scala @@ -20,14 +20,14 @@ import api.models.domain.ex.{DownstreamNicExemption, MtdNicExemption} import play.api.libs.functional.syntax._ import play.api.libs.json.{JsPath, Json, OWrites, Reads} -case class Retrieve_NonFinancials(businessDetailsChangedRecently: Boolean, class4NicsExemptionReason: Option[MtdNicExemption]) +case class RetrieveNonFinancials(businessDetailsChangedRecently: Boolean, class4NicsExemptionReason: Option[MtdNicExemption]) -object Retrieve_NonFinancials { - implicit val writes: OWrites[Retrieve_NonFinancials] = Json.writes[Retrieve_NonFinancials] +object RetrieveNonFinancials { + implicit val writes: OWrites[RetrieveNonFinancials] = Json.writes[RetrieveNonFinancials] - implicit val reads: Reads[Retrieve_NonFinancials] = ( + implicit val reads: Reads[RetrieveNonFinancials] = ( (JsPath \ "businessDetailsChangedRecently").read[Boolean] and (JsPath \ "class4NicsExemptionReason").readNullable[DownstreamNicExemption].map(_.map(_.toMtd)) - )(Retrieve_NonFinancials.apply _) + )(RetrieveNonFinancials.apply _) } diff --git a/app/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_StructuredBuildingAllowance.scala b/app/v4/retrieveAnnualSubmission/def1/model/response/RetrieveStructuredBuildingAllowance.scala similarity index 71% rename from app/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_StructuredBuildingAllowance.scala rename to app/v4/retrieveAnnualSubmission/def1/model/response/RetrieveStructuredBuildingAllowance.scala index fe7aac24..06715284 100644 --- a/app/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_StructuredBuildingAllowance.scala +++ b/app/v4/retrieveAnnualSubmission/def1/model/response/RetrieveStructuredBuildingAllowance.scala @@ -18,15 +18,15 @@ package v4.retrieveAnnualSubmission.def1.model.response import play.api.libs.json.{Json, OFormat} -case class Retrieve_StructuredBuildingAllowance( +case class RetrieveStructuredBuildingAllowance( amount: BigDecimal, - firstYear: Option[Retrieve_FirstYear], - building: Retrieve_Building + firstYear: Option[RetrieveFirstYear], + building: RetrieveBuilding ) -object Retrieve_StructuredBuildingAllowance { +object RetrieveStructuredBuildingAllowance { - implicit val format: OFormat[Retrieve_StructuredBuildingAllowance] = - Json.format[Retrieve_StructuredBuildingAllowance] + implicit val format: OFormat[RetrieveStructuredBuildingAllowance] = + Json.format[RetrieveStructuredBuildingAllowance] } diff --git a/app/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_Adjustments.scala b/app/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_Adjustments.scala deleted file mode 100644 index bb0bb462..00000000 --- a/app/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_Adjustments.scala +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2023 HM Revenue & Customs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package v4.retrieveAnnualSubmission.def1.model.response - -import play.api.libs.json.{Format, Json} - -case class Retrieve_Adjustments(includedNonTaxableProfits: Option[BigDecimal], - basisAdjustment: Option[BigDecimal], - overlapReliefUsed: Option[BigDecimal], - accountingAdjustment: Option[BigDecimal], - averagingAdjustment: Option[BigDecimal], - outstandingBusinessIncome: Option[BigDecimal], - balancingChargeBpra: Option[BigDecimal], - balancingChargeOther: Option[BigDecimal], - goodsAndServicesOwnUse: Option[BigDecimal]) - -object Retrieve_Adjustments { - implicit val format: Format[Retrieve_Adjustments] = Json.format[Retrieve_Adjustments] -} diff --git a/app/v4/retrieveAnnualSubmission/def2/Def2_RetrieveAnnualSubmissionValidator.scala b/app/v4/retrieveAnnualSubmission/def2/Def2_RetrieveAnnualSubmissionValidator.scala index 2ba06efe..d5cd7e3d 100644 --- a/app/v4/retrieveAnnualSubmission/def2/Def2_RetrieveAnnualSubmissionValidator.scala +++ b/app/v4/retrieveAnnualSubmission/def2/Def2_RetrieveAnnualSubmissionValidator.scala @@ -18,9 +18,8 @@ package v4.retrieveAnnualSubmission.def2 import cats.data.Validated import cats.implicits._ -import config.SeBusinessConfig import shared.controllers.validators.Validator -import shared.controllers.validators.resolvers.{ResolveBusinessId, ResolveNino, ResolveTaxYearMinimum} +import shared.controllers.validators.resolvers.{ResolveBusinessId, ResolveNino, ResolveTaxYear} import shared.models.errors.MtdError import v4.retrieveAnnualSubmission.def2.model.request.Def2_RetrieveAnnualSubmissionRequestData import v4.retrieveAnnualSubmission.model.request.RetrieveAnnualSubmissionRequestData @@ -28,14 +27,11 @@ import v4.retrieveAnnualSubmission.model.request.RetrieveAnnualSubmissionRequest class Def2_RetrieveAnnualSubmissionValidator(nino: String, businessId: String, taxYear: String) extends Validator[RetrieveAnnualSubmissionRequestData] { - private val resolveTaxYear = - ResolveTaxYearMinimum(minimumTaxYear = SeBusinessConfig.minimumTaxYear) - def validate: Validated[Seq[MtdError], RetrieveAnnualSubmissionRequestData] = ( ResolveNino(nino), ResolveBusinessId(businessId), - resolveTaxYear(taxYear) + ResolveTaxYear(taxYear) ).mapN(Def2_RetrieveAnnualSubmissionRequestData) } diff --git a/app/v4/retrieveAnnualSubmission/def2/model/response/Def2_RetrieveAnnualSubmissionResponse.scala b/app/v4/retrieveAnnualSubmission/def2/model/response/Def2_RetrieveAnnualSubmissionResponse.scala index bb5b6b21..b26325bb 100644 --- a/app/v4/retrieveAnnualSubmission/def2/model/response/Def2_RetrieveAnnualSubmissionResponse.scala +++ b/app/v4/retrieveAnnualSubmission/def2/model/response/Def2_RetrieveAnnualSubmissionResponse.scala @@ -22,17 +22,17 @@ import play.api.libs.json.{JsPath, Json, OWrites, Reads} import v4.retrieveAnnualSubmission.model.response.RetrieveAnnualSubmissionResponse case class Def2_RetrieveAnnualSubmissionResponse( - adjustments: Option[Retrieve_Adjustments], - allowances: Option[Retrieve_Allowances], - nonFinancials: Option[Retrieve_NonFinancials] + adjustments: Option[RetrieveAdjustments], + allowances: Option[RetrieveAllowances], + nonFinancials: Option[RetrieveNonFinancials] ) extends RetrieveAnnualSubmissionResponse object Def2_RetrieveAnnualSubmissionResponse { implicit val reads: Reads[Def2_RetrieveAnnualSubmissionResponse] = ( - (JsPath \ "annualAdjustments").readNullable[Retrieve_Adjustments] and - (JsPath \ "annualAllowances").readNullable[Retrieve_Allowances] and - (JsPath \ "annualNonFinancials").readNullable[Retrieve_NonFinancials] + (JsPath \ "annualAdjustments").readNullable[RetrieveAdjustments] and + (JsPath \ "annualAllowances").readNullable[RetrieveAllowances] and + (JsPath \ "annualNonFinancials").readNullable[RetrieveNonFinancials] )(Def2_RetrieveAnnualSubmissionResponse.apply _) implicit def writes(implicit featureSwitches: SeBusinessFeatureSwitches): OWrites[Def2_RetrieveAnnualSubmissionResponse] = diff --git a/app/v4/retrieveAnnualSubmission/def2/model/response/RetrieveAdjustments.scala b/app/v4/retrieveAnnualSubmission/def2/model/response/RetrieveAdjustments.scala new file mode 100644 index 00000000..807b34f0 --- /dev/null +++ b/app/v4/retrieveAnnualSubmission/def2/model/response/RetrieveAdjustments.scala @@ -0,0 +1,46 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def2.model.response + +import config.SeBusinessFeatureSwitches +import play.api.libs.json.{JsObject, Json, Reads, Writes} + +case class RetrieveAdjustments(includedNonTaxableProfits: Option[BigDecimal], + basisAdjustment: Option[BigDecimal], + overlapReliefUsed: Option[BigDecimal], + accountingAdjustment: Option[BigDecimal], + averagingAdjustment: Option[BigDecimal], + outstandingBusinessIncome: Option[BigDecimal], + balancingChargeBpra: Option[BigDecimal], + balancingChargeOther: Option[BigDecimal], + goodsAndServicesOwnUse: Option[BigDecimal], + transitionProfitAmount: Option[BigDecimal], + transitionProfitAccelerationAmount: Option[BigDecimal]) + +object RetrieveAdjustments { + implicit val reads: Reads[RetrieveAdjustments] = Json.reads + + implicit def writes(implicit featureSwitches: SeBusinessFeatureSwitches): Writes[RetrieveAdjustments] = Json.writes.transform { json: JsObject => + if (featureSwitches.isAdjustmentsAdditionalFieldsEnabled) { + json + } else { + json - "transitionProfitAmount" - "transitionProfitAccelerationAmount" + } + + } + +} diff --git a/app/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_Allowances.scala b/app/v4/retrieveAnnualSubmission/def2/model/response/RetrieveAllowances.scala similarity index 56% rename from app/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_Allowances.scala rename to app/v4/retrieveAnnualSubmission/def2/model/response/RetrieveAllowances.scala index 197396fd..f4935e1f 100644 --- a/app/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_Allowances.scala +++ b/app/v4/retrieveAnnualSubmission/def2/model/response/RetrieveAllowances.scala @@ -19,23 +19,23 @@ package v4.retrieveAnnualSubmission.def2.model.response import play.api.libs.functional.syntax._ import play.api.libs.json.{JsPath, Json, OWrites, Reads} -case class Retrieve_Allowances(annualInvestmentAllowance: Option[BigDecimal], - businessPremisesRenovationAllowance: Option[BigDecimal], - capitalAllowanceMainPool: Option[BigDecimal], - capitalAllowanceSpecialRatePool: Option[BigDecimal], - zeroEmissionsGoodsVehicleAllowance: Option[BigDecimal], - enhancedCapitalAllowance: Option[BigDecimal], - allowanceOnSales: Option[BigDecimal], - capitalAllowanceSingleAssetPool: Option[BigDecimal], - tradingIncomeAllowance: Option[BigDecimal], - electricChargePointAllowance: Option[BigDecimal], - zeroEmissionsCarAllowance: Option[BigDecimal], - structuredBuildingAllowance: Option[Seq[Retrieve_StructuredBuildingAllowance]], - enhancedStructuredBuildingAllowance: Option[Seq[Retrieve_StructuredBuildingAllowance]]) +case class RetrieveAllowances(annualInvestmentAllowance: Option[BigDecimal], + businessPremisesRenovationAllowance: Option[BigDecimal], + capitalAllowanceMainPool: Option[BigDecimal], + capitalAllowanceSpecialRatePool: Option[BigDecimal], + zeroEmissionsGoodsVehicleAllowance: Option[BigDecimal], + enhancedCapitalAllowance: Option[BigDecimal], + allowanceOnSales: Option[BigDecimal], + capitalAllowanceSingleAssetPool: Option[BigDecimal], + tradingIncomeAllowance: Option[BigDecimal], + electricChargePointAllowance: Option[BigDecimal], + zeroEmissionsCarAllowance: Option[BigDecimal], + structuredBuildingAllowance: Option[Seq[RetrieveStructuredBuildingAllowance]], + enhancedStructuredBuildingAllowance: Option[Seq[RetrieveStructuredBuildingAllowance]]) -object Retrieve_Allowances { +object RetrieveAllowances { - implicit val reads: Reads[Retrieve_Allowances] = ( + implicit val reads: Reads[RetrieveAllowances] = ( (JsPath \ "annualInvestmentAllowance").readNullable[BigDecimal] and (JsPath \ "businessPremisesRenovationAllowance").readNullable[BigDecimal] and (JsPath \ "capitalAllowanceMainPool").readNullable[BigDecimal] and @@ -47,10 +47,10 @@ object Retrieve_Allowances { (JsPath \ "tradingIncomeAllowance").readNullable[BigDecimal] and (JsPath \ "electricChargePointAllowance").readNullable[BigDecimal] and (JsPath \ "zeroEmissionsCarAllowance").readNullable[BigDecimal] and - (JsPath \ "structuredBuildingAllowance").readNullable[Seq[Retrieve_StructuredBuildingAllowance]] and - (JsPath \ "enhancedStructuredBuildingAllowance").readNullable[Seq[Retrieve_StructuredBuildingAllowance]] - )(Retrieve_Allowances.apply _) + (JsPath \ "structuredBuildingAllowance").readNullable[Seq[RetrieveStructuredBuildingAllowance]] and + (JsPath \ "enhancedStructuredBuildingAllowance").readNullable[Seq[RetrieveStructuredBuildingAllowance]] + )(RetrieveAllowances.apply _) - implicit val writes: OWrites[Retrieve_Allowances] = Json.writes[Retrieve_Allowances] + implicit val writes: OWrites[RetrieveAllowances] = Json.writes[RetrieveAllowances] } diff --git a/app/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_Building.scala b/app/v4/retrieveAnnualSubmission/def2/model/response/RetrieveBuilding.scala similarity index 76% rename from app/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_Building.scala rename to app/v4/retrieveAnnualSubmission/def2/model/response/RetrieveBuilding.scala index f290ca04..d8430c47 100644 --- a/app/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_Building.scala +++ b/app/v4/retrieveAnnualSubmission/def2/model/response/RetrieveBuilding.scala @@ -19,15 +19,15 @@ package v4.retrieveAnnualSubmission.def2.model.response import play.api.libs.functional.syntax._ import play.api.libs.json.{JsPath, Json, OWrites, Reads} -case class Retrieve_Building(name: Option[String], number: Option[String], postcode: String) +case class RetrieveBuilding(name: Option[String], number: Option[String], postcode: String) -object Retrieve_Building { - implicit val writes: OWrites[Retrieve_Building] = Json.writes[Retrieve_Building] +object RetrieveBuilding { + implicit val writes: OWrites[RetrieveBuilding] = Json.writes[RetrieveBuilding] - implicit val reads: Reads[Retrieve_Building] = ( + implicit val reads: Reads[RetrieveBuilding] = ( (JsPath \ "name").readNullable[String] and (JsPath \ "number").readNullable[String] and (JsPath \ "postCode").read[String] - )(Retrieve_Building.apply _) + )(RetrieveBuilding.apply _) } diff --git a/app/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_FirstYear.scala b/app/v4/retrieveAnnualSubmission/def2/model/response/RetrieveFirstYear.scala similarity index 77% rename from app/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_FirstYear.scala rename to app/v4/retrieveAnnualSubmission/def2/model/response/RetrieveFirstYear.scala index c9a090fc..bf8869e0 100644 --- a/app/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_FirstYear.scala +++ b/app/v4/retrieveAnnualSubmission/def2/model/response/RetrieveFirstYear.scala @@ -18,8 +18,8 @@ package v4.retrieveAnnualSubmission.def2.model.response import play.api.libs.json.{Json, OFormat} -case class Retrieve_FirstYear(qualifyingDate: String, qualifyingAmountExpenditure: BigDecimal) +case class RetrieveFirstYear(qualifyingDate: String, qualifyingAmountExpenditure: BigDecimal) -object Retrieve_FirstYear { - implicit val format: OFormat[Retrieve_FirstYear] = Json.format[Retrieve_FirstYear] +object RetrieveFirstYear { + implicit val format: OFormat[RetrieveFirstYear] = Json.format[RetrieveFirstYear] } diff --git a/app/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_NonFinancials.scala b/app/v4/retrieveAnnualSubmission/def2/model/response/RetrieveNonFinancials.scala similarity index 74% rename from app/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_NonFinancials.scala rename to app/v4/retrieveAnnualSubmission/def2/model/response/RetrieveNonFinancials.scala index 32e67e93..2ec94adf 100644 --- a/app/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_NonFinancials.scala +++ b/app/v4/retrieveAnnualSubmission/def2/model/response/RetrieveNonFinancials.scala @@ -20,14 +20,14 @@ import api.models.domain.ex.{DownstreamNicExemption, MtdNicExemption} import play.api.libs.functional.syntax._ import play.api.libs.json.{JsPath, Json, OWrites, Reads} -case class Retrieve_NonFinancials(businessDetailsChangedRecently: Boolean, class4NicsExemptionReason: Option[MtdNicExemption]) +case class RetrieveNonFinancials(businessDetailsChangedRecently: Boolean, class4NicsExemptionReason: Option[MtdNicExemption]) -object Retrieve_NonFinancials { - implicit val writes: OWrites[Retrieve_NonFinancials] = Json.writes[Retrieve_NonFinancials] +object RetrieveNonFinancials { + implicit val writes: OWrites[RetrieveNonFinancials] = Json.writes[RetrieveNonFinancials] - implicit val reads: Reads[Retrieve_NonFinancials] = ( + implicit val reads: Reads[RetrieveNonFinancials] = ( (JsPath \ "businessDetailsChangedRecently").read[Boolean] and (JsPath \ "class4NicsExemptionReason").readNullable[DownstreamNicExemption].map(_.map(_.toMtd)) - )(Retrieve_NonFinancials.apply _) + )(RetrieveNonFinancials.apply _) } diff --git a/app/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_StructuredBuildingAllowance.scala b/app/v4/retrieveAnnualSubmission/def2/model/response/RetrieveStructuredBuildingAllowance.scala similarity index 71% rename from app/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_StructuredBuildingAllowance.scala rename to app/v4/retrieveAnnualSubmission/def2/model/response/RetrieveStructuredBuildingAllowance.scala index ded8eb1d..674302f6 100644 --- a/app/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_StructuredBuildingAllowance.scala +++ b/app/v4/retrieveAnnualSubmission/def2/model/response/RetrieveStructuredBuildingAllowance.scala @@ -18,15 +18,15 @@ package v4.retrieveAnnualSubmission.def2.model.response import play.api.libs.json.{Json, OFormat} -case class Retrieve_StructuredBuildingAllowance( +case class RetrieveStructuredBuildingAllowance( amount: BigDecimal, - firstYear: Option[Retrieve_FirstYear], - building: Retrieve_Building + firstYear: Option[RetrieveFirstYear], + building: RetrieveBuilding ) -object Retrieve_StructuredBuildingAllowance { +object RetrieveStructuredBuildingAllowance { - implicit val format: OFormat[Retrieve_StructuredBuildingAllowance] = - Json.format[Retrieve_StructuredBuildingAllowance] + implicit val format: OFormat[RetrieveStructuredBuildingAllowance] = + Json.format[RetrieveStructuredBuildingAllowance] } diff --git a/app/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_Adjustments.scala b/app/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_Adjustments.scala deleted file mode 100644 index b5a51ac7..00000000 --- a/app/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_Adjustments.scala +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2023 HM Revenue & Customs - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package v4.retrieveAnnualSubmission.def2.model.response - -import config.SeBusinessFeatureSwitches -import play.api.libs.json.{JsObject, Json, Reads, Writes} - -case class Retrieve_Adjustments(includedNonTaxableProfits: Option[BigDecimal], - basisAdjustment: Option[BigDecimal], - overlapReliefUsed: Option[BigDecimal], - accountingAdjustment: Option[BigDecimal], - averagingAdjustment: Option[BigDecimal], - outstandingBusinessIncome: Option[BigDecimal], - balancingChargeBpra: Option[BigDecimal], - balancingChargeOther: Option[BigDecimal], - goodsAndServicesOwnUse: Option[BigDecimal], - transitionProfitAmount: Option[BigDecimal], - transitionProfitAccelerationAmount: Option[BigDecimal]) - -object Retrieve_Adjustments { - implicit val reads: Reads[Retrieve_Adjustments] = Json.reads - - implicit def writes(implicit featureSwitches: SeBusinessFeatureSwitches): Writes[Retrieve_Adjustments] = Json.writes.transform { json: JsObject => - if (featureSwitches.isAdjustmentsAdditionalFieldsEnabled) - json - else - json - "transitionProfitAmount" - "transitionProfitAccelerationAmount" - - } - -} diff --git a/app/v4/retrieveAnnualSubmission/def3/Def3_RetrieveAnnualSubmissionValidator.scala b/app/v4/retrieveAnnualSubmission/def3/Def3_RetrieveAnnualSubmissionValidator.scala new file mode 100644 index 00000000..d438b317 --- /dev/null +++ b/app/v4/retrieveAnnualSubmission/def3/Def3_RetrieveAnnualSubmissionValidator.scala @@ -0,0 +1,37 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def3 + +import cats.data.Validated +import cats.implicits._ +import shared.controllers.validators.Validator +import shared.controllers.validators.resolvers.{ResolveBusinessId, ResolveNino, ResolveTaxYear} +import shared.models.errors.MtdError +import v4.retrieveAnnualSubmission.def3.model.request.Def3_RetrieveAnnualSubmissionRequestData +import v4.retrieveAnnualSubmission.model.request.RetrieveAnnualSubmissionRequestData + +class Def3_RetrieveAnnualSubmissionValidator(nino: String, businessId: String, taxYear: String) + extends Validator[RetrieveAnnualSubmissionRequestData] { + + def validate: Validated[Seq[MtdError], RetrieveAnnualSubmissionRequestData] = + ( + ResolveNino(nino), + ResolveBusinessId(businessId), + ResolveTaxYear(taxYear) + ).mapN(Def3_RetrieveAnnualSubmissionRequestData) + +} diff --git a/app/v4/retrieveAnnualSubmission/def3/model/request/Def3_RetrieveAnnualSubmissionRequestData.scala b/app/v4/retrieveAnnualSubmission/def3/model/request/Def3_RetrieveAnnualSubmissionRequestData.scala new file mode 100644 index 00000000..12abd410 --- /dev/null +++ b/app/v4/retrieveAnnualSubmission/def3/model/request/Def3_RetrieveAnnualSubmissionRequestData.scala @@ -0,0 +1,26 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def3.model.request + +import shared.models.domain.{BusinessId, Nino, TaxYear} +import v4.retrieveAnnualSubmission.RetrieveAnnualSubmissionSchema +import v4.retrieveAnnualSubmission.model.request.RetrieveAnnualSubmissionRequestData + +case class Def3_RetrieveAnnualSubmissionRequestData(nino: Nino, businessId: BusinessId, taxYear: TaxYear) + extends RetrieveAnnualSubmissionRequestData { + override val schema: RetrieveAnnualSubmissionSchema = RetrieveAnnualSubmissionSchema.Def3 +} diff --git a/app/v4/retrieveAnnualSubmission/def3/model/response/Def3_RetrieveAnnualSubmissionResponse.scala b/app/v4/retrieveAnnualSubmission/def3/model/response/Def3_RetrieveAnnualSubmissionResponse.scala new file mode 100644 index 00000000..903c8d79 --- /dev/null +++ b/app/v4/retrieveAnnualSubmission/def3/model/response/Def3_RetrieveAnnualSubmissionResponse.scala @@ -0,0 +1,41 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def3.model.response + +import config.SeBusinessFeatureSwitches +import play.api.libs.functional.syntax._ +import play.api.libs.json.{JsPath, Json, OWrites, Reads} +import v4.retrieveAnnualSubmission.model.response.RetrieveAnnualSubmissionResponse + +case class Def3_RetrieveAnnualSubmissionResponse( + adjustments: Option[RetrieveAdjustments], + allowances: Option[RetrieveAllowances], + nonFinancials: Option[RetrieveNonFinancials] +) extends RetrieveAnnualSubmissionResponse + +object Def3_RetrieveAnnualSubmissionResponse { + + implicit val reads: Reads[Def3_RetrieveAnnualSubmissionResponse] = ( + (JsPath \ "annualAdjustments").readNullable[RetrieveAdjustments] and + (JsPath \ "annualAllowances").readNullable[RetrieveAllowances] and + (JsPath \ "annualNonFinancials").readNullable[RetrieveNonFinancials] + )(Def3_RetrieveAnnualSubmissionResponse.apply _) + + implicit def writes(implicit featureSwitches: SeBusinessFeatureSwitches): OWrites[Def3_RetrieveAnnualSubmissionResponse] = + Json.writes[Def3_RetrieveAnnualSubmissionResponse] + +} diff --git a/app/v4/retrieveAnnualSubmission/def3/model/response/RetrieveAdjustments.scala b/app/v4/retrieveAnnualSubmission/def3/model/response/RetrieveAdjustments.scala new file mode 100644 index 00000000..187b3e8f --- /dev/null +++ b/app/v4/retrieveAnnualSubmission/def3/model/response/RetrieveAdjustments.scala @@ -0,0 +1,49 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def3.model.response + +import config.SeBusinessFeatureSwitches +import play.api.libs.json.{JsObject, Json, Reads, Writes} + +case class RetrieveAdjustments( + includedNonTaxableProfits: Option[BigDecimal], + basisAdjustment: Option[BigDecimal], + overlapReliefUsed: Option[BigDecimal], + accountingAdjustment: Option[BigDecimal], + averagingAdjustment: Option[BigDecimal], + outstandingBusinessIncome: Option[BigDecimal], + balancingChargeBpra: Option[BigDecimal], + balancingChargeOther: Option[BigDecimal], + goodsAndServicesOwnUse: Option[BigDecimal], + transitionProfitAmount: Option[BigDecimal], + transitionProfitAccelerationAmount: Option[BigDecimal] +) + +object RetrieveAdjustments { + implicit val reads: Reads[RetrieveAdjustments] = Json.reads + + implicit def writes(implicit featureSwitches: SeBusinessFeatureSwitches): Writes[RetrieveAdjustments] = + Json.writes.transform { json: JsObject => + if (featureSwitches.isAdjustmentsAdditionalFieldsEnabled) { + json + } else { + json - "transitionProfitAmount" - "transitionProfitAccelerationAmount" + } + + } + +} diff --git a/app/v4/retrieveAnnualSubmission/def3/model/response/RetrieveAllowances.scala b/app/v4/retrieveAnnualSubmission/def3/model/response/RetrieveAllowances.scala new file mode 100644 index 00000000..9977178a --- /dev/null +++ b/app/v4/retrieveAnnualSubmission/def3/model/response/RetrieveAllowances.scala @@ -0,0 +1,56 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def3.model.response + +import play.api.libs.functional.syntax._ +import play.api.libs.json.{JsPath, Json, OWrites, Reads} + +case class RetrieveAllowances( + annualInvestmentAllowance: Option[BigDecimal], + businessPremisesRenovationAllowance: Option[BigDecimal], + capitalAllowanceMainPool: Option[BigDecimal], + capitalAllowanceSpecialRatePool: Option[BigDecimal], + zeroEmissionsGoodsVehicleAllowance: Option[BigDecimal], + enhancedCapitalAllowance: Option[BigDecimal], + allowanceOnSales: Option[BigDecimal], + capitalAllowanceSingleAssetPool: Option[BigDecimal], + tradingIncomeAllowance: Option[BigDecimal], + zeroEmissionsCarAllowance: Option[BigDecimal], + structuredBuildingAllowance: Option[Seq[RetrieveStructuredBuildingAllowance]], + enhancedStructuredBuildingAllowance: Option[Seq[RetrieveStructuredBuildingAllowance]] +) + +object RetrieveAllowances { + + implicit val reads: Reads[RetrieveAllowances] = ( + (JsPath \ "annualInvestmentAllowance").readNullable[BigDecimal] and + (JsPath \ "businessPremisesRenovationAllowance").readNullable[BigDecimal] and + (JsPath \ "capitalAllowanceMainPool").readNullable[BigDecimal] and + (JsPath \ "capitalAllowanceSpecialRatePool").readNullable[BigDecimal] and + (JsPath \ "zeroEmissionGoodsVehicleAllowance").readNullable[BigDecimal] and + (JsPath \ "enhanceCapitalAllowance").readNullable[BigDecimal] and + (JsPath \ "allowanceOnSales").readNullable[BigDecimal] and + (JsPath \ "capitalAllowanceSingleAssetPool").readNullable[BigDecimal] and + (JsPath \ "tradingIncomeAllowance").readNullable[BigDecimal] and + (JsPath \ "zeroEmissionsCarAllowance").readNullable[BigDecimal] and + (JsPath \ "structuredBuildingAllowance").readNullable[Seq[RetrieveStructuredBuildingAllowance]] and + (JsPath \ "enhancedStructuredBuildingAllowance").readNullable[Seq[RetrieveStructuredBuildingAllowance]] + )(RetrieveAllowances.apply _) + + implicit val writes: OWrites[RetrieveAllowances] = Json.writes[RetrieveAllowances] + +} diff --git a/app/v4/retrieveAnnualSubmission/def3/model/response/RetrieveBuilding.scala b/app/v4/retrieveAnnualSubmission/def3/model/response/RetrieveBuilding.scala new file mode 100644 index 00000000..e7568ca8 --- /dev/null +++ b/app/v4/retrieveAnnualSubmission/def3/model/response/RetrieveBuilding.scala @@ -0,0 +1,33 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def3.model.response + +import play.api.libs.functional.syntax._ +import play.api.libs.json.{JsPath, Json, OWrites, Reads} + +case class RetrieveBuilding(name: Option[String], number: Option[String], postcode: String) + +object RetrieveBuilding { + implicit val writes: OWrites[RetrieveBuilding] = Json.writes[RetrieveBuilding] + + implicit val reads: Reads[RetrieveBuilding] = ( + (JsPath \ "name").readNullable[String] and + (JsPath \ "number").readNullable[String] and + (JsPath \ "postCode").read[String] + )(RetrieveBuilding.apply _) + +} diff --git a/app/v4/retrieveAnnualSubmission/def3/model/response/RetrieveFirstYear.scala b/app/v4/retrieveAnnualSubmission/def3/model/response/RetrieveFirstYear.scala new file mode 100644 index 00000000..c6d60c21 --- /dev/null +++ b/app/v4/retrieveAnnualSubmission/def3/model/response/RetrieveFirstYear.scala @@ -0,0 +1,25 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def3.model.response + +import play.api.libs.json.{Json, OFormat} + +case class RetrieveFirstYear(qualifyingDate: String, qualifyingAmountExpenditure: BigDecimal) + +object RetrieveFirstYear { + implicit val format: OFormat[RetrieveFirstYear] = Json.format[RetrieveFirstYear] +} diff --git a/app/v4/retrieveAnnualSubmission/def3/model/response/RetrieveNonFinancials.scala b/app/v4/retrieveAnnualSubmission/def3/model/response/RetrieveNonFinancials.scala new file mode 100644 index 00000000..98539bfd --- /dev/null +++ b/app/v4/retrieveAnnualSubmission/def3/model/response/RetrieveNonFinancials.scala @@ -0,0 +1,33 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def3.model.response + +import api.models.domain.ex.{DownstreamNicExemption, MtdNicExemption} +import play.api.libs.functional.syntax._ +import play.api.libs.json.{JsPath, Json, OWrites, Reads} + +case class RetrieveNonFinancials(businessDetailsChangedRecently: Boolean, class4NicsExemptionReason: Option[MtdNicExemption]) + +object RetrieveNonFinancials { + implicit val writes: OWrites[RetrieveNonFinancials] = Json.writes[RetrieveNonFinancials] + + implicit val reads: Reads[RetrieveNonFinancials] = ( + (JsPath \ "businessDetailsChangedRecently").read[Boolean] and + (JsPath \ "class4NicsExemptionReason").readNullable[DownstreamNicExemption].map(_.map(_.toMtd)) + )(RetrieveNonFinancials.apply _) + +} diff --git a/app/v4/retrieveAnnualSubmission/def3/model/response/RetrieveStructuredBuildingAllowance.scala b/app/v4/retrieveAnnualSubmission/def3/model/response/RetrieveStructuredBuildingAllowance.scala new file mode 100644 index 00000000..a8d0e845 --- /dev/null +++ b/app/v4/retrieveAnnualSubmission/def3/model/response/RetrieveStructuredBuildingAllowance.scala @@ -0,0 +1,32 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def3.model.response + +import play.api.libs.json.{Json, OFormat} + +case class RetrieveStructuredBuildingAllowance( + amount: BigDecimal, + firstYear: Option[RetrieveFirstYear], + building: RetrieveBuilding +) + +object RetrieveStructuredBuildingAllowance { + + implicit val format: OFormat[RetrieveStructuredBuildingAllowance] = + Json.format[RetrieveStructuredBuildingAllowance] + +} diff --git a/app/v4/retrieveAnnualSubmission/model/response/RetrieveAnnualSubmissionResponse.scala b/app/v4/retrieveAnnualSubmission/model/response/RetrieveAnnualSubmissionResponse.scala index 95be3538..8002f253 100644 --- a/app/v4/retrieveAnnualSubmission/model/response/RetrieveAnnualSubmissionResponse.scala +++ b/app/v4/retrieveAnnualSubmission/model/response/RetrieveAnnualSubmissionResponse.scala @@ -17,18 +17,20 @@ package v4.retrieveAnnualSubmission.model.response import config.SeBusinessFeatureSwitches -import play.api.libs.json.{Json, OWrites} +import play.api.libs.json.OWrites import shared.utils.JsonWritesUtil import v4.retrieveAnnualSubmission.def1.model.response.Def1_RetrieveAnnualSubmissionResponse import v4.retrieveAnnualSubmission.def2.model.response.Def2_RetrieveAnnualSubmissionResponse +import v4.retrieveAnnualSubmission.def3.model.response.Def3_RetrieveAnnualSubmissionResponse trait RetrieveAnnualSubmissionResponse object RetrieveAnnualSubmissionResponse extends JsonWritesUtil { implicit def writes(implicit seBusinessFeatureSwitches: SeBusinessFeatureSwitches): OWrites[RetrieveAnnualSubmissionResponse] = writesFrom { - case response: Def1_RetrieveAnnualSubmissionResponse => Json.toJsObject(response) - case response: Def2_RetrieveAnnualSubmissionResponse => Json.toJsObject(response) + case def1: Def1_RetrieveAnnualSubmissionResponse => implicitly[OWrites[Def1_RetrieveAnnualSubmissionResponse]].writes(def1) + case def2: Def2_RetrieveAnnualSubmissionResponse => implicitly[OWrites[Def2_RetrieveAnnualSubmissionResponse]].writes(def2) + case def3: Def3_RetrieveAnnualSubmissionResponse => implicitly[OWrites[Def3_RetrieveAnnualSubmissionResponse]].writes(def3) } } diff --git a/it/v4/retrieveAnnualSubmission/def1/RetrieveAnnualSubmissionControllerISpec.scala b/it/v4/retrieveAnnualSubmission/def1/Def1_RetrieveAnnualSubmissionControllerISpec.scala similarity index 98% rename from it/v4/retrieveAnnualSubmission/def1/RetrieveAnnualSubmissionControllerISpec.scala rename to it/v4/retrieveAnnualSubmission/def1/Def1_RetrieveAnnualSubmissionControllerISpec.scala index 33071abf..bb2e2c64 100644 --- a/it/v4/retrieveAnnualSubmission/def1/RetrieveAnnualSubmissionControllerISpec.scala +++ b/it/v4/retrieveAnnualSubmission/def1/Def1_RetrieveAnnualSubmissionControllerISpec.scala @@ -28,7 +28,7 @@ import shared.support.IntegrationBaseSpec import stubs.BaseDownstreamStub import v4.retrieveAnnualSubmission.def1.model.Def1_RetrieveAnnualSubmissionFixture -class RetrieveAnnualSubmissionControllerISpec extends IntegrationBaseSpec with Def1_RetrieveAnnualSubmissionFixture { +class Def1_RetrieveAnnualSubmissionControllerISpec extends IntegrationBaseSpec with Def1_RetrieveAnnualSubmissionFixture { "calling the V4 retrieve endpoint" should { diff --git a/it/v4/retrieveAnnualSubmission/def2/RetrieveAnnualSubmissionControllerISpec.scala b/it/v4/retrieveAnnualSubmission/def2/Def2_RetrieveAnnualSubmissionControllerISpec.scala similarity index 95% rename from it/v4/retrieveAnnualSubmission/def2/RetrieveAnnualSubmissionControllerISpec.scala rename to it/v4/retrieveAnnualSubmission/def2/Def2_RetrieveAnnualSubmissionControllerISpec.scala index ef3f513b..429b56a1 100644 --- a/it/v4/retrieveAnnualSubmission/def2/RetrieveAnnualSubmissionControllerISpec.scala +++ b/it/v4/retrieveAnnualSubmission/def2/Def2_RetrieveAnnualSubmissionControllerISpec.scala @@ -22,13 +22,14 @@ import play.api.http.Status._ import play.api.libs.json.Json import play.api.libs.ws.{WSRequest, WSResponse} import play.api.test.Helpers.AUTHORIZATION +import shared.models.domain.TaxYear import shared.models.errors._ import shared.services.{AuditStub, AuthStub, MtdIdLookupStub} import shared.support.IntegrationBaseSpec import stubs.BaseDownstreamStub import v4.retrieveAnnualSubmission.def2.model.Def2_RetrieveAnnualSubmissionFixture -class RetrieveAnnualSubmissionControllerISpec extends IntegrationBaseSpec with Def2_RetrieveAnnualSubmissionFixture { +class Def2_RetrieveAnnualSubmissionControllerISpec extends IntegrationBaseSpec with Def2_RetrieveAnnualSubmissionFixture { "calling the V4 retrieve endpoint" should { @@ -133,7 +134,7 @@ class RetrieveAnnualSubmissionControllerISpec extends IntegrationBaseSpec with D val businessId = "XAIS12345678910" def taxYear: String = "2024-25" - def downstreamUri: String = s"/income-tax/24-25/$nino/self-employments/$businessId/annual-summaries" + def downstreamUri: String = s"/income-tax/${TaxYear.fromMtd(taxYear).asTysDownstream}/$nino/self-employments/$businessId/annual-summaries" def setupStubs(): StubMapping diff --git a/it/v4/retrieveAnnualSubmission/def3/Def3_RetrieveAnnualSubmissionControllerISpec.scala b/it/v4/retrieveAnnualSubmission/def3/Def3_RetrieveAnnualSubmissionControllerISpec.scala new file mode 100644 index 00000000..bf913616 --- /dev/null +++ b/it/v4/retrieveAnnualSubmission/def3/Def3_RetrieveAnnualSubmissionControllerISpec.scala @@ -0,0 +1,172 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def3 + +import com.github.tomakehurst.wiremock.stubbing.StubMapping +import play.api.http.HeaderNames.ACCEPT +import play.api.http.Status._ +import play.api.libs.json.Json +import play.api.libs.ws.{WSRequest, WSResponse} +import play.api.test.Helpers.AUTHORIZATION +import shared.models.domain.TaxYear +import shared.models.errors._ +import shared.services.{AuditStub, AuthStub, MtdIdLookupStub} +import shared.support.IntegrationBaseSpec +import stubs.BaseDownstreamStub +import v4.retrieveAnnualSubmission.def3.model.Def3_RetrieveAnnualSubmissionFixture + +class Def3_RetrieveAnnualSubmissionControllerISpec extends IntegrationBaseSpec with Def3_RetrieveAnnualSubmissionFixture { + + "calling the V4 retrieve endpoint" should { + + "return a 200 status code" when { + s"any valid request is made" in new Test { + override def setupStubs(): StubMapping = { + + AuditStub.audit() + AuthStub.authorised() + MtdIdLookupStub.ninoFound(nino) + BaseDownstreamStub.onSuccess(BaseDownstreamStub.GET, downstreamUri, OK, downstreamRetrieveResponseJson) + } + + val response: WSResponse = await(request().get()) + response.status shouldBe OK + response.json shouldBe mtdRetrieveResponseJson + response.header("X-CorrelationId").nonEmpty shouldBe true + response.header("Content-Type") shouldBe Some("application/json") + } + } + + "return error according to spec" when { + "validation error" when { + def validationErrorTest( + requestNino: String, + requestBusinessId: String, + requestTaxYear: String, + expectedStatus: Int, + expectedBody: MtdError + ): Unit = + s"validation fails with ${expectedBody.code} error" in new Test { + + override val nino: String = requestNino + override val businessId: String = requestBusinessId + override val taxYear: String = requestTaxYear + + override def setupStubs(): StubMapping = { + AuditStub.audit() + AuthStub.authorised() + MtdIdLookupStub.ninoFound(requestNino) + } + + val response: WSResponse = await(request().get()) + response.status shouldBe expectedStatus + response.json shouldBe Json.toJson(expectedBody) + } + + val input = Seq( + ("AA123", "XAIS12345678910", "2021-22", BAD_REQUEST, NinoFormatError), + ("AA123456A", "203100", "2021-22", BAD_REQUEST, BusinessIdFormatError), + ("AA123456A", "XAIS12345678910", "NOT_TAX_YEAR", BAD_REQUEST, TaxYearFormatError), + ("AA123456A", "XAIS12345678910", "2020-22", BAD_REQUEST, RuleTaxYearRangeInvalidError), + ("AA123456A", "XAIS12345678910", "2016-17", BAD_REQUEST, RuleTaxYearNotSupportedError) + ) + + input.foreach(args => validationErrorTest(args._1, args._2, args._3, args._4, args._5)) + } + + "downstream service error" when { + def serviceErrorTest( + downstreamStatus: Int, + downstreamCode: String, + expectedStatus: Int, + expectedBody: MtdError + ): Unit = + s"downstream returns an $downstreamCode error and status $downstreamStatus" in new Test { + + override def setupStubs(): StubMapping = { + AuditStub.audit() + AuthStub.authorised() + MtdIdLookupStub.ninoFound(nino) + BaseDownstreamStub.onError( + BaseDownstreamStub.GET, + downstreamUri, + downstreamStatus, + errorBody(downstreamCode) + ) + } + + val response: WSResponse = await(request().get()) + response.status shouldBe expectedStatus + response.json shouldBe Json.toJson(expectedBody) + } + + val errors = Seq( + (BAD_REQUEST, "INVALID_NINO", BAD_REQUEST, NinoFormatError), + (BAD_REQUEST, "INVALID_INCOMESOURCEID", BAD_REQUEST, BusinessIdFormatError), + (BAD_REQUEST, "INVALID_TAX_YEAR", BAD_REQUEST, TaxYearFormatError), + (NOT_FOUND, "INCOME_SOURCE_NOT_FOUND", NOT_FOUND, NotFoundError), + (NOT_FOUND, "NOT_FOUND_PERIOD", NOT_FOUND, NotFoundError), + (INTERNAL_SERVER_ERROR, "INVALID_CORRELATIONID", INTERNAL_SERVER_ERROR, InternalError), + (INTERNAL_SERVER_ERROR, "SERVER_ERROR", INTERNAL_SERVER_ERROR, InternalError), + (SERVICE_UNAVAILABLE, "SERVICE_UNAVAILABLE", INTERNAL_SERVER_ERROR, InternalError) + ) + + val extraTysErrors = Seq( + (BAD_REQUEST, "INVALID_INCOMESOURCE_ID", BAD_REQUEST, BusinessIdFormatError), + (BAD_REQUEST, "INVALID_CORRELATION_ID", INTERNAL_SERVER_ERROR, InternalError), + (BAD_REQUEST, "INVALID_DELETED_RETURN_PERIOD", INTERNAL_SERVER_ERROR, InternalError), + (NOT_FOUND, "SUBMISSION_DATA_NOT_FOUND", NOT_FOUND, NotFoundError), + (NOT_FOUND, "INCOME_DATA_SOURCE_NOT_FOUND", NOT_FOUND, NotFoundError), + (UNPROCESSABLE_ENTITY, "TAX_YEAR_NOT_SUPPORTED", BAD_REQUEST, RuleTaxYearNotSupportedError) + ) + (errors ++ extraTysErrors).foreach(args => serviceErrorTest(args._1, args._2, args._3, args._4)) + } + } + } + + private trait Test { + + val nino = "AA123456A" + val businessId = "XAIS12345678910" + + def taxYear: String = "2025-26" + def downstreamUri: String = s"/income-tax/${TaxYear.fromMtd(taxYear).asTysDownstream}/$nino/self-employments/$businessId/annual-summaries" + + def setupStubs(): StubMapping + + def request(): WSRequest = { + setupStubs() + buildRequest(uri) + .withHttpHeaders( + (ACCEPT, s"application/vnd.hmrc.4.0+json"), + (AUTHORIZATION, "Bearer 123") + ) + } + + private def uri: String = s"/$nino/$businessId/annual/$taxYear" + + def errorBody(code: String): String = + s""" + | { + | "code": "$code", + | "reason": "downstream message" + | } + """.stripMargin + + } + +} diff --git a/resources/public/api/conf/4.0/examples/retrieveAnnualSubmission/def3/full_response.json b/resources/public/api/conf/4.0/examples/retrieveAnnualSubmission/def3/full_response.json new file mode 100644 index 00000000..2d4c6ae3 --- /dev/null +++ b/resources/public/api/conf/4.0/examples/retrieveAnnualSubmission/def3/full_response.json @@ -0,0 +1,60 @@ +{ + "adjustments": { + "includedNonTaxableProfits": 210, + "basisAdjustment": 178.23, + "overlapReliefUsed": 123.78, + "accountingAdjustment": 678.9, + "averagingAdjustment": 674.98, + "outstandingBusinessIncome": 342.67, + "balancingChargeBpra": 145.98, + "balancingChargeOther": 457.23, + "goodsAndServicesOwnUse": 432.9 + {{#if (enabled 'adjustmentsAdditionalFields')}}, + "transitionProfitAmount": 435.9, + "transitionProfitAccelerationAmount": 439.9 + {{/if}} + }, + "allowances": { + "annualInvestmentAllowance": 564.76, + "capitalAllowanceMainPool": 456.98, + "capitalAllowanceSpecialRatePool": 352.87, + "zeroEmissionsGoodsVehicleAllowance": 653.9, + "businessPremisesRenovationAllowance": 452.98, + "enhancedCapitalAllowance": 563.23, + "allowanceOnSales": 678.9, + "capitalAllowanceSingleAssetPool": 563.89, + "structuredBuildingAllowance": [ + { + "amount": 564.89, + "firstYear": { + "qualifyingDate": "2019-05-29", + "qualifyingAmountExpenditure": 567.67 + }, + "building": { + "name": "Victoria Building", + "number": "23", + "postcode": "TF3 5GH" + } + } + ], + "enhancedStructuredBuildingAllowance": [ + { + "amount": 445.56, + "firstYear": { + "qualifyingDate": "2019-09-29", + "qualifyingAmountExpenditure": 565.56 + }, + "building": { + "name": "Trinity House", + "number": "20", + "postcode": "TF4 7HJ" + } + } + ], + "zeroEmissionsCarAllowance": 678.78 + }, + "nonFinancials": { + "businessDetailsChangedRecently": true, + "class4NicsExemptionReason": "non-resident" + } +} diff --git a/resources/public/api/conf/4.0/examples/retrieveAnnualSubmission/def3/trading_allowance_response.json b/resources/public/api/conf/4.0/examples/retrieveAnnualSubmission/def3/trading_allowance_response.json new file mode 100644 index 00000000..95d2f0e0 --- /dev/null +++ b/resources/public/api/conf/4.0/examples/retrieveAnnualSubmission/def3/trading_allowance_response.json @@ -0,0 +1,24 @@ +{ + "adjustments": { + "includedNonTaxableProfits": 210, + "basisAdjustment": 178.23, + "overlapReliefUsed": 123.78, + "accountingAdjustment": 678.9, + "averagingAdjustment": 674.98, + "outstandingBusinessIncome": 342.67, + "balancingChargeBpra": 145.98, + "balancingChargeOther": 457.23, + "goodsAndServicesOwnUse": 432.9 + {{#if (enabled 'adjustmentsAdditionalFields')}}, + "transitionProfitAmount": 435.9, + "transitionProfitAccelerationAmount": 439.9 + {{/if}} + }, + "allowances": { + "tradingIncomeAllowance": 572.99 + }, + "nonFinancials": { + "businessDetailsChangedRecently": true, + "class4NicsExemptionReason": "non-resident" + } +} diff --git a/resources/public/api/conf/4.0/retrieve_annual_submission.yaml b/resources/public/api/conf/4.0/retrieve_annual_submission.yaml index f0820661..7930c2be 100644 --- a/resources/public/api/conf/4.0/retrieve_annual_submission.yaml +++ b/resources/public/api/conf/4.0/retrieve_annual_submission.yaml @@ -46,6 +46,7 @@ responses: oneOf: - $ref: './schemas/retrieveAnnualSubmission/def1/response.json' - $ref: './schemas/retrieveAnnualSubmission/def2/response.json' + - $ref: './schemas/retrieveAnnualSubmission/def3/response.json' examples: "With allowances response for TY 2023-24 and before": value: @@ -53,12 +54,18 @@ responses: "With trading allowances response for TY 2023-24 and before": value: $ref: './examples/retrieveAnnualSubmission/def1/trading_allowance_response.json' - "With allowances response for TY 2024-25 onwards": + "With allowances response for TY 2024-25": value: $ref: './examples/retrieveAnnualSubmission/def2/full_response.json' - "With trading allowances response for TY 2024-25 onwards": + "With trading allowances response for TY 2024-25": value: $ref: './examples/retrieveAnnualSubmission/def2/trading_allowance_response.json' + "With allowances response for TY 2025-26 onwards": + value: + $ref: './examples/retrieveAnnualSubmission/def3/full_response.json' + "With trading allowances response for TY 2025-26 onwards": + value: + $ref: './examples/retrieveAnnualSubmission/def3/trading_allowance_response.json' "400": description: Bad request diff --git a/resources/public/api/conf/4.0/schemas/retrieveAnnualSubmission/def2/response.json b/resources/public/api/conf/4.0/schemas/retrieveAnnualSubmission/def2/response.json index b625594d..95ad12a8 100644 --- a/resources/public/api/conf/4.0/schemas/retrieveAnnualSubmission/def2/response.json +++ b/resources/public/api/conf/4.0/schemas/retrieveAnnualSubmission/def2/response.json @@ -1,6 +1,6 @@ { "$schema": "http://json-schema.org/draft-04/schema#", - "title": "TY 2024-25 or later", + "title": "TY 2024-25", "description": "Retrieves a self-employment annual summary for a tax year.", "type": "object", "properties": { diff --git a/resources/public/api/conf/4.0/schemas/retrieveAnnualSubmission/def3/response.json b/resources/public/api/conf/4.0/schemas/retrieveAnnualSubmission/def3/response.json new file mode 100644 index 00000000..cc34199d --- /dev/null +++ b/resources/public/api/conf/4.0/schemas/retrieveAnnualSubmission/def3/response.json @@ -0,0 +1,286 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "TY 2025-26 or later", + "description": "Retrieves a self-employment annual summary for a tax year.", + "type": "object", + "properties": { + "adjustments": { + "type": "object", + "description": "Object containing the details about annual adjustments", + "properties": { + "includedNonTaxableProfits": { + "description": "Income, receipts and other profits included in business income or expenses but not taxable as business profits. The value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + }, + "basisAdjustment": { + "description": "If your basis period is not the same as your accounting period, enter the adjustment needed to arrive at the profit or loss for the basis period. If the adjustment needs to be taken off the profit figure, this should be negative. Between -99999999999.99 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + }, + "overlapReliefUsed": { + "description": "Overlap relief used this year. The value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + }, + "accountingAdjustment": { + "description": "Adjustment for change of accounting practice. The value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + }, + "averagingAdjustment": { + "description": "Averaging adjustment (only for farmers, market gardeners and creators of literary or artistic works) – if the adjustment needs to be taken off the profit figure, this should be negative. This value must be between -99999999999.99 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + }, + "outstandingBusinessIncome": { + "description": "Any other business income not included in other fields. The value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + }, + "balancingChargeBpra": { + "description": "Balancing charge on sale or cessation of business use (only where Business Premises Renovation Allowance has been claimed). The value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + }, + "balancingChargeOther": { + "description": "Balancing charge on sale or cessation of business use (where you have disposed of assets for more than their tax value). The value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + }, + "goodsAndServicesOwnUse": { + "description": "Value of the normal sale price of goods or stock have been taken out of the business. The value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + } + {{#if (enabled 'adjustmentsAdditionalFields')}}, + "transitionProfitAmount": { + "description": "{{#unless (releasedInProduction 'adjustmentsAdditionalFields')}}[Test only] {{/unless}}Amount of transition profit arising in this tax year for this income source. This value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + }, + "transitionProfitAccelerationAmount": { + "description": "{{#unless (releasedInProduction 'adjustmentsAdditionalFields')}}[Test only] {{/unless}}Additional amount of transition profit elected to be treated as arising in this tax year for this income source. This value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + } + {{/if}} + }, + "additionalProperties": false + }, + "allowances": { + "type": "object", + "description": "Object containing the details about annual allowances", + "properties": { + "annualInvestmentAllowance": { + "description": "Annual investment allowance on items that qualify up to the AIA amount. The value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + }, + "capitalAllowanceMainPool": { + "description": "Capital allowances at 18% on equipment, including cars with lower CO2 emissions. The value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + }, + "capitalAllowanceSpecialRatePool": { + "description": "Capital allowances at 8% on equipment, including cars with higher CO2 emissions. The value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + }, + "zeroEmissionsGoodsVehicleAllowance": { + "description": "Zero emissions goods vehicle allowance for goods vehicles purchased for business use.\n\nThe value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + }, + "businessPremisesRenovationAllowance": { + "description": "Business Premises Renovation Allowance if converting or renovating unused qualifying business premises. The value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + }, + "enhancedCapitalAllowance": { + "description": "Other enhanced capital allowances.\n\nThe value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + }, + "allowanceOnSales": { + "description": "Allowances on sale or cessation of business use (where you have disposed of assets for less than their tax value). The value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + }, + "capitalAllowanceSingleAssetPool": { + "description": "Claim to capital allowances in respect of all single asset pools. The value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + }, + "zeroEmissionsCarAllowance": { + "description": "The amount of zero emissions car allowance. The value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + }, + "tradingIncomeAllowance": { + "description": "The amount of trading allowance (can not be supplied with any other allowances). The value must be between 0 and 1000.00 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + }, + "structuredBuildingAllowance": { + "type": "array", + "description": "Details about structured building allowance", + "items": { + "type": "object", + "properties": { + "amount": { + "description": "The amount of structured building allowance.\n\nThe value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + }, + "firstYear": { + "type": "object", + "description": "Object containing the details about structured building allowance", + "properties": { + "qualifyingDate": { + "description": "The date qualified for structured building allowance. Must conform to the format YYYY-MM-DD.", + "type": "string", + "example": "2020-01-01" + }, + "qualifyingAmountExpenditure": { + "description": "The amount of qualifying expenditure. The value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "2000.99" + } + }, + "required": [ + "qualifyingDate", + "qualifyingAmountExpenditure" + ] + }, + "building": { + "type": "object", + "description": "Postcode is mandatory and minimum one of name and number field must be supplied", + "properties": { + "name": { + "description": "The name of the building.", + "type": "string", + "pattern": "^[0-9a-zA-Z{À-˿’}\\- _&`():.'^]{1,90}$", + "example": "Green Oak’s" + }, + "number": { + "description": "The number of the building.", + "type": "string", + "pattern": "^[0-9a-zA-Z{À-˿’}\\- _&`():.'^]{1,90}$", + "example": "16D" + }, + "postcode": { + "description": "The postcode for the building.", + "type": "string", + "pattern": "^[0-9a-zA-Z{À-˿’}\\- _&`():.'^]{1,90}$", + "example": "SW1A 2AA" + } + }, + "required": [ + "postcode" + ] + } + }, + "required": [ + "amount", + "building" + ] + } + }, + "enhancedStructuredBuildingAllowance": { + "type": "array", + "description": "Details about enhanced structured building allowance", + "items": { + "type": "object", + "properties": { + "amount": { + "description": "The amount of enhanced structured building allowance. The value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "5000.99" + }, + "firstYear": { + "type": "object", + "description": "Object containing the details about enhanced structured building allowance", + "properties": { + "qualifyingDate": { + "description": "The date qualified for enhanced structured building allowance. Must conform to the format YYYY-MM-DD.", + "type": "string", + "example": "2020-01-01" + }, + "qualifyingAmountExpenditure": { + "description": "The amount of qualifying expenditure. The value must be between 0 and 99999999999.99 up to 2 decimal places.", + "type": "number", + "example": "5000.99" + } + }, + "required": [ + "qualifyingDate", + "qualifyingAmountExpenditure" + ] + }, + "building": { + "type": "object", + "description": "Object holding enhanced structured building details. Postcode is mandatory and minimum one of name and number field must be supplied", + "properties": { + "name": { + "description": "The name of the building.", + "type": "string", + "pattern": "^[0-9a-zA-Z{À-˿’}\\- _&`():.'^]{1,90}$", + "example": "Green Oak’s" + }, + "number": { + "description": "The number of the building.", + "type": "string", + "pattern": "^[0-9a-zA-Z{À-˿’}\\- _&`():.'^]{1,90}$", + "example": "16D" + }, + "postcode": { + "description": "The postcode for the building.", + "type": "string", + "pattern": "^[0-9a-zA-Z{À-˿’}\\- _&`():.'^]{1,90}$", + "example": "SW1A 2AA" + } + }, + "required": [ + "postcode" + ] + } + }, + "required": [ + "amount", + "building" + ] + } + } + } + }, + "nonFinancials": { + "type": "object", + "description": "Object containing details about annual non financials", + "properties": { + "businessDetailsChangedRecently": { + "description": "A boolean to identify if business details have recently changed. The value must be true or false.", + "type": "boolean", + "example": "false" + }, + "class4NicsExemptionReason": { + "description": "If exempt from paying Class 4 National Insurance, the reason for exemption.", + "type": "string", + "enum": [ + "non-resident", + "trustee", + "diver", + "ITTOIA-2005", + "over-state-pension-age", + "under-16" + ], + "example": "non-resident" + } + }, + "required": [ + "businessDetailsChangedRecently" + ] + } + }, + "additionalProperties": false +} diff --git a/test/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionSchemaSpec.scala b/test/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionSchemaSpec.scala index 13ff6e43..6caca89f 100644 --- a/test/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionSchemaSpec.scala +++ b/test/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionSchemaSpec.scala @@ -16,29 +16,47 @@ package v4.retrieveAnnualSubmission +import cats.data.Validated.{Invalid, Valid} import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks import shared.models.domain.{TaxYear, TaxYearPropertyCheckSupport} +import shared.models.errors.{RuleTaxYearNotSupportedError, RuleTaxYearRangeInvalidError, TaxYearFormatError} import shared.utils.UnitSpec import v4.retrieveAnnualSubmission.RetrieveAnnualSubmissionSchema._ class RetrieveAnnualSubmissionSchemaSpec extends UnitSpec with ScalaCheckDrivenPropertyChecks with TaxYearPropertyCheckSupport { - "Getting a schema" when { - "use Def1 for tax years before 2024-25" in { - forTaxYearsBefore(TaxYear.fromMtd("2024-25")) { taxYear => - schemaFor(taxYear.asMtd) shouldBe Def1 + "RetrieveAnnualSubmissionSchema" when { + "a correctly formatted tax year is supplied" must { + "use Def1 for tax years between 2017-18 and 2023-24" in { + forTaxYearsInRange(TaxYear.fromMtd("2017-18"), TaxYear.fromMtd("2023-24")) { taxYear => + schemaFor(taxYear.asMtd) shouldBe Valid(Def1) + } + } + + "use Def2 for tax year 2024-25" in { + schemaFor(TaxYear.fromMtd("2024-25")) shouldBe Valid(Def2) + } + + "use Def3 for tax years from 2025-26 onwards" in { + forTaxYearsFrom(TaxYear.fromMtd("2025-26")) { taxYear => + schemaFor(taxYear.asMtd) shouldBe Valid(Def3) + } + } + + "disallow tax years prior to 2017-18 and return RuleTaxYearNotSupportedError" in { + forTaxYearsBefore(TaxYear.fromMtd("2016-17")) { taxYear => + schemaFor(taxYear.asMtd) shouldBe Invalid(Seq(RuleTaxYearNotSupportedError)) + } } - } - "use Def2 for tax years from 2024-25" in { - forTaxYearsFrom(TaxYear.fromMtd("2024-25")) { taxYear => - schemaFor(taxYear.asMtd) shouldBe Def2 + "disallow tax years with an invalid range and return RuleTaxYearRangeInvalidError" in { + schemaFor("2020-99") shouldBe Invalid(Seq(RuleTaxYearRangeInvalidError)) } } - "the tax year is not valid" must { - "use a default of Def2 (where tax year validation will fail)" in { - schemaFor("NotATaxYear") shouldBe Def2 + "a badly formatted tax year is supplied" must { + "return a TaxYearFormatError" in { + schemaFor("NotATaxYear") shouldBe Invalid(Seq(TaxYearFormatError)) } } } diff --git a/test/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionServiceSpec.scala b/test/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionServiceSpec.scala index 96fe2ff7..22155b1a 100644 --- a/test/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionServiceSpec.scala +++ b/test/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionServiceSpec.scala @@ -25,9 +25,9 @@ import v4.retrieveAnnualSubmission.def1.model.Def1_RetrieveAnnualSubmissionFixtu import v4.retrieveAnnualSubmission.def1.model.request.Def1_RetrieveAnnualSubmissionRequestData import v4.retrieveAnnualSubmission.def1.model.response.{ Def1_RetrieveAnnualSubmissionResponse, - Retrieve_Adjustments, - Retrieve_Allowances, - Retrieve_NonFinancials + RetrieveAdjustments, + RetrieveAllowances, + RetrieveNonFinancials } import v4.retrieveAnnualSubmission.model.response.RetrieveAnnualSubmissionResponse @@ -41,9 +41,9 @@ class RetrieveAnnualSubmissionServiceSpec extends ServiceSpec with Def1_Retrieve override implicit val correlationId: String = "X-123" val response: RetrieveAnnualSubmissionResponse = Def1_RetrieveAnnualSubmissionResponse( - allowances = Some(Retrieve_Allowances(None, None, None, None, None, None, None, None, None, None, None, None, None)), - adjustments = Some(Retrieve_Adjustments(None, None, None, None, None, None, None, None, None)), - nonFinancials = Some(Retrieve_NonFinancials(businessDetailsChangedRecently = true, None)) + allowances = Some(RetrieveAllowances(None, None, None, None, None, None, None, None, None, None, None, None, None)), + adjustments = Some(RetrieveAdjustments(None, None, None, None, None, None, None, None, None)), + nonFinancials = Some(RetrieveNonFinancials(businessDetailsChangedRecently = true, None)) ) private val requestData = Def1_RetrieveAnnualSubmissionRequestData( diff --git a/test/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionValidatorFactorySpec.scala b/test/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionValidatorFactorySpec.scala index f4ba5178..44549be7 100644 --- a/test/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionValidatorFactorySpec.scala +++ b/test/v4/retrieveAnnualSubmission/RetrieveAnnualSubmissionValidatorFactorySpec.scala @@ -18,12 +18,12 @@ package v4.retrieveAnnualSubmission import config.MockSeBusinessConfig import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks -import shared.controllers.validators.Validator +import shared.controllers.validators.{AlwaysErrorsValidator, Validator} import shared.models.domain.{TaxYear, TaxYearPropertyCheckSupport} import shared.utils.UnitSpec -import v4.retrieveAnnualSubmission.RetrieveAnnualSubmissionSchema.{Def1, Def2} import v4.retrieveAnnualSubmission.def1.Def1_RetrieveAnnualSubmissionValidator import v4.retrieveAnnualSubmission.def2.Def2_RetrieveAnnualSubmissionValidator +import v4.retrieveAnnualSubmission.def3.Def3_RetrieveAnnualSubmissionValidator import v4.retrieveAnnualSubmission.model.request.RetrieveAnnualSubmissionRequestData class RetrieveAnnualSubmissionValidatorFactorySpec @@ -32,25 +32,34 @@ class RetrieveAnnualSubmissionValidatorFactorySpec with TaxYearPropertyCheckSupport with MockSeBusinessConfig { - private val nino = "AA123456A" - private val businessId = "XAIS12345678910" + private def validatorFor(taxYear: String): Validator[RetrieveAnnualSubmissionRequestData] = + new RetrieveAnnualSubmissionValidatorFactory() + .validator(nino = "ignoredNino", businessId = "ignored", taxYear = taxYear) - private val validatorFactory = new RetrieveAnnualSubmissionValidatorFactory - - "ValidatorFactory" when { + "RetrieveAnnualSubmissionValidatorFactory" when { + "given a request corresponding to a Def1 schema" should { + "return a Def1 validator" in forTaxYearsInRange(TaxYear.fromMtd("2017-18"), TaxYear.fromMtd("2023-24")) { taxYear: TaxYear => + validatorFor(taxYear.asMtd) shouldBe a[Def1_RetrieveAnnualSubmissionValidator] + } + } - "given a tax year" should { - "return the Validator corresponding to the schema for that tax year" in forTaxYearsFrom(TaxYear.starting(2020)) { taxYear: TaxYear => - val result: Validator[RetrieveAnnualSubmissionRequestData] = - validatorFactory.validator(nino, businessId, taxYear = taxYear.asMtd) + "given a request corresponding to a Def2 schema" should { + "return a Def2 validator" in { + validatorFor("2024-25") shouldBe a[Def2_RetrieveAnnualSubmissionValidator] + } + } - RetrieveAnnualSubmissionSchema.schemaFor(taxYear) match { - case Def1 => result shouldBe a[Def1_RetrieveAnnualSubmissionValidator] - case Def2 => result shouldBe a[Def2_RetrieveAnnualSubmissionValidator] - } + "given a request corresponding to a Def3 schema" should { + "return a Def3 validator" in { + validatorFor("2025-26") shouldBe a[Def3_RetrieveAnnualSubmissionValidator] } } + "given a request where no valid schema could be determined" should { + "return a validator returning the errors" in { + validatorFor("BAD_TAX_YEAR") shouldBe an[AlwaysErrorsValidator] + } + } } } diff --git a/test/v4/retrieveAnnualSubmission/def1/Def1_RetrieveAnnualSubmissionValidatorSpec.scala b/test/v4/retrieveAnnualSubmission/def1/Def1_RetrieveAnnualSubmissionValidatorSpec.scala index f02d3025..80c6127d 100644 --- a/test/v4/retrieveAnnualSubmission/def1/Def1_RetrieveAnnualSubmissionValidatorSpec.scala +++ b/test/v4/retrieveAnnualSubmission/def1/Def1_RetrieveAnnualSubmissionValidatorSpec.scala @@ -82,15 +82,6 @@ class Def1_RetrieveAnnualSubmissionValidatorSpec extends UnitSpec with MockSeBus } } - "return RuleTaxYearNotSupportedError" when { - "an invalid tax year is supplied" in { - val result: Either[ErrorWrapper, RetrieveAnnualSubmissionRequestData] = - validator(validNino, validBusinessId, "2016-17").validateAndWrapResult() - - result shouldBe Left(ErrorWrapper(correlationId, RuleTaxYearNotSupportedError)) - } - } - "return multiple errors" when { "request supplied has multiple errors" in { val result: Either[ErrorWrapper, RetrieveAnnualSubmissionRequestData] = validator("A12344A", "Baked Beans", "20178").validateAndWrapResult() diff --git a/test/v4/retrieveAnnualSubmission/def1/model/Def1_RetrieveAnnualSubmissionFixture.scala b/test/v4/retrieveAnnualSubmission/def1/model/Def1_RetrieveAnnualSubmissionFixture.scala index 375c1da2..0862f813 100644 --- a/test/v4/retrieveAnnualSubmission/def1/model/Def1_RetrieveAnnualSubmissionFixture.scala +++ b/test/v4/retrieveAnnualSubmission/def1/model/Def1_RetrieveAnnualSubmissionFixture.scala @@ -22,23 +22,23 @@ import v4.retrieveAnnualSubmission.def1.model.response._ trait Def1_RetrieveAnnualSubmissionFixture { - val structuredBuildingAllowance: Retrieve_StructuredBuildingAllowance = - Retrieve_StructuredBuildingAllowance( + val structuredBuildingAllowance: RetrieveStructuredBuildingAllowance = + RetrieveStructuredBuildingAllowance( 3000.30, Some( - Retrieve_FirstYear( + RetrieveFirstYear( "2020-01-01", 3000.40 )), - Retrieve_Building( + RetrieveBuilding( Some("house name"), Some("house number"), "GF49JH" ) ) - val buildingMtdModel: Retrieve_Building = - Retrieve_Building( + val buildingMtdModel: RetrieveBuilding = + RetrieveBuilding( Some("house name"), Some("house number"), "GF4 9JH" @@ -90,8 +90,8 @@ trait Def1_RetrieveAnnualSubmissionFixture { |} |""".stripMargin) - val adjustments: Retrieve_Adjustments = - Retrieve_Adjustments( + val adjustments: RetrieveAdjustments = + RetrieveAdjustments( includedNonTaxableProfits = Some(1.12), basisAdjustment = Some(2.12), overlapReliefUsed = Some(3.12), @@ -129,7 +129,7 @@ trait Def1_RetrieveAnnualSubmissionFixture { |} |""".stripMargin) - val allowances: Retrieve_Allowances = Retrieve_Allowances( + val allowances: RetrieveAllowances = RetrieveAllowances( annualInvestmentAllowance = Some(1.12), capitalAllowanceMainPool = Some(2.12), capitalAllowanceSpecialRatePool = Some(3.12), @@ -177,8 +177,8 @@ trait Def1_RetrieveAnnualSubmissionFixture { |} |""".stripMargin) - val nonFinancials: Retrieve_NonFinancials = - Retrieve_NonFinancials( + val nonFinancials: RetrieveNonFinancials = + RetrieveNonFinancials( businessDetailsChangedRecently = true, class4NicsExemptionReason = Some(MtdNicExemption.`non-resident`) ) diff --git a/test/v4/retrieveAnnualSubmission/def1/model/response/Def1_RetrieveAnnualSubmissionResponseSpec.scala b/test/v4/retrieveAnnualSubmission/def1/model/response/Def1_RetrieveAnnualSubmissionResponseSpec.scala index d11bbce6..692cb6de 100644 --- a/test/v4/retrieveAnnualSubmission/def1/model/response/Def1_RetrieveAnnualSubmissionResponseSpec.scala +++ b/test/v4/retrieveAnnualSubmission/def1/model/response/Def1_RetrieveAnnualSubmissionResponseSpec.scala @@ -24,9 +24,9 @@ import v4.retrieveAnnualSubmission.def1.model.Def1_RetrieveAnnualSubmissionFixtu class Def1_RetrieveAnnualSubmissionResponseSpec extends UnitSpec with MockSharedAppConfig with Def1_RetrieveAnnualSubmissionFixture { private val retrieveAnnualSubmissionResponse = Def1_RetrieveAnnualSubmissionResponse( - allowances = Some(Retrieve_Allowances(None, None, None, None, None, None, None, None, None, None, None, None, None)), - adjustments = Some(Retrieve_Adjustments(None, None, None, None, None, None, None, None, None)), - nonFinancials = Some(Retrieve_NonFinancials(businessDetailsChangedRecently = true, None)) + allowances = Some(RetrieveAllowances(None, None, None, None, None, None, None, None, None, None, None, None, None)), + adjustments = Some(RetrieveAdjustments(None, None, None, None, None, None, None, None, None)), + nonFinancials = Some(RetrieveNonFinancials(businessDetailsChangedRecently = true, None)) ) "reads" should { diff --git a/test/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_AdjustmentsSpec.scala b/test/v4/retrieveAnnualSubmission/def1/model/response/RetrieveAdjustmentsSpec.scala similarity index 94% rename from test/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_AdjustmentsSpec.scala rename to test/v4/retrieveAnnualSubmission/def1/model/response/RetrieveAdjustmentsSpec.scala index e25a5a59..79cc71fd 100644 --- a/test/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_AdjustmentsSpec.scala +++ b/test/v4/retrieveAnnualSubmission/def1/model/response/RetrieveAdjustmentsSpec.scala @@ -19,10 +19,10 @@ package v4.retrieveAnnualSubmission.def1.model.response import play.api.libs.json.Json import shared.utils.UnitSpec -class Retrieve_AdjustmentsSpec extends UnitSpec { +class RetrieveAdjustmentsSpec extends UnitSpec { - val adjustments: Retrieve_Adjustments = - Retrieve_Adjustments( + val adjustments: RetrieveAdjustments = + RetrieveAdjustments( includedNonTaxableProfits = Some(1.12), basisAdjustment = Some(2.12), overlapReliefUsed = Some(3.12), @@ -50,7 +50,7 @@ class Retrieve_AdjustmentsSpec extends UnitSpec { | "goodsAndServicesOwnUse": 9.12 |} |""".stripMargin) - .as[Retrieve_Adjustments] + .as[RetrieveAdjustments] result shouldBe adjustments } diff --git a/test/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_AllowancesSpec.scala b/test/v4/retrieveAnnualSubmission/def1/model/response/RetrieveAllowancesSpec.scala similarity index 95% rename from test/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_AllowancesSpec.scala rename to test/v4/retrieveAnnualSubmission/def1/model/response/RetrieveAllowancesSpec.scala index 8e5d226b..33352b51 100644 --- a/test/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_AllowancesSpec.scala +++ b/test/v4/retrieveAnnualSubmission/def1/model/response/RetrieveAllowancesSpec.scala @@ -19,9 +19,9 @@ package v4.retrieveAnnualSubmission.def1.model.response import play.api.libs.json.Json import shared.utils.UnitSpec -class Retrieve_AllowancesSpec extends UnitSpec { +class RetrieveAllowancesSpec extends UnitSpec { - val model: Retrieve_Allowances = Retrieve_Allowances( + val model: RetrieveAllowances = RetrieveAllowances( annualInvestmentAllowance = Some(1.12), capitalAllowanceMainPool = Some(2.12), capitalAllowanceSpecialRatePool = Some(3.12), @@ -57,7 +57,7 @@ class Retrieve_AllowancesSpec extends UnitSpec { | "enhancedStructuredBuildingAllowance": [] |} |""".stripMargin) - .as[Retrieve_Allowances] shouldBe model + .as[RetrieveAllowances] shouldBe model } } } diff --git a/test/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_BuildingSpec.scala b/test/v4/retrieveAnnualSubmission/def1/model/response/RetrieveBuildingSpec.scala similarity index 85% rename from test/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_BuildingSpec.scala rename to test/v4/retrieveAnnualSubmission/def1/model/response/RetrieveBuildingSpec.scala index d1dfff14..5ddf94da 100644 --- a/test/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_BuildingSpec.scala +++ b/test/v4/retrieveAnnualSubmission/def1/model/response/RetrieveBuildingSpec.scala @@ -20,12 +20,12 @@ import play.api.libs.json.Json import shared.utils.UnitSpec import v4.retrieveAnnualSubmission.def1.model.Def1_RetrieveAnnualSubmissionFixture -class Retrieve_BuildingSpec extends UnitSpec with Def1_RetrieveAnnualSubmissionFixture { +class RetrieveBuildingSpec extends UnitSpec with Def1_RetrieveAnnualSubmissionFixture { "reads" when { "passed a valid JSON" should { "return the model" in { - buildingAllowanceDownstreamJson.as[Retrieve_Building] shouldBe buildingMtdModel + buildingAllowanceDownstreamJson.as[RetrieveBuilding] shouldBe buildingMtdModel } } } diff --git a/test/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_FirstYearSpec.scala b/test/v4/retrieveAnnualSubmission/def1/model/response/RetrieveFirstYearSpec.scala similarity index 88% rename from test/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_FirstYearSpec.scala rename to test/v4/retrieveAnnualSubmission/def1/model/response/RetrieveFirstYearSpec.scala index a4333ab8..926bef82 100644 --- a/test/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_FirstYearSpec.scala +++ b/test/v4/retrieveAnnualSubmission/def1/model/response/RetrieveFirstYearSpec.scala @@ -19,10 +19,10 @@ package v4.retrieveAnnualSubmission.def1.model.response import play.api.libs.json.{JsValue, Json} import shared.utils.UnitSpec -class Retrieve_FirstYearSpec extends UnitSpec { +class RetrieveFirstYearSpec extends UnitSpec { - val model: Retrieve_FirstYear = - Retrieve_FirstYear( + val model: RetrieveFirstYear = + RetrieveFirstYear( "2020-01-01", 3000.40 ) @@ -37,7 +37,7 @@ class Retrieve_FirstYearSpec extends UnitSpec { "reads" when { "passed a valid JSON" should { "return the model" in { - json.as[Retrieve_FirstYear] shouldBe model + json.as[RetrieveFirstYear] shouldBe model } } } diff --git a/test/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_NonFinancialsSpec.scala b/test/v4/retrieveAnnualSubmission/def1/model/response/RetrieveNonFinancialsSpec.scala similarity index 86% rename from test/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_NonFinancialsSpec.scala rename to test/v4/retrieveAnnualSubmission/def1/model/response/RetrieveNonFinancialsSpec.scala index 59b02160..b6e17c1b 100644 --- a/test/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_NonFinancialsSpec.scala +++ b/test/v4/retrieveAnnualSubmission/def1/model/response/RetrieveNonFinancialsSpec.scala @@ -21,7 +21,7 @@ import play.api.libs.json.{JsValue, Json} import shared.utils.UnitSpec import v4.retrieveAnnualSubmission.def1.model.Def1_RetrieveAnnualSubmissionFixture -class Retrieve_NonFinancialsSpec extends UnitSpec with Def1_RetrieveAnnualSubmissionFixture { +class RetrieveNonFinancialsSpec extends UnitSpec with Def1_RetrieveAnnualSubmissionFixture { "reads" should { "passed a valid JSON" should { @@ -33,7 +33,7 @@ class Retrieve_NonFinancialsSpec extends UnitSpec with Def1_RetrieveAnnualSubmis |} |""".stripMargin) - requestJson.as[Retrieve_NonFinancials] shouldBe Retrieve_NonFinancials( + requestJson.as[RetrieveNonFinancials] shouldBe RetrieveNonFinancials( businessDetailsChangedRecently = true, class4NicsExemptionReason = Some(MtdNicExemption.`non-resident`) ) @@ -55,7 +55,7 @@ class Retrieve_NonFinancialsSpec extends UnitSpec with Def1_RetrieveAnnualSubmis "there is no exemption reason" must { "set exemptFromPayingClass4Nics true" in { - Json.toJson(Retrieve_NonFinancials(businessDetailsChangedRecently = true, class4NicsExemptionReason = None)) shouldBe + Json.toJson(RetrieveNonFinancials(businessDetailsChangedRecently = true, class4NicsExemptionReason = None)) shouldBe Json.parse(s""" |{ | "businessDetailsChangedRecently": true diff --git a/test/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_StructuredBuildingAllowanceSpec.scala b/test/v4/retrieveAnnualSubmission/def1/model/response/RetrieveStructuredBuildingAllowanceSpec.scala similarity index 89% rename from test/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_StructuredBuildingAllowanceSpec.scala rename to test/v4/retrieveAnnualSubmission/def1/model/response/RetrieveStructuredBuildingAllowanceSpec.scala index a3e6bdf3..58c44acd 100644 --- a/test/v4/retrieveAnnualSubmission/def1/model/response/Retrieve_StructuredBuildingAllowanceSpec.scala +++ b/test/v4/retrieveAnnualSubmission/def1/model/response/RetrieveStructuredBuildingAllowanceSpec.scala @@ -20,12 +20,12 @@ import play.api.libs.json.Json import shared.utils.UnitSpec import v4.retrieveAnnualSubmission.def1.model.Def1_RetrieveAnnualSubmissionFixture -class Retrieve_StructuredBuildingAllowanceSpec extends UnitSpec with Def1_RetrieveAnnualSubmissionFixture { +class RetrieveStructuredBuildingAllowanceSpec extends UnitSpec with Def1_RetrieveAnnualSubmissionFixture { "reads" when { "passed a valid JSON" should { "return the model" in { - val result = structuredBuildingAllowanceDownstreamJson.as[Retrieve_StructuredBuildingAllowance] + val result = structuredBuildingAllowanceDownstreamJson.as[RetrieveStructuredBuildingAllowance] result shouldBe structuredBuildingAllowance } } diff --git a/test/v4/retrieveAnnualSubmission/def2/Def2_RetrieveAnnualSubmissionValidatorSpec.scala b/test/v4/retrieveAnnualSubmission/def2/Def2_RetrieveAnnualSubmissionValidatorSpec.scala index 5d6802c2..f0a56bdf 100644 --- a/test/v4/retrieveAnnualSubmission/def2/Def2_RetrieveAnnualSubmissionValidatorSpec.scala +++ b/test/v4/retrieveAnnualSubmission/def2/Def2_RetrieveAnnualSubmissionValidatorSpec.scala @@ -81,15 +81,6 @@ class Def2_RetrieveAnnualSubmissionValidatorSpec extends UnitSpec { } } - "return RuleTaxYearNotSupportedError" when { - "an invalid tax year is supplied" in { - val result: Either[ErrorWrapper, RetrieveAnnualSubmissionRequestData] = - validator(validNino, validBusinessId, "2016-17").validateAndWrapResult() - - result shouldBe Left(ErrorWrapper(correlationId, RuleTaxYearNotSupportedError)) - } - } - "return multiple errors" when { "request supplied has multiple errors" in { val result: Either[ErrorWrapper, RetrieveAnnualSubmissionRequestData] = validator("A12344A", "Baked Beans", "20178").validateAndWrapResult() diff --git a/test/v4/retrieveAnnualSubmission/def2/model/Def2_RetrieveAnnualSubmissionFixture.scala b/test/v4/retrieveAnnualSubmission/def2/model/Def2_RetrieveAnnualSubmissionFixture.scala index 00d6a415..5221751b 100644 --- a/test/v4/retrieveAnnualSubmission/def2/model/Def2_RetrieveAnnualSubmissionFixture.scala +++ b/test/v4/retrieveAnnualSubmission/def2/model/Def2_RetrieveAnnualSubmissionFixture.scala @@ -22,23 +22,23 @@ import v4.retrieveAnnualSubmission.def2.model.response._ trait Def2_RetrieveAnnualSubmissionFixture { - val structuredBuildingAllowance: Retrieve_StructuredBuildingAllowance = - Retrieve_StructuredBuildingAllowance( + val structuredBuildingAllowance: RetrieveStructuredBuildingAllowance = + RetrieveStructuredBuildingAllowance( 3000.30, Some( - Retrieve_FirstYear( + RetrieveFirstYear( "2020-01-01", 3000.40 )), - Retrieve_Building( + RetrieveBuilding( Some("house name"), Some("house number"), "GF49JH" ) ) - val buildingMtdModel: Retrieve_Building = - Retrieve_Building( + val buildingMtdModel: RetrieveBuilding = + RetrieveBuilding( Some("house name"), Some("house number"), "GF4 9JH" @@ -90,8 +90,8 @@ trait Def2_RetrieveAnnualSubmissionFixture { |} |""".stripMargin) - val adjustments: Retrieve_Adjustments = - Retrieve_Adjustments( + val adjustments: RetrieveAdjustments = + RetrieveAdjustments( includedNonTaxableProfits = Some(1.12), basisAdjustment = Some(2.12), overlapReliefUsed = Some(3.12), @@ -135,7 +135,7 @@ trait Def2_RetrieveAnnualSubmissionFixture { |} |""".stripMargin) - val allowances: Retrieve_Allowances = Retrieve_Allowances( + val allowances: RetrieveAllowances = RetrieveAllowances( annualInvestmentAllowance = Some(1.12), capitalAllowanceMainPool = Some(2.12), capitalAllowanceSpecialRatePool = Some(3.12), @@ -183,8 +183,8 @@ trait Def2_RetrieveAnnualSubmissionFixture { |} |""".stripMargin) - val nonFinancials: Retrieve_NonFinancials = - Retrieve_NonFinancials( + val nonFinancials: RetrieveNonFinancials = + RetrieveNonFinancials( businessDetailsChangedRecently = true, class4NicsExemptionReason = Some(MtdNicExemption.`non-resident`) ) diff --git a/test/v4/retrieveAnnualSubmission/def2/model/response/Def2_RetrieveAnnualSubmissionResponseSpec.scala b/test/v4/retrieveAnnualSubmission/def2/model/response/Def2_RetrieveAnnualSubmissionResponseSpec.scala index 5dbf17b9..5616da3f 100644 --- a/test/v4/retrieveAnnualSubmission/def2/model/response/Def2_RetrieveAnnualSubmissionResponseSpec.scala +++ b/test/v4/retrieveAnnualSubmission/def2/model/response/Def2_RetrieveAnnualSubmissionResponseSpec.scala @@ -32,9 +32,9 @@ class Def2_RetrieveAnnualSubmissionResponseSpec private implicit val featureSwitches: SeBusinessFeatureSwitches = SeBusinessFeatureSwitches(Configuration.empty) private val retrieveAnnualSubmissionResponse = Def2_RetrieveAnnualSubmissionResponse( - allowances = Some(Retrieve_Allowances(None, None, None, None, None, None, None, None, None, None, None, None, None)), - adjustments = Some(Retrieve_Adjustments(None, None, None, None, None, None, None, None, None, None, None)), - nonFinancials = Some(Retrieve_NonFinancials(businessDetailsChangedRecently = true, None)) + allowances = Some(RetrieveAllowances(None, None, None, None, None, None, None, None, None, None, None, None, None)), + adjustments = Some(RetrieveAdjustments(None, None, None, None, None, None, None, None, None, None, None)), + nonFinancials = Some(RetrieveNonFinancials(businessDetailsChangedRecently = true, None)) ) "reads" should { diff --git a/test/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_AdjustmentsSpec.scala b/test/v4/retrieveAnnualSubmission/def2/model/response/RetrieveAdjustmentsSpec.scala similarity index 95% rename from test/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_AdjustmentsSpec.scala rename to test/v4/retrieveAnnualSubmission/def2/model/response/RetrieveAdjustmentsSpec.scala index f322a7c8..8a8c33f4 100644 --- a/test/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_AdjustmentsSpec.scala +++ b/test/v4/retrieveAnnualSubmission/def2/model/response/RetrieveAdjustmentsSpec.scala @@ -21,10 +21,10 @@ import play.api.Configuration import play.api.libs.json.Json import shared.utils.UnitSpec -class Retrieve_AdjustmentsSpec extends UnitSpec { +class RetrieveAdjustmentsSpec extends UnitSpec { - val adjustments: Retrieve_Adjustments = - Retrieve_Adjustments( + val adjustments: RetrieveAdjustments = + RetrieveAdjustments( includedNonTaxableProfits = Some(1.12), basisAdjustment = Some(2.12), overlapReliefUsed = Some(3.12), @@ -56,7 +56,7 @@ class Retrieve_AdjustmentsSpec extends UnitSpec { | "transitionProfitAccelerationAmount": 11.13 |} |""".stripMargin) - .as[Retrieve_Adjustments] shouldBe adjustments + .as[RetrieveAdjustments] shouldBe adjustments } } } diff --git a/test/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_AllowancesSpec.scala b/test/v4/retrieveAnnualSubmission/def2/model/response/RetrieveAllowancesSpec.scala similarity index 95% rename from test/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_AllowancesSpec.scala rename to test/v4/retrieveAnnualSubmission/def2/model/response/RetrieveAllowancesSpec.scala index 41252c33..c74e0a92 100644 --- a/test/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_AllowancesSpec.scala +++ b/test/v4/retrieveAnnualSubmission/def2/model/response/RetrieveAllowancesSpec.scala @@ -19,9 +19,9 @@ package v4.retrieveAnnualSubmission.def2.model.response import play.api.libs.json.Json import shared.utils.UnitSpec -class Retrieve_AllowancesSpec extends UnitSpec { +class RetrieveAllowancesSpec extends UnitSpec { - val model: Retrieve_Allowances = Retrieve_Allowances( + val model: RetrieveAllowances = RetrieveAllowances( annualInvestmentAllowance = Some(1.12), capitalAllowanceMainPool = Some(2.12), capitalAllowanceSpecialRatePool = Some(3.12), @@ -57,7 +57,7 @@ class Retrieve_AllowancesSpec extends UnitSpec { | "enhancedStructuredBuildingAllowance": [] |} |""".stripMargin) - .as[Retrieve_Allowances] shouldBe model + .as[RetrieveAllowances] shouldBe model } } } diff --git a/test/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_BuildingSpec.scala b/test/v4/retrieveAnnualSubmission/def2/model/response/RetrieveBuildingSpec.scala similarity index 85% rename from test/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_BuildingSpec.scala rename to test/v4/retrieveAnnualSubmission/def2/model/response/RetrieveBuildingSpec.scala index de57e858..50d10bf6 100644 --- a/test/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_BuildingSpec.scala +++ b/test/v4/retrieveAnnualSubmission/def2/model/response/RetrieveBuildingSpec.scala @@ -20,12 +20,12 @@ import play.api.libs.json.Json import shared.utils.UnitSpec import v4.retrieveAnnualSubmission.def2.model.Def2_RetrieveAnnualSubmissionFixture -class Retrieve_BuildingSpec extends UnitSpec with Def2_RetrieveAnnualSubmissionFixture { +class RetrieveBuildingSpec extends UnitSpec with Def2_RetrieveAnnualSubmissionFixture { "reads" when { "passed a valid JSON" should { "return the model" in { - buildingAllowanceDownstreamJson.as[Retrieve_Building] shouldBe buildingMtdModel + buildingAllowanceDownstreamJson.as[RetrieveBuilding] shouldBe buildingMtdModel } } } diff --git a/test/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_FirstYearSpec.scala b/test/v4/retrieveAnnualSubmission/def2/model/response/RetrieveFirstYearSpec.scala similarity index 88% rename from test/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_FirstYearSpec.scala rename to test/v4/retrieveAnnualSubmission/def2/model/response/RetrieveFirstYearSpec.scala index 3a9de71f..2771e8c8 100644 --- a/test/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_FirstYearSpec.scala +++ b/test/v4/retrieveAnnualSubmission/def2/model/response/RetrieveFirstYearSpec.scala @@ -19,10 +19,10 @@ package v4.retrieveAnnualSubmission.def2.model.response import play.api.libs.json.{JsValue, Json} import shared.utils.UnitSpec -class Retrieve_FirstYearSpec extends UnitSpec { +class RetrieveFirstYearSpec extends UnitSpec { - val model: Retrieve_FirstYear = - Retrieve_FirstYear( + val model: RetrieveFirstYear = + RetrieveFirstYear( "2020-01-01", 3000.40 ) @@ -37,7 +37,7 @@ class Retrieve_FirstYearSpec extends UnitSpec { "reads" when { "passed a valid JSON" should { "return the model" in { - json.as[Retrieve_FirstYear] shouldBe model + json.as[RetrieveFirstYear] shouldBe model } } } diff --git a/test/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_NonFinancialsSpec.scala b/test/v4/retrieveAnnualSubmission/def2/model/response/RetrieveNonFinancialsSpec.scala similarity index 86% rename from test/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_NonFinancialsSpec.scala rename to test/v4/retrieveAnnualSubmission/def2/model/response/RetrieveNonFinancialsSpec.scala index c60e3abc..d56e632f 100644 --- a/test/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_NonFinancialsSpec.scala +++ b/test/v4/retrieveAnnualSubmission/def2/model/response/RetrieveNonFinancialsSpec.scala @@ -21,7 +21,7 @@ import play.api.libs.json.{JsValue, Json} import shared.utils.UnitSpec import v4.retrieveAnnualSubmission.def2.model.Def2_RetrieveAnnualSubmissionFixture -class Retrieve_NonFinancialsSpec extends UnitSpec with Def2_RetrieveAnnualSubmissionFixture { +class RetrieveNonFinancialsSpec extends UnitSpec with Def2_RetrieveAnnualSubmissionFixture { "reads" should { "passed a valid JSON" should { @@ -33,7 +33,7 @@ class Retrieve_NonFinancialsSpec extends UnitSpec with Def2_RetrieveAnnualSubmis |} |""".stripMargin) - requestJson.as[Retrieve_NonFinancials] shouldBe Retrieve_NonFinancials( + requestJson.as[RetrieveNonFinancials] shouldBe RetrieveNonFinancials( businessDetailsChangedRecently = true, class4NicsExemptionReason = Some(MtdNicExemption.`non-resident`) ) @@ -55,7 +55,7 @@ class Retrieve_NonFinancialsSpec extends UnitSpec with Def2_RetrieveAnnualSubmis "there is no exemption reason" must { "set exemptFromPayingClass4Nics true" in { - Json.toJson(Retrieve_NonFinancials(businessDetailsChangedRecently = true, class4NicsExemptionReason = None)) shouldBe + Json.toJson(RetrieveNonFinancials(businessDetailsChangedRecently = true, class4NicsExemptionReason = None)) shouldBe Json.parse(s""" |{ | "businessDetailsChangedRecently": true diff --git a/test/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_StructuredBuildingAllowanceSpec.scala b/test/v4/retrieveAnnualSubmission/def2/model/response/RetrieveStructuredBuildingAllowanceSpec.scala similarity index 89% rename from test/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_StructuredBuildingAllowanceSpec.scala rename to test/v4/retrieveAnnualSubmission/def2/model/response/RetrieveStructuredBuildingAllowanceSpec.scala index d239c4ea..9f163d4d 100644 --- a/test/v4/retrieveAnnualSubmission/def2/model/response/Retrieve_StructuredBuildingAllowanceSpec.scala +++ b/test/v4/retrieveAnnualSubmission/def2/model/response/RetrieveStructuredBuildingAllowanceSpec.scala @@ -20,12 +20,12 @@ import play.api.libs.json.Json import shared.utils.UnitSpec import v4.retrieveAnnualSubmission.def2.model.Def2_RetrieveAnnualSubmissionFixture -class Retrieve_StructuredBuildingAllowanceSpec extends UnitSpec with Def2_RetrieveAnnualSubmissionFixture { +class RetrieveStructuredBuildingAllowanceSpec extends UnitSpec with Def2_RetrieveAnnualSubmissionFixture { "reads" when { "passed a valid JSON" should { "return the model" in { - val result = structuredBuildingAllowanceDownstreamJson.as[Retrieve_StructuredBuildingAllowance] + val result = structuredBuildingAllowanceDownstreamJson.as[RetrieveStructuredBuildingAllowance] result shouldBe structuredBuildingAllowance } } diff --git a/test/v4/retrieveAnnualSubmission/def3/Def3_RetrieveAnnualSubmissionValidatorSpec.scala b/test/v4/retrieveAnnualSubmission/def3/Def3_RetrieveAnnualSubmissionValidatorSpec.scala new file mode 100644 index 00000000..94af6f4e --- /dev/null +++ b/test/v4/retrieveAnnualSubmission/def3/Def3_RetrieveAnnualSubmissionValidatorSpec.scala @@ -0,0 +1,93 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def3 + +import shared.models.domain.{BusinessId, Nino, TaxYear} +import shared.models.errors._ +import shared.utils.UnitSpec +import v4.retrieveAnnualSubmission.def3.model.request.Def3_RetrieveAnnualSubmissionRequestData +import v4.retrieveAnnualSubmission.model.request.RetrieveAnnualSubmissionRequestData + +class Def3_RetrieveAnnualSubmissionValidatorSpec extends UnitSpec { + + private implicit val correlationId: String = "1234" + + private val validNino = "AA123456A" + private val validBusinessId = "XAIS12345678910" + private val validTaxYear = "2017-18" + + private val parsedNino = Nino(validNino) + private val parsedBusinessId = BusinessId(validBusinessId) + private val parsedTaxYear = TaxYear.fromMtd(validTaxYear) + + private def validator(nino: String, businessId: String, taxYear: String) = + new Def3_RetrieveAnnualSubmissionValidator(nino, businessId, taxYear) + + "validator" should { + "return the parsed domain object" when { + "a valid request is made" in { + val result: Either[ErrorWrapper, RetrieveAnnualSubmissionRequestData] = + validator(validNino, validBusinessId, validTaxYear).validateAndWrapResult() + + result shouldBe Right(Def3_RetrieveAnnualSubmissionRequestData(parsedNino, parsedBusinessId, parsedTaxYear)) + } + } + + "return NinoFormatError error" when { + "an invalid nino is supplied" in { + val result: Either[ErrorWrapper, RetrieveAnnualSubmissionRequestData] = + validator("A12344A", validBusinessId, validTaxYear).validateAndWrapResult() + + result shouldBe Left(ErrorWrapper(correlationId, NinoFormatError)) + } + } + + "return BusinessIdFormatError error" when { + "an invalid nino is supplied" in { + val result: Either[ErrorWrapper, RetrieveAnnualSubmissionRequestData] = validator(validNino, "Walruses", validTaxYear).validateAndWrapResult() + + result shouldBe Left(ErrorWrapper(correlationId, BusinessIdFormatError)) + } + } + + "return TaxYearFormatError error" when { + "an invalid tax year is supplied" in { + val result: Either[ErrorWrapper, RetrieveAnnualSubmissionRequestData] = validator(validNino, validBusinessId, "20178").validateAndWrapResult() + + result shouldBe Left(ErrorWrapper(correlationId, TaxYearFormatError)) + } + } + + "return RuleTaxYearRangeInvalidError" when { + "an invalid tax year is supplied" in { + val result: Either[ErrorWrapper, RetrieveAnnualSubmissionRequestData] = + validator(validNino, validBusinessId, "2017-19").validateAndWrapResult() + + result shouldBe Left(ErrorWrapper(correlationId, RuleTaxYearRangeInvalidError)) + } + } + + "return multiple errors" when { + "request supplied has multiple errors" in { + val result: Either[ErrorWrapper, RetrieveAnnualSubmissionRequestData] = validator("A12344A", "Baked Beans", "20178").validateAndWrapResult() + + result shouldBe Left(ErrorWrapper(correlationId, BadRequestError, Some(List(BusinessIdFormatError, NinoFormatError, TaxYearFormatError)))) + } + } + } + +} diff --git a/test/v4/retrieveAnnualSubmission/def3/model/Def3_RetrieveAnnualSubmissionFixture.scala b/test/v4/retrieveAnnualSubmission/def3/model/Def3_RetrieveAnnualSubmissionFixture.scala new file mode 100644 index 00000000..479182c6 --- /dev/null +++ b/test/v4/retrieveAnnualSubmission/def3/model/Def3_RetrieveAnnualSubmissionFixture.scala @@ -0,0 +1,226 @@ +/* + * Copyright 2024 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def3.model + +import api.models.domain.ex.MtdNicExemption +import play.api.libs.json.{JsValue, Json} +import v4.retrieveAnnualSubmission.def3.model.response._ + +trait Def3_RetrieveAnnualSubmissionFixture { + + val structuredBuildingAllowance: RetrieveStructuredBuildingAllowance = + RetrieveStructuredBuildingAllowance( + 3000.30, + Some( + RetrieveFirstYear( + "2020-01-01", + 3000.40 + ) + ), + RetrieveBuilding( + Some("house name"), + Some("house number"), + "GF49JH" + ) + ) + + val buildingMtdModel: RetrieveBuilding = + RetrieveBuilding( + Some("house name"), + Some("house number"), + "GF4 9JH" + ) + + val buildingAllowanceMtdJson: JsValue = Json.parse(""" + |{ + | "name": "house name", + | "number": "house number", + | "postcode": "GF4 9JH" + |} + |""".stripMargin) + + val buildingAllowanceDownstreamJson: JsValue = Json.parse(""" + |{ + | "name": "house name", + | "number": "house number", + | "postCode": "GF4 9JH" + |} + |""".stripMargin) + + val structuredBuildingAllowanceMtdJson: JsValue = Json.parse(""" + |{ + | "amount": 3000.30, + | "firstYear": { + | "qualifyingDate": "2020-01-01", + | "qualifyingAmountExpenditure": 3000.40 + | }, + | "building": { + | "name": "house name", + | "number": "house number", + | "postcode": "GF49JH" + | } + |} + |""".stripMargin) + + val structuredBuildingAllowanceDownstreamJson: JsValue = Json.parse(""" + |{ + | "amount": 3000.30, + | "firstYear": { + | "qualifyingDate": "2020-01-01", + | "qualifyingAmountExpenditure": 3000.40 + | }, + | "building": { + | "name": "house name", + | "number": "house number", + | "postCode": "GF49JH" + | } + |} + |""".stripMargin) + + val adjustments: RetrieveAdjustments = + RetrieveAdjustments( + includedNonTaxableProfits = Some(1.12), + basisAdjustment = Some(2.12), + overlapReliefUsed = Some(3.12), + accountingAdjustment = Some(4.12), + averagingAdjustment = Some(5.12), + outstandingBusinessIncome = Some(6.12), + balancingChargeBpra = Some(7.12), + balancingChargeOther = Some(8.12), + goodsAndServicesOwnUse = Some(9.12), + transitionProfitAmount = Some(9.12), + transitionProfitAccelerationAmount = Some(9.12) + ) + + val adjustmentsMtdJson: JsValue = Json.parse(s"""{ + | "includedNonTaxableProfits": 1.12, + | "basisAdjustment": 2.12, + | "overlapReliefUsed": 3.12, + | "accountingAdjustment": 4.12, + | "averagingAdjustment": 5.12, + | "outstandingBusinessIncome": 6.12, + | "balancingChargeBpra": 7.12, + | "balancingChargeOther": 8.12, + | "goodsAndServicesOwnUse": 9.12, + | "transitionProfitAmount": 9.12, + | "transitionProfitAccelerationAmount": 9.12 + |} + |""".stripMargin) + + val adjustmentsDownstreamJson: JsValue = Json.parse(s"""{ + | "includedNonTaxableProfits": 1.12, + | "basisAdjustment": 2.12, + | "overlapReliefUsed": 3.12, + | "accountingAdjustment": 4.12, + | "averagingAdjustment": 5.12, + | "outstandingBusinessIncome": 6.12, + | "balancingChargeBpra": 7.12, + | "balancingChargeOther": 8.12, + | "goodsAndServicesOwnUse": 9.12, + | "transitionProfitAmount": 9.12, + | "transitionProfitAccelerationAmount": 9.12 + |} + |""".stripMargin) + + val allowances: RetrieveAllowances = RetrieveAllowances( + annualInvestmentAllowance = Some(1.12), + capitalAllowanceMainPool = Some(2.12), + capitalAllowanceSpecialRatePool = Some(3.12), + zeroEmissionsGoodsVehicleAllowance = Some(4.12), + businessPremisesRenovationAllowance = Some(5.12), + enhancedCapitalAllowance = Some(6.12), + allowanceOnSales = Some(7.12), + capitalAllowanceSingleAssetPool = Some(8.12), + tradingIncomeAllowance = None, + zeroEmissionsCarAllowance = Some(11.12), + structuredBuildingAllowance = Some(List(structuredBuildingAllowance)), + enhancedStructuredBuildingAllowance = Some(List(structuredBuildingAllowance)) + ) + + val allowancesMtdJson: JsValue = Json.parse(s"""{ + | "annualInvestmentAllowance": 1.12, + | "capitalAllowanceMainPool": 2.12, + | "capitalAllowanceSpecialRatePool": 3.12, + | "zeroEmissionsGoodsVehicleAllowance": 4.12, + | "businessPremisesRenovationAllowance": 5.12, + | "enhancedCapitalAllowance": 6.12, + | "allowanceOnSales": 7.12, + | "capitalAllowanceSingleAssetPool": 8.12, + | "zeroEmissionsCarAllowance": 11.12, + | "structuredBuildingAllowance": [ $structuredBuildingAllowanceMtdJson ], + | "enhancedStructuredBuildingAllowance": [ $structuredBuildingAllowanceMtdJson ] + |} + |""".stripMargin) + + val allowancesDownstreamJson: JsValue = Json.parse(s"""{ + | "annualInvestmentAllowance": 1.12, + | "capitalAllowanceMainPool": 2.12, + | "capitalAllowanceSpecialRatePool": 3.12, + | "zeroEmissionGoodsVehicleAllowance": 4.12, + | "businessPremisesRenovationAllowance": 5.12, + | "enhanceCapitalAllowance": 6.12, + | "allowanceOnSales": 7.12, + | "capitalAllowanceSingleAssetPool": 8.12, + | "zeroEmissionsCarAllowance": 11.12, + | "structuredBuildingAllowance": [ $structuredBuildingAllowanceDownstreamJson ], + | "enhancedStructuredBuildingAllowance": [ $structuredBuildingAllowanceDownstreamJson] + |} + |""".stripMargin) + + val nonFinancials: RetrieveNonFinancials = + RetrieveNonFinancials( + businessDetailsChangedRecently = true, + class4NicsExemptionReason = Some(MtdNicExemption.`non-resident`) + ) + + val nonFinancialsMtdJson: JsValue = Json.parse(s""" + |{ + | "businessDetailsChangedRecently": true, + | "class4NicsExemptionReason": "non-resident" + | } + |""".stripMargin) + + val nonFinancialsDownstreamJson: JsValue = Json.parse(s""" + |{ + | "businessDetailsChangedRecently": true, + | "class4NicsExemptionReason": "001" + |} + |""".stripMargin) + + val retrieveResponseModel: Def3_RetrieveAnnualSubmissionResponse = Def3_RetrieveAnnualSubmissionResponse( + Some(adjustments), + Some(allowances), + Some(nonFinancials) + ) + + val mtdRetrieveResponseJson: JsValue = Json.parse(s""" + |{ + | "adjustments": $adjustmentsMtdJson, + | "allowances": $allowancesMtdJson, + | "nonFinancials": $nonFinancialsMtdJson + |} + |""".stripMargin) + + val downstreamRetrieveResponseJson: JsValue = Json.parse(s""" + |{ + | "annualAdjustments": $adjustmentsDownstreamJson, + | "annualAllowances": $allowancesDownstreamJson, + | "annualNonFinancials": $nonFinancialsDownstreamJson + |} + |""".stripMargin) + +} diff --git a/test/v4/retrieveAnnualSubmission/def3/model/response/Def3_RetrieveAnnualSubmissionResponseSpec.scala b/test/v4/retrieveAnnualSubmission/def3/model/response/Def3_RetrieveAnnualSubmissionResponseSpec.scala new file mode 100644 index 00000000..a32d98e8 --- /dev/null +++ b/test/v4/retrieveAnnualSubmission/def3/model/response/Def3_RetrieveAnnualSubmissionResponseSpec.scala @@ -0,0 +1,77 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def3.model.response + +import config.{MockSeBusinessFeatureSwitches, SeBusinessFeatureSwitches} +import play.api.Configuration +import play.api.libs.json.Json +import shared.config.MockSharedAppConfig +import shared.utils.UnitSpec +import v4.retrieveAnnualSubmission.def3.model.Def3_RetrieveAnnualSubmissionFixture + +class Def3_RetrieveAnnualSubmissionResponseSpec + extends UnitSpec + with MockSharedAppConfig + with Def3_RetrieveAnnualSubmissionFixture + with MockSeBusinessFeatureSwitches { + + private implicit val featureSwitches: SeBusinessFeatureSwitches = SeBusinessFeatureSwitches(Configuration.empty) + + private val retrieveAnnualSubmissionResponse = Def3_RetrieveAnnualSubmissionResponse( + allowances = Some(RetrieveAllowances(None, None, None, None, None, None, None, None, None, None, None, None)), + adjustments = Some(RetrieveAdjustments(None, None, None, None, None, None, None, None, None, None, None)), + nonFinancials = Some(RetrieveNonFinancials(businessDetailsChangedRecently = true, None)) + ) + + "reads" should { + "return a valid model" when { + "given valid JSON" in { + val result = Json + .parse(s"""{ + | "annualAllowances": {}, + | "annualAdjustments": {}, + | "annualNonFinancials": { + | "businessDetailsChangedRecently": true + | } + |} + |""".stripMargin) + .as[Def3_RetrieveAnnualSubmissionResponse] + + result shouldBe retrieveAnnualSubmissionResponse + } + } + } + + "writes" should { + "return valid JSON" when { + "given a valid Scala object" in { + val result = Json.toJson(retrieveAnnualSubmissionResponse) + + result shouldBe + Json.parse(s"""{ + | "allowances": {}, + | "adjustments": {}, + | "nonFinancials": { + | "businessDetailsChangedRecently": true + | } + |} + |""".stripMargin) + } + } + } + +} diff --git a/test/v4/retrieveAnnualSubmission/def3/model/response/RetrieveAdjustmentsSpec.scala b/test/v4/retrieveAnnualSubmission/def3/model/response/RetrieveAdjustmentsSpec.scala new file mode 100644 index 00000000..fd212d53 --- /dev/null +++ b/test/v4/retrieveAnnualSubmission/def3/model/response/RetrieveAdjustmentsSpec.scala @@ -0,0 +1,108 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def3.model.response + +import config.SeBusinessFeatureSwitches +import play.api.Configuration +import play.api.libs.json.Json +import shared.utils.UnitSpec + +class RetrieveAdjustmentsSpec extends UnitSpec { + + val adjustments: RetrieveAdjustments = + RetrieveAdjustments( + includedNonTaxableProfits = Some(1.12), + basisAdjustment = Some(2.12), + overlapReliefUsed = Some(3.12), + accountingAdjustment = Some(4.12), + averagingAdjustment = Some(5.12), + outstandingBusinessIncome = Some(6.12), + balancingChargeBpra = Some(7.12), + balancingChargeOther = Some(8.12), + goodsAndServicesOwnUse = Some(9.12), + transitionProfitAmount = Some(10.12), + transitionProfitAccelerationAmount = Some(11.13) + ) + + "reads" when { + "given valid downstream JSON" should { + "work" in { + Json + .parse(s"""{ + | "includedNonTaxableProfits": 1.12, + | "basisAdjustment": 2.12, + | "overlapReliefUsed": 3.12, + | "accountingAdjustment": 4.12, + | "averagingAdjustment": 5.12, + | "outstandingBusinessIncome": 6.12, + | "balancingChargeBpra": 7.12, + | "balancingChargeOther": 8.12, + | "goodsAndServicesOwnUse": 9.12, + | "transitionProfitAmount": 10.12, + | "transitionProfitAccelerationAmount": 11.13 + |} + |""".stripMargin) + .as[RetrieveAdjustments] shouldBe adjustments + } + } + } + + "writes" when { + "additional fields are switched on" should { + "include those fields" in { + implicit val featureSwitches: SeBusinessFeatureSwitches = + SeBusinessFeatureSwitches(Configuration("adjustmentsAdditionalFields.enabled" -> true)) + + Json.toJson(adjustments) shouldBe Json.parse(s"""{ + | "includedNonTaxableProfits": 1.12, + | "basisAdjustment": 2.12, + | "overlapReliefUsed": 3.12, + | "accountingAdjustment": 4.12, + | "averagingAdjustment": 5.12, + | "outstandingBusinessIncome": 6.12, + | "balancingChargeBpra": 7.12, + | "balancingChargeOther": 8.12, + | "goodsAndServicesOwnUse": 9.12, + | "transitionProfitAmount": 10.12, + | "transitionProfitAccelerationAmount": 11.13 + |} + |""".stripMargin) + } + } + + "additional fields are switched off" should { + "not include those fields" in { + implicit val featureSwitches: SeBusinessFeatureSwitches = + SeBusinessFeatureSwitches(Configuration("adjustmentsAdditionalFields.enabled" -> false)) + + Json.toJson(adjustments) shouldBe Json.parse(s"""{ + | "includedNonTaxableProfits": 1.12, + | "basisAdjustment": 2.12, + | "overlapReliefUsed": 3.12, + | "accountingAdjustment": 4.12, + | "averagingAdjustment": 5.12, + | "outstandingBusinessIncome": 6.12, + | "balancingChargeBpra": 7.12, + | "balancingChargeOther": 8.12, + | "goodsAndServicesOwnUse": 9.12 + |} + |""".stripMargin) + } + } + } + +} diff --git a/test/v4/retrieveAnnualSubmission/def3/model/response/RetrieveAllowancesSpec.scala b/test/v4/retrieveAnnualSubmission/def3/model/response/RetrieveAllowancesSpec.scala new file mode 100644 index 00000000..638d6c24 --- /dev/null +++ b/test/v4/retrieveAnnualSubmission/def3/model/response/RetrieveAllowancesSpec.scala @@ -0,0 +1,85 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def3.model.response + +import play.api.libs.json.Json +import shared.utils.UnitSpec + +class RetrieveAllowancesSpec extends UnitSpec { + + val model: RetrieveAllowances = RetrieveAllowances( + annualInvestmentAllowance = Some(1.12), + capitalAllowanceMainPool = Some(2.12), + capitalAllowanceSpecialRatePool = Some(3.12), + zeroEmissionsGoodsVehicleAllowance = Some(4.12), + businessPremisesRenovationAllowance = Some(5.12), + enhancedCapitalAllowance = Some(6.12), + allowanceOnSales = Some(7.12), + capitalAllowanceSingleAssetPool = Some(8.12), + tradingIncomeAllowance = Some(10.12), + zeroEmissionsCarAllowance = Some(11.12), + structuredBuildingAllowance = Some(Nil), + enhancedStructuredBuildingAllowance = Some(Nil) + ) + + "reads" when { + "passed valid mtd JSON" should { + "return the model" in { + Json + .parse(s"""{ + | "annualInvestmentAllowance": 1.12, + | "capitalAllowanceMainPool": 2.12, + | "capitalAllowanceSpecialRatePool": 3.12, + | "zeroEmissionGoodsVehicleAllowance": 4.12, + | "businessPremisesRenovationAllowance": 5.12, + | "enhanceCapitalAllowance": 6.12, + | "allowanceOnSales": 7.12, + | "capitalAllowanceSingleAssetPool": 8.12, + | "tradingIncomeAllowance": 10.12, + | "zeroEmissionsCarAllowance": 11.12, + | "structuredBuildingAllowance": [], + | "enhancedStructuredBuildingAllowance": [] + |} + |""".stripMargin) + .as[RetrieveAllowances] shouldBe model + } + } + } + + "writes" when { + "passed a model" should { + "return downstream JSON" in { + Json.toJson(model) shouldBe Json.parse(s"""{ + | "annualInvestmentAllowance": 1.12, + | "capitalAllowanceMainPool": 2.12, + | "capitalAllowanceSpecialRatePool": 3.12, + | "zeroEmissionsGoodsVehicleAllowance": 4.12, + | "businessPremisesRenovationAllowance": 5.12, + | "enhancedCapitalAllowance": 6.12, + | "allowanceOnSales": 7.12, + | "capitalAllowanceSingleAssetPool": 8.12, + | "tradingIncomeAllowance": 10.12, + | "zeroEmissionsCarAllowance": 11.12, + | "structuredBuildingAllowance": [], + | "enhancedStructuredBuildingAllowance": [] + |} + |""".stripMargin) + } + } + } + +} diff --git a/test/v4/retrieveAnnualSubmission/def3/model/response/RetrieveBuildingSpec.scala b/test/v4/retrieveAnnualSubmission/def3/model/response/RetrieveBuildingSpec.scala new file mode 100644 index 00000000..961e4476 --- /dev/null +++ b/test/v4/retrieveAnnualSubmission/def3/model/response/RetrieveBuildingSpec.scala @@ -0,0 +1,41 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def3.model.response + +import play.api.libs.json.Json +import shared.utils.UnitSpec +import v4.retrieveAnnualSubmission.def3.model.Def3_RetrieveAnnualSubmissionFixture + +class RetrieveBuildingSpec extends UnitSpec with Def3_RetrieveAnnualSubmissionFixture { + + "reads" when { + "passed a valid JSON" should { + "return the model" in { + buildingAllowanceDownstreamJson.as[RetrieveBuilding] shouldBe buildingMtdModel + } + } + } + + "writes" when { + "passed a model" should { + "return Mtd JSON" in { + Json.toJson(buildingMtdModel) shouldBe buildingAllowanceMtdJson + } + } + } + +} diff --git a/test/v4/retrieveAnnualSubmission/def3/model/response/RetrieveFirstYearSpec.scala b/test/v4/retrieveAnnualSubmission/def3/model/response/RetrieveFirstYearSpec.scala new file mode 100644 index 00000000..25d7108e --- /dev/null +++ b/test/v4/retrieveAnnualSubmission/def3/model/response/RetrieveFirstYearSpec.scala @@ -0,0 +1,53 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def3.model.response + +import play.api.libs.json.{JsValue, Json} +import shared.utils.UnitSpec + +class RetrieveFirstYearSpec extends UnitSpec { + + val model: RetrieveFirstYear = + RetrieveFirstYear( + "2020-01-01", + 3000.40 + ) + + val json: JsValue = Json.parse(""" + |{ + | "qualifyingDate": "2020-01-01", + | "qualifyingAmountExpenditure": 3000.40 + |} + |""".stripMargin) + + "reads" when { + "passed a valid JSON" should { + "return the model" in { + json.as[RetrieveFirstYear] shouldBe model + } + } + } + + "writes" when { + "passed a model" should { + "return downstream JSON" in { + Json.toJson(model) shouldBe json + } + } + } + +} diff --git a/test/v4/retrieveAnnualSubmission/def3/model/response/RetrieveNonFinancialsSpec.scala b/test/v4/retrieveAnnualSubmission/def3/model/response/RetrieveNonFinancialsSpec.scala new file mode 100644 index 00000000..ab9475c4 --- /dev/null +++ b/test/v4/retrieveAnnualSubmission/def3/model/response/RetrieveNonFinancialsSpec.scala @@ -0,0 +1,71 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def3.model.response + +import api.models.domain.ex.MtdNicExemption +import play.api.libs.json.{JsValue, Json} +import shared.utils.UnitSpec +import v4.retrieveAnnualSubmission.def3.model.Def3_RetrieveAnnualSubmissionFixture + +class RetrieveNonFinancialsSpec extends UnitSpec with Def3_RetrieveAnnualSubmissionFixture { + + "reads" should { + "passed a valid JSON" should { + "return the model" in { + val requestJson: JsValue = Json.parse(s""" + |{ + | "businessDetailsChangedRecently": true, + | "class4NicsExemptionReason": "001" + |} + |""".stripMargin) + + requestJson.as[RetrieveNonFinancials] shouldBe RetrieveNonFinancials( + businessDetailsChangedRecently = true, + class4NicsExemptionReason = Some(MtdNicExemption.`non-resident`) + ) + } + } + + "writes" when { + "passed a model" must { + "return json" in { + Json.toJson(nonFinancialsMtdJson) shouldBe + Json.parse(s""" + |{ + | "businessDetailsChangedRecently": true, + | "class4NicsExemptionReason": "non-resident" + |} + |""".stripMargin) + } + } + + "there is no exemption reason" must { + "set exemptFromPayingClass4Nics true" in { + Json.toJson( + RetrieveNonFinancials(businessDetailsChangedRecently = true, class4NicsExemptionReason = None) + ) shouldBe + Json.parse(s""" + |{ + | "businessDetailsChangedRecently": true + |} + |""".stripMargin) + } + } + } + } + +} diff --git a/test/v4/retrieveAnnualSubmission/def3/model/response/RetrieveStructuredBuildingAllowanceSpec.scala b/test/v4/retrieveAnnualSubmission/def3/model/response/RetrieveStructuredBuildingAllowanceSpec.scala new file mode 100644 index 00000000..55b4c5cf --- /dev/null +++ b/test/v4/retrieveAnnualSubmission/def3/model/response/RetrieveStructuredBuildingAllowanceSpec.scala @@ -0,0 +1,43 @@ +/* + * Copyright 2023 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package v4.retrieveAnnualSubmission.def3.model.response + +import play.api.libs.json.Json +import shared.utils.UnitSpec +import v4.retrieveAnnualSubmission.def3.model.Def3_RetrieveAnnualSubmissionFixture + +class RetrieveStructuredBuildingAllowanceSpec extends UnitSpec with Def3_RetrieveAnnualSubmissionFixture { + + "reads" when { + "passed a valid JSON" should { + "return the model" in { + val result = structuredBuildingAllowanceDownstreamJson.as[RetrieveStructuredBuildingAllowance] + result shouldBe structuredBuildingAllowance + } + } + } + + "writes" when { + "passed a model" should { + "return Mtd JSON" in { + val result = Json.toJson(structuredBuildingAllowance) + result shouldBe structuredBuildingAllowanceMtdJson + } + } + } + +}