Skip to content

Commit

Permalink
Add coveralls for code coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Seddon committed May 31, 2016
1 parent 17e6b89 commit be7b4c3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ language: scala
jdk:
- oraclejdk8
scala:
- 2.11.7
- 2.11.7
script:
- sbt clean coverage test &&
sbt coverageReport &&
sbt coverageAggregate
after_success:
- sbt coveralls
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ trait HttpHandler {
}

private def handleResponse[B, R](response: HttpResponse, handler: ResponseHandler[B, R])(implicit decode: DecodeJson[B]): R = {
def errors = decodeEither[Errors](response.body.get).map(_.toString).getOrElse("Failed to decode body")
def errors = decodeEither[Errors](response.body.get).map(_.toString).getOrElse(s"Failed to decode body: ${response.body.get}")

response.status match {
case status if okRange contains status => {
val parts = for {
decoded <- decodeEither[B] (response.body.get)
decoded <- decodeEither[B](response.body.get)
rateLimits <- extractRateLimitInfo(response)
} yield(decoded, rateLimits)
} yield (decoded, rateLimits)

parts.map(right => handler(right._1, right._2)) | (throw new ApiException("Failed to read response"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ class VenuesSpec extends BaseSpec with TestableDiscoveryApi {
t.getMessage should be("Errors(Vector(Error(DIS1004,Resource not found with provided criteria (locale=en-us, id=abcde),404)))")
}
}

it should "throw exception if sort param invalid" in {
val expectedRequest = HttpRequest(root = "https://app.ticketmaster.com/discovery/v2", queryParams = Map("sort" -> "asc", "apikey" -> testApiKey)) / "venues.json"
val response = HttpResponse(status = 400, headers = responseHeaders, body = Some(VenuesSpec.errorInvalidSortParam))
val api = testableApi(expectedRequest, response)

val pendingResponse: Future[PageResponse[Venues]] = api.searchVenues(SearchVenuesRequest(sort = "asc"))

whenReady(pendingResponse.failed) { t =>
t shouldBe a[ApiException]
t.getMessage should be("Errors(Vector(Error(DIS1005,Query param \"sort\" may take one of these two values only - {'name,asc', 'name,desc'},400)))")
}
}
}

object VenuesSpec {
Expand Down Expand Up @@ -257,4 +270,20 @@ object VenuesSpec {
| }]
|}
""".stripMargin

val errorInvalidSortParam =
"""
|{
| "errors": [{
| "code": "DIS1005",
| "detail": "Query param \"sort\" may take one of these two values only - {'name,asc', 'name,desc'}",
| "status": "400",
| "_links": {
| "about": {
| "href": "/discovery/v2/errors.html#DIS1005"
| }
| }
| }]
|}
""".stripMargin
}
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ Seq(
"com.timushev.sbt" % "sbt-updates" % "0.1.9",
"com.github.gseitz" % "sbt-release" % "1.0.3",
"org.tpolecat" % "tut-plugin" % "0.4.2",
"org.scoverage" % "sbt-scoverage" % "1.3.5",
"org.scoverage" % "sbt-coveralls" % "1.1.0",
"me.lessis" % "bintray-sbt" % "0.3.0"
).map(addSbtPlugin)

0 comments on commit be7b4c3

Please sign in to comment.