From d4b7160275f887856b78aaa13359a23a39217258 Mon Sep 17 00:00:00 2001 From: Narendra Vijayarao Date: Tue, 17 Apr 2018 14:04:14 +0100 Subject: [PATCH] MTDSA-1521 Obligations Des model update as per DES spec --- .../hmrc/vatapi/models/des/Obligations.scala | 4 +- .../wrappers/ObligationsResponse.scala | 2 +- .../gov/hmrc/support/BaseFunctionalSpec.scala | 24 +++++ .../gov/hmrc/vatapi/resources/DesJsons.scala | 92 +++++++++++++++++++ .../resources/ObligationsResourceSpec.scala | 22 +++++ 5 files changed, 141 insertions(+), 3 deletions(-) diff --git a/app/uk/gov/hmrc/vatapi/models/des/Obligations.scala b/app/uk/gov/hmrc/vatapi/models/des/Obligations.scala index e67bc88e..2e144e88 100644 --- a/app/uk/gov/hmrc/vatapi/models/des/Obligations.scala +++ b/app/uk/gov/hmrc/vatapi/models/des/Obligations.scala @@ -24,13 +24,13 @@ object Obligations { implicit val reads: Reads[Obligations] = Json.reads[Obligations] } -case class Obligation(identification: ObligationIdentification, obligationDetails: Seq[ObligationDetail]) +case class Obligation(identification: Option[ObligationIdentification] = None, obligationDetails: Seq[ObligationDetail]) object Obligation { implicit val reads: Reads[Obligation] = Json.reads[Obligation] } -case class ObligationIdentification(incomeSourceType: String, referenceNumber: String, referenceType: String) +case class ObligationIdentification(incomeSourceType: Option[String] = None, referenceNumber: String, referenceType: String) object ObligationIdentification { implicit val reads: Reads[ObligationIdentification] = Json.reads[ObligationIdentification] diff --git a/app/uk/gov/hmrc/vatapi/resources/wrappers/ObligationsResponse.scala b/app/uk/gov/hmrc/vatapi/resources/wrappers/ObligationsResponse.scala index 9b09e5fc..9aff76f4 100644 --- a/app/uk/gov/hmrc/vatapi/resources/wrappers/ObligationsResponse.scala +++ b/app/uk/gov/hmrc/vatapi/resources/wrappers/ObligationsResponse.scala @@ -37,7 +37,7 @@ case class ObligationsResponse(underlying: HttpResponse) extends Response { def oneFound(obligation: des.Obligations): Either[DesTransformError, Option[Obligations]] = { errorMessage = "Obligation for VAT type was not found." - obligation.obligations.find(obj => obj.identification.referenceNumber == vrn.toString() && obj.identification.referenceType == "VRN").fold(noneFound) { + obligation.obligations.find(obj => obj.obligationDetails.nonEmpty).fold(noneFound) { desObligation => val obligationsOrError: Seq[Either[DesTransformError, Obligation]] = for { details <- desObligation.obligationDetails diff --git a/func/uk/gov/hmrc/support/BaseFunctionalSpec.scala b/func/uk/gov/hmrc/support/BaseFunctionalSpec.scala index 14011bb2..437e184d 100644 --- a/func/uk/gov/hmrc/support/BaseFunctionalSpec.scala +++ b/func/uk/gov/hmrc/support/BaseFunctionalSpec.scala @@ -571,6 +571,30 @@ trait BaseFunctionalSpec extends TestApplication { givens } + + def returnObligationsWithoutIdentificationFor(vrn: Vrn): Givens = { + stubFor(any(urlMatching(s".*/vrn/$vrn.*")) + .willReturn( + aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withHeader("CorrelationId", "abc") + .withBody(DesJsons.ObligationsWithoutIdentification(vrn.toString())))) + + givens + } + + def returnObligationsWithIdentificationButNoIncomeSourceTypeFor(vrn: Vrn): Givens = { + stubFor(any(urlMatching(s".*/vrn/$vrn.*")) + .willReturn( + aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withHeader("CorrelationId", "abc") + .withBody(DesJsons.ObligationsWithNoIncomeSourceType(vrn.toString())))) + + givens + } } object vatReturns { diff --git a/func/uk/gov/hmrc/vatapi/resources/DesJsons.scala b/func/uk/gov/hmrc/vatapi/resources/DesJsons.scala index 3bb93361..2ded3a45 100644 --- a/func/uk/gov/hmrc/vatapi/resources/DesJsons.scala +++ b/func/uk/gov/hmrc/vatapi/resources/DesJsons.scala @@ -82,6 +82,98 @@ object DesJsons { } } + object ObligationsWithNoIncomeSourceType { + def apply(id: String = "abc"): String = { + s""" + |{ + | "obligations": [ + | { + | "identification": { + | "referenceNumber": "$id", + | "referenceType": "VRN" + | }, + | "obligationDetails": [ + | { + | "status": "F", + | "inboundCorrespondenceFromDate": "2017-04-06", + | "inboundCorrespondenceToDate": "2017-07-05", + | "inboundCorrespondenceDateReceived": "2017-08-01", + | "inboundCorrespondenceDueDate": "2017-08-05", + | "periodKey": "#001" + | }, + | { + | "status": "O", + | "inboundCorrespondenceFromDate": "2017-07-06", + | "inboundCorrespondenceToDate": "2017-10-05", + | "inboundCorrespondenceDueDate": "2017-11-05", + | "periodKey": "#002" + | }, + | { + | "status": "O", + | "inboundCorrespondenceFromDate": "2017-10-06", + | "inboundCorrespondenceToDate": "2018-01-05", + | "inboundCorrespondenceDueDate": "2018-02-05", + | "periodKey": "#003" + | }, + | { + | "status": "O", + | "inboundCorrespondenceFromDate": "2018-01-06", + | "inboundCorrespondenceToDate": "2018-04-05", + | "inboundCorrespondenceDueDate": "2018-05-06", + | "periodKey": "#004" + | } + | ] + | } + | ] + |} + """.stripMargin + } + } + + object ObligationsWithoutIdentification { + def apply(id: String = "abc"): String = { + s""" + |{ + | "obligations": [ + | { + | "obligationDetails": [ + | { + | "status": "F", + | "inboundCorrespondenceFromDate": "2017-04-06", + | "inboundCorrespondenceToDate": "2017-07-05", + | "inboundCorrespondenceDateReceived": "2017-08-01", + | "inboundCorrespondenceDueDate": "2017-08-05", + | "periodKey": "#001" + | }, + | { + | "status": "O", + | "inboundCorrespondenceFromDate": "2017-07-06", + | "inboundCorrespondenceToDate": "2017-10-05", + | "inboundCorrespondenceDueDate": "2017-11-05", + | "periodKey": "#002" + | }, + | { + | "status": "O", + | "inboundCorrespondenceFromDate": "2017-10-06", + | "inboundCorrespondenceToDate": "2018-01-05", + | "inboundCorrespondenceDueDate": "2018-02-05", + | "periodKey": "#003" + | }, + | { + | "status": "O", + | "inboundCorrespondenceFromDate": "2018-01-06", + | "inboundCorrespondenceToDate": "2018-04-05", + | "inboundCorrespondenceDueDate": "2018-05-06", + | "periodKey": "#004" + | } + | ] + | } + | ] + |} + """.stripMargin + } + } + object FinancialData { val oneLiability: JsValue = Json.parse("""{ "idType": "MTDBSA", diff --git a/func/uk/gov/hmrc/vatapi/resources/ObligationsResourceSpec.scala b/func/uk/gov/hmrc/vatapi/resources/ObligationsResourceSpec.scala index e8d04943..ac850bf5 100644 --- a/func/uk/gov/hmrc/vatapi/resources/ObligationsResourceSpec.scala +++ b/func/uk/gov/hmrc/vatapi/resources/ObligationsResourceSpec.scala @@ -91,6 +91,28 @@ class ObligationsResourceSpec extends BaseFunctionalSpec { .bodyIsLike(Jsons.Obligations(firstMet = "F").toString) } + "return code 200 with a set of obligations with out identifications" in { + given() + .userIsFullyAuthorisedForTheResource + .des().obligations.returnObligationsWithoutIdentificationFor(vrn) + .when() + .get(s"/$vrn/obligations?from=2017-01-01&to=2017-08-31&status=A") + .thenAssertThat() + .statusIs(200) + .bodyIsLike(Jsons.Obligations(firstMet = "F").toString) + } + + "return code 200 with a set of obligations with identifications but no incomeSourceType" in { + given() + .userIsFullyAuthorisedForTheResource + .des().obligations.returnObligationsWithIdentificationButNoIncomeSourceTypeFor(vrn) + .when() + .get(s"/$vrn/obligations?from=2017-01-01&to=2017-08-31&status=A") + .thenAssertThat() + .statusIs(200) + .bodyIsLike(Jsons.Obligations(firstMet = "F").toString) + } + "reject client with no authorization" in { given() .userIsNotAuthorisedForTheResource