Skip to content

Commit

Permalink
API tidy up: Added taxOfficeNumber/Reference to some responses that w…
Browse files Browse the repository at this point in the history
…ere missing it. Added missing links to responses. Added description to writeOffs on Monthly Statement.
  • Loading branch information
Tim Golding committed Feb 21, 2018
1 parent b719b33 commit 8bd8173
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 19 deletions.
13 changes: 6 additions & 7 deletions app/uk/gov/hmrc/epayeapi/models/out/AnnualStatementJson.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,16 @@ case class SelfLink(

case class AnnualStatementLinksJson(
empRefs: Link,
summary: Link,
statements: Link,
self: Link,
next: Link,
previous: Link
)

case class AnnualStatementJson(
taxOfficeNumber: String,
taxOfficeReference: String,
taxYear: TaxYear,
nonRtiCharges: Seq[NonRtiChargesJson],
_embedded: EmbeddedRtiChargesJson,
Expand All @@ -134,6 +137,8 @@ case class AnnualStatementJson(
object AnnualStatementJson {
def apply(apiBaseUrl: String, empRef: EmpRef, taxYear: TaxYear, epayeAnnualStatement: EpayeAnnualStatement): AnnualStatementJson =
AnnualStatementJson(
taxOfficeNumber = empRef.taxOfficeNumber,
taxOfficeReference = empRef.taxOfficeReference,
taxYear = taxYear,
_embedded = EmbeddedRtiChargesJson(
EarlierYearUpdateJson.extractFrom(epayeAnnualStatement.rti.lineItems),
Expand All @@ -142,6 +147,7 @@ object AnnualStatementJson {
nonRtiCharges = epayeAnnualStatement.nonRti.lineItems.flatMap(NonRtiChargesJson.from(_, taxYear)),
_links = AnnualStatementLinksJson(
empRefs = Link.empRefsLink,
summary = Link.summaryLink(empRef),
statements = Link.statementsLink(empRef),
self = Link.anualStatementLink(empRef, taxYear),
next = Link.anualStatementLink(empRef, taxYear.next),
Expand All @@ -150,10 +156,3 @@ object AnnualStatementJson {
)

}

case class AllAnnualStatementLinksJson(
empRefs: Link,
self: Link,
next: Link,
previous: Link
)
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ case class MonthlySummaryJson(

case class MonthlyStatementLinksJson(
empRefs: Link,
summary: Link,
statements: Link,
annualStatement: Link,
self: Link,
Expand Down Expand Up @@ -127,8 +128,10 @@ object MonthlyStatementLinksJson {
MonthlyStatementLinksJson(
empRefs =
Link.empRefsLink,
statements =
summary =
Link.summaryLink(empRef),
statements =
Link.statementsLink(empRef),
annualStatement =
Link.anualStatementLink(empRef, taxYear),
self =
Expand Down
4 changes: 4 additions & 0 deletions app/uk/gov/hmrc/epayeapi/models/out/StatementsJson.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import uk.gov.hmrc.domain.EmpRef
import uk.gov.hmrc.epayeapi.models.TaxYear

case class StatementsJson(
taxOfficeNumber: String,
taxOfficeReference: String,
_embedded: Embedded,
_links: Links
)
Expand Down Expand Up @@ -66,6 +68,8 @@ object StatementsJson {
)

StatementsJson(
taxOfficeNumber = empRef.taxOfficeNumber,
taxOfficeReference = empRef.taxOfficeReference,
_embedded = Embedded(statements),
_links = links
)
Expand Down
6 changes: 4 additions & 2 deletions app/uk/gov/hmrc/epayeapi/models/out/SummaryJson.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ object SummaryJson {

case class SummaryLinks(
empRefs: Link,
self: Link
self: Link,
statements: Link
)

object SummaryLinks {
def apply(empRef: EmpRef): SummaryLinks = SummaryLinks(
Link.empRefsLink,
Link.summaryLink(empRef)
Link.summaryLink(empRef),
Link.statementsLink(empRef)
)
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"taxOfficeNumber": "001",
"taxOfficeReference": "AB00001",
"taxYear": {
"year": "2016-17",
"firstDay": "2016-04-06",
Expand Down Expand Up @@ -50,6 +52,9 @@
"empRefs": {
"href": "/organisations/paye/"
},
"summary": {
"href": "/organisations/paye/001/AB00001"
},
"statements": {
"href": "/organisations/paye/001/AB00001/statements"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
"empRefs": {
"href": "/organisations/paye/"
},
"summary": {
"href": "/organisations/paye/001/AB00001"
},
"statements": {
"href": "/organisations/paye/001/AB00001/statements"
},
Expand Down
2 changes: 2 additions & 0 deletions resources/public/api/conf/1.0/examples/Statements.get.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"taxOfficeNumber": "001",
"taxOfficeReference": "AB00001",
"_embedded": {
"statements": [{
"taxYear": {
Expand Down
3 changes: 3 additions & 0 deletions resources/public/api/conf/1.0/examples/Summary.get.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
},
"self": {
"href": "/organisations/paye/001/AB00001"
},
"statements": {
"href": "/organisations/paye/001/AB00001/statements"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"type": "object",
"description": "Annual Statement for the requested year",
"properties": {
"taxOfficeNumber": {
"$ref": "Definitions.schema.json#/definitions/taxOfficeNumber"
},
"taxOfficeReference": {
"$ref": "Definitions.schema.json#/definitions/taxOfficeReference"
},
"taxYear": {
"$ref": "Definitions.schema.json#/definitions/taxYear"
},
Expand All @@ -17,6 +23,8 @@
}
},
"required": [
"taxOfficeNumber",
"taxOfficeReference",
"taxYear",
"nonRtiCharges",
"_embedded",
Expand Down Expand Up @@ -132,10 +140,14 @@
"description": "Link to the list of available empRefs",
"$ref": "Definitions.schema.json#/definitions/link"
},
"statements": {
"summary": {
"description": "Link to the account summary for the given empRef",
"$ref": "Definitions.schema.json#/definitions/link"
},
"statements": {
"description": "Link to the account statements for the given empRef",
"$ref": "Definitions.schema.json#/definitions/link"
},
"self": {
"$ref": "Definitions.schema.json#/definitions/link"
},
Expand All @@ -150,6 +162,7 @@
},
"required": [
"empRefs",
"summary",
"statements",
"self",
"next",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
}
},
"writeOffs": {
"description": "Adjustments for charges that have been written-off (cancelled) by HMRC. i.e. the charges have been cleared without payment.",
"$ref": "#/definitions/monthlyItems"
},
"dueDate": {
Expand Down Expand Up @@ -95,15 +96,19 @@
"statements": {
"$ref": "Definitions.schema.json#/definitions/link"
},
"summary": {
"$ref": "Definitions.schema.json#/definitions/link"
},
"empRefs": {
"$ref": "Definitions.schema.json#/definitions/link"
}
},
"required": [
"self",
"annualStatement",
"empRefs",
"summary",
"statements",
"empRefs"
"annualStatement",
"self"
]
}
},
Expand Down
8 changes: 8 additions & 0 deletions resources/public/api/conf/1.0/schemas/Statements.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"type": "object",
"description": "Statements links for the given empRef",
"properties": {
"taxOfficeNumber": {
"$ref": "Definitions.schema.json#/definitions/taxOfficeNumber"
},
"taxOfficeReference": {
"$ref": "Definitions.schema.json#/definitions/taxOfficeReference"
},
"_embedded": {
"$ref": "#/definitions/embedded"
},
Expand All @@ -11,6 +17,8 @@
}
},
"required": [
"taxOfficeNumber",
"taxOfficeReference",
"_embedded",
"_links"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,16 @@
"empRefs": {
"description": "Link to the list of available empRefs",
"$ref": "Definitions.schema.json#/definitions/link"
},
"statements": {
"description": "Link to the account statements for the given empRef",
"$ref": "Definitions.schema.json#/definitions/link"
}
},
"required": [
"empRefs",
"self",
"empRefs"
"statements"
]
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/common/Fixtures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ object Fixtures {
def expectedAnnualStatementJson(empRef: EmpRef): JsValue = Json.parse(
s"""
|{
| "taxOfficeNumber": "${empRef.taxOfficeNumber}",
| "taxOfficeReference": "${empRef.taxOfficeReference}",
| "taxYear": {
| "year": "2017-18",
| "firstDay": "2017-04-06",
Expand Down Expand Up @@ -192,6 +194,9 @@ object Fixtures {
| "empRefs": {
| "href": "/organisations/paye/"
| },
| "summary": {
| "href": "/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}"
| },
| "statements": {
| "href": "/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/statements"
| },
Expand All @@ -212,6 +217,8 @@ object Fixtures {
def expectedStatementLinksJson(empRef: EmpRef): JsValue = Json.parse(
s"""
|{
| "taxOfficeNumber": "${empRef.taxOfficeNumber}",
| "taxOfficeReference": "${empRef.taxOfficeReference}",
| "_embedded": {
| "statements": [{
| "taxYear": {
Expand Down
2 changes: 2 additions & 0 deletions test/integration/GetStatementsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class GetStatementsSpec extends IntegrationTestBase {
.bodyIsOfJson(Json.parse(
s"""
|{
| "taxOfficeNumber": "${empRef.taxOfficeNumber}",
| "taxOfficeReference": "${empRef.taxOfficeReference}",
| "_embedded": {
| "statements": [{
| "taxYear": {
Expand Down
3 changes: 3 additions & 0 deletions test/integration/GetSummarySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class GetSummarySpec
| },
| "self": {
| "href": "/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}"
| },
| "statements": {
| "href": "/organisations/paye/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/statements"
| }
| }
|}
Expand Down
5 changes: 4 additions & 1 deletion test/resources/epaye/monthly-statement/out/2017-3.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@
"empRefs": {
"href": "/organisations/paye/"
},
"statements": {
"summary": {
"href": "/organisations/paye/%{ton}/%{tor}"
},
"statements": {
"href": "/organisations/paye/%{ton}/%{tor}/statements"
},
"annualStatement": {
"href": "/organisations/paye/%{ton}/%{tor}/statements/2017-18"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class AnnualStatementJsonSpec extends WordSpec with Matchers {
AnnualStatementJson(apiBaseUrl, empRef, taxYear, emptyEpayeAnnualStatement)._links shouldBe
AnnualStatementLinksJson(
empRefs = Link.empRefsLink,
summary = Link.summaryLink(empRef),
statements = Link.statementsLink(empRef),
self = Link.anualStatementLink(empRef, taxYear),
next = Link.anualStatementLink(empRef, taxYear.next),
Expand Down
9 changes: 6 additions & 3 deletions test/uk/gov/hmrc/epayeapi/models/out/StatementsJsonSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class StatementsJsonSpec extends WordSpec with Matchers {

"StatementsJson.apply" should {
"return a result with empty statements when the year of registration is missing" in {
StatementsJson.apply(empRef, None) shouldBe StatementsJson(Embedded(Seq.empty), _links)
StatementsJson.apply(empRef, None) shouldBe
StatementsJson(empRef.taxOfficeNumber, empRef.taxOfficeReference, Embedded(Seq.empty), _links)
}
"return a result with a statement link for the current tax year" in {
val currentTaxYear = TaxYear(LocalDate.now())
Expand All @@ -45,7 +46,8 @@ class StatementsJsonSpec extends WordSpec with Matchers {
)
val _embedded = Embedded(Seq(currentTaxYearStatement))

StatementsJson.apply(empRef, Some(currentTaxYear)) shouldBe StatementsJson(_embedded, _links)
StatementsJson.apply(empRef, Some(currentTaxYear)) shouldBe
StatementsJson(empRef.taxOfficeNumber, empRef.taxOfficeReference, _embedded, _links)
}
"return a result with statement links for 2015, 2016 and 2017" in {
val yearOfRegistration = 2015
Expand All @@ -61,7 +63,8 @@ class StatementsJsonSpec extends WordSpec with Matchers {

val _embedded = Embedded(statements)

StatementsJson.apply(empRef, Some(TaxYear(yearOfRegistration))) shouldBe StatementsJson(_embedded, _links)
StatementsJson.apply(empRef, Some(TaxYear(yearOfRegistration))) shouldBe
StatementsJson(empRef.taxOfficeNumber, empRef.taxOfficeReference, _embedded, _links)
}
}
}
Expand Down

0 comments on commit 8bd8173

Please sign in to comment.