Skip to content

Commit

Permalink
[MTDSA-1171] [CK] Remove vat context, add periodKey, change metDate t…
Browse files Browse the repository at this point in the history
…o received.
  • Loading branch information
Chandrashekhar Korivi authored and Chandrashekhar Korivi committed Oct 23, 2017
1 parent 702c27f commit 88358d9
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 48 deletions.
5 changes: 3 additions & 2 deletions app/uk/gov/hmrc/vatapi/models/Obligations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object Obligations {
implicit val writes: Writes[Obligations] = Json.writes[Obligations]
}

case class Obligation(start: LocalDate, end: LocalDate, due: LocalDate, met: Boolean, metDate : Option[LocalDate] = None)
case class Obligation(start: LocalDate, end: LocalDate, due: LocalDate, met: Boolean, periodKey : String, received : Option[LocalDate] = None)

object Obligation {
implicit val jodaDateWrites: Writes[LocalDate] = new Writes[LocalDate] {
Expand All @@ -42,7 +42,8 @@ object Obligation {
end = LocalDate.parse(desObligation.inboundCorrespondenceToDate),
due = LocalDate.parse(desObligation.inboundCorrespondenceDueDate),
met = desObligation.isFulfilled,
metDate = desObligation.inboundCorrespondenceDateReceived.map(LocalDate.parse))
periodKey = desObligation.periodKey,
received = desObligation.inboundCorrespondenceDateReceived.map(LocalDate.parse))
) match {
case Success(obj) => Right(obj)
case Failure(ex) => Left(InvalidDateError(s"Unable to parse the date from des response $ex"))
Expand Down
2 changes: 1 addition & 1 deletion conf/live.routes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# microservice specific routes

# Obligations
GET /vat/:vrn/obligations uk.gov.hmrc.vatapi.resources.ObligationsResource.retrieveObligations(vrn: uk.gov.hmrc.domain.Vrn, queryParams: uk.gov.hmrc.vatapi.models.ObligationsQueryParams)
GET /:vrn/obligations uk.gov.hmrc.vatapi.resources.ObligationsResource.retrieveObligations(vrn: uk.gov.hmrc.domain.Vrn, queryParams: uk.gov.hmrc.vatapi.models.ObligationsQueryParams)
8 changes: 4 additions & 4 deletions func/uk/gov/hmrc/vatapi/resources/DesJsons.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,28 @@ object DesJsons {
| "inboundCorrespondenceToDate": "2017-07-05",
| "inboundCorrespondenceDateReceived": "2017-08-01",
| "inboundCorrespondenceDueDate": "2017-08-05",
| "periodKey": "004"
| "periodKey": "#001"
| },
| {
| "status": "O",
| "inboundCorrespondenceFromDate": "2017-07-06",
| "inboundCorrespondenceToDate": "2017-10-05",
| "inboundCorrespondenceDueDate": "2017-11-05",
| "periodKey": "004"
| "periodKey": "#002"
| },
| {
| "status": "O",
| "inboundCorrespondenceFromDate": "2017-10-06",
| "inboundCorrespondenceToDate": "2018-01-05",
| "inboundCorrespondenceDueDate": "2018-02-05",
| "periodKey": "004"
| "periodKey": "#003"
| },
| {
| "status": "O",
| "inboundCorrespondenceFromDate": "2018-01-06",
| "inboundCorrespondenceToDate": "2018-04-05",
| "inboundCorrespondenceDueDate": "2018-05-06",
| "periodKey": "004"
| "periodKey": "#004"
| }
| ]
| },
Expand Down
22 changes: 11 additions & 11 deletions func/uk/gov/hmrc/vatapi/resources/ObligationsResourceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,64 +8,64 @@ class ObligationsResourceSpec extends BaseFunctionalSpec {

"return code 400 when vrn is invalid" in {
when()
.get(s"/vat/abc/obligations?from=2017-01-01&to=2017-03-31&status=A")
.get(s"/abc/obligations?from=2017-01-01&to=2017-03-31&status=A")
.thenAssertThat()
.statusIs(400)
.isBadRequest("VRN_INVALID")
}

"return code 400 when from is missing" in {
when()
.get(s"/vat/$vrn/obligations?to=2017-03-31&status=A")
.get(s"/$vrn/obligations?to=2017-03-31&status=A")
.thenAssertThat()
.statusIs(400)
}

"return code 400 when from is invalid" in {
when()
.get(s"/vat/$vrn/obligations?from=abc&to=2017-03-31&status=A")
.get(s"/$vrn/obligations?from=abc&to=2017-03-31&status=A")
.thenAssertThat()
.statusIs(400)
}

"return code 400 when to is missing" in {
when()
.get(s"/vat/$vrn/obligations?from=2017-01-01&status=A")
.get(s"/$vrn/obligations?from=2017-01-01&status=A")
.thenAssertThat()
.statusIs(400)
}

"return code 400 when to is invalid" in {
when()
.get(s"/vat/$vrn/obligations?from=2017-01-01&to=abc&status=A")
.get(s"/$vrn/obligations?from=2017-01-01&to=abc&status=A")
.thenAssertThat()
.statusIs(400)
}

"return code 400 when status is missing" in {
when()
.get(s"/vat/$vrn/obligations?from=2017-01-01&to=2017-03-31")
.get(s"/$vrn/obligations?from=2017-01-01&to=2017-03-31")
.thenAssertThat()
.statusIs(400)
}

"return code 400 when status is invalid" in {
when()
.get(s"/vat/$vrn/obligations?from=2017-01-01&to=2017-03-31&status=X")
.get(s"/$vrn/obligations?from=2017-01-01&to=2017-03-31&status=X")
.thenAssertThat()
.statusIs(400)
}

"return code 400 when from is after to" in {
when()
.get(s"/vat/$vrn/obligations?from=2017-04-01&to=2017-03-31&status=A")
.get(s"/$vrn/obligations?from=2017-04-01&to=2017-03-31&status=A")
.thenAssertThat()
.statusIs(400)
}

"return code 400 when date range between from and to is more than 366 days" in {
when()
.get(s"/vat/$vrn/obligations?from=2017-01-01&to=2018-01-02&status=A")
.get(s"/$vrn/obligations?from=2017-01-01&to=2018-01-02&status=A")
.thenAssertThat()
.statusIs(400)
}
Expand All @@ -74,7 +74,7 @@ class ObligationsResourceSpec extends BaseFunctionalSpec {
given()
.des().obligations.obligationNotFoundFor(vrn)
.when()
.get(s"/vat/$vrn/obligations?from=2017-01-01&to=2017-08-31&status=A")
.get(s"/$vrn/obligations?from=2017-01-01&to=2017-08-31&status=A")
.thenAssertThat()
.statusIs(404)
}
Expand All @@ -83,7 +83,7 @@ class ObligationsResourceSpec extends BaseFunctionalSpec {
given()
.des().obligations.returnObligationsFor(vrn)
.when()
.get(s"/vat/$vrn/obligations?from=2017-01-01&to=2017-08-31&status=A")
.get(s"/$vrn/obligations?from=2017-01-01&to=2017-08-31&status=A")
.thenAssertThat()
.statusIs(200)
.bodyIsLike(Jsons.Obligations(firstMet = true).toString)
Expand Down
44 changes: 24 additions & 20 deletions public/api/conf/0.1/application.raml
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,13 @@ traits:
description: Vat registration number.
type: string
example: "123456789"
/periods/{periodKey}:
description: Submit VAT return for period.
uriParameters:
periodKey:
description: Identifier for the period of the VAT return
type: string
example: "#001"
post:
description: Submit VAT return for period.
body:
application/json:
type: !include schemas/submitVatReturn.json
example: !include examples/vatReturn.json
responses:
200:
headers:
X-CorrelationId:
example: 5968c22d620000620096db5f
description: Unique id for operation tracking
/obligations:
displayName: Retrieve all VAT obligations
description: Retrieve all VAT obligations
(annotations.sandboxData): !include scenarios/vat-obligation-scenarios.md
is: [contentType, testScenarioHeader]
(annotations.scope): "read:vat"
securedBy: [ sec.oauth_2_0: { scopes: [ "read:vat" ] } ]
get:
description: Retrieve all VAT obligations.
queryParameters:
Expand All @@ -76,7 +59,7 @@ traits:
example: 2017-01-25
required: true
status:
description: Which obligation statuses to return (O=Open,C=Closed,A=All)
description: Which obligation statuses to return (O=Open, F=Fulfilled, A=All)
type: string
example: A
required: true
Expand Down Expand Up @@ -115,3 +98,24 @@ traits:
description: Invalid status
value:
code: INVALID_STATUS
/periods/{periodKey}:
description: Submit VAT return for period.
(annotations.scope): "write:vat"
securedBy: [ sec.oauth_2_0: { scopes: [ "write:vat" ] } ]
uriParameters:
periodKey:
description: Identifier for the period of the VAT return
type: string
example: "#001"
post:
description: Submit VAT return for period.
body:
application/json:
type: !include schemas/submitVatReturn.json
example: !include examples/vatReturn.json
responses:
200:
headers:
X-CorrelationId:
example: 5968c22d620000620096db5f
description: Unique id for operation tracking
4 changes: 2 additions & 2 deletions public/api/conf/0.1/examples/Obligations.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"end": "2017-07-05",
"due": "2017-08-05",
"met": true,
"metDate": "2017-08-05",
"received": "2017-08-05",
"periodKey": "#001"
},
{
Expand All @@ -27,7 +27,7 @@
"end": "2018-04-05",
"due": "2018-05-06",
"met": true,
"metDate": "2018-05-06",
"received": "2018-05-06",
"periodKey": "#004"
}
]
Expand Down
6 changes: 3 additions & 3 deletions public/api/conf/0.1/schemas/Obligation.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"type": "boolean",
"example": "true or false"
},
"metDate": {
"title": "Met Date",
"description": "The obligation met date",
"received": {
"title": "Received Date",
"description": "The obligation received date",
"$ref": "FullDate.json"
},
"periodKey": {
Expand Down
12 changes: 8 additions & 4 deletions test/uk/gov/hmrc/vatapi/resources/Jsons.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,25 +126,29 @@ object Jsons {
| "end": "2017-07-05",
| "due": "2017-08-05",
| "met": $firstMet,
| "metDate": "2017-08-01"
| "received": "2017-08-01",
| "periodKey": "#001"
| },
| {
| "start": "2017-07-06",
| "end": "2017-10-05",
| "due": "2017-11-05",
| "met": $secondMet
| "met": $secondMet,
| "periodKey": "#002"
| },
| {
| "start": "2017-10-06",
| "end": "2018-01-05",
| "due": "2018-02-05",
| "met": $thirdMet
| "met": $thirdMet,
| "periodKey": "#003"
| },
| {
| "start": "2018-01-06",
| "end": "2018-04-05",
| "due": "2018-05-06",
| "met": $fourthMet
| "met": $fourthMet,
| "periodKey": "#004"
| }
| ]
|}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class ObligationsResponseSpec extends UnitSpec {
val response = ObligationsResponse(HttpResponse(200, Some(obligationJson)))

val obligations = response.obligations
obligations.right.get.get.obligations.find(o => o.metDate.get == new LocalDate("2017-04-25")) shouldBe defined
obligations.right.get.get.obligations.find(o => o.received.get == new LocalDate("2017-04-25")) shouldBe defined
}
}
}

0 comments on commit 88358d9

Please sign in to comment.