Skip to content

Commit

Permalink
Merge pull request #117 from hmrc/MTDSA-1521
Browse files Browse the repository at this point in the history
MTDSA-1521 Obligations Des model update as per DES spec
  • Loading branch information
Scott Lace authored Apr 17, 2018
2 parents 7acd619 + d4b7160 commit a2935b3
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/uk/gov/hmrc/vatapi/models/des/Obligations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions func/uk/gov/hmrc/support/BaseFunctionalSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,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 {
Expand Down
92 changes: 92 additions & 0 deletions func/uk/gov/hmrc/vatapi/resources/DesJsons.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 22 additions & 0 deletions func/uk/gov/hmrc/vatapi/resources/ObligationsResourceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a2935b3

Please sign in to comment.