Skip to content

Commit

Permalink
Add test to handle 400 response.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Seddon committed Jun 25, 2016
1 parent 514b0ad commit fa43013
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class HttpHandlerTest extends BaseSpec with TestableHttpHandler {
}
}

it should "handle 404 response" in {
it should "handle 404 response - resource not found" in {
val expectedHttpRequest = HttpRequest("https://app.ticketmaster.com/", queryParams = Map("apikey" -> "12345"))
.addHeader(s"User-Agent", s"Ticketmaster Test Scala/${build.Info.version}")
val httpResponse = HttpResponse(404, body = Some(HttpHandlerTest.error404))
Expand All @@ -133,6 +133,24 @@ class HttpHandlerTest extends BaseSpec with TestableHttpHandler {
t.getMessage should be("Errors(Vector(Error(ABC123,Resource not found with provided criteria,404)))")
}
}

it should "handle 400 response - invalid query param size" in {
val expectedHttpRequest = HttpRequest("https://app.ticketmaster.com/", queryParams = Map("apikey" -> "12345"))
.addHeader(s"User-Agent", s"Ticketmaster Test Scala/${build.Info.version}")
val httpResponse = HttpResponse(400, body = Some(HttpHandlerTest.error400))

val handler = newHttpHandler(expectedHttpRequest, httpResponse)

val actualHttpRequest = HttpRequest("https://app.ticketmaster.com/")
val responseHandler = (body: SomeBody, rateLimits: RateLimits) => SomeResponse(body, rateLimits)

val pendingResponse = handler.handleRequest[SomeBody, SomeResponse](actualHttpRequest, responseHandler)

whenReady(pendingResponse.failed) { t =>
t shouldBe a[ApiException]
t.getMessage should be("Errors(Vector(Error(ABC123,Query param \"size\" must be between 1 to 500,400)))")
}
}
}

object HttpHandlerTest {
Expand All @@ -151,4 +169,20 @@ object HttpHandlerTest {
| }]
|}
""".stripMargin

val error400 =
"""
|{
| "errors": [{
| "code": "ABC123",
| "detail": "Query param \"size\" must be between 1 to 500",
| "status": "400",
| "_links": {
| "about": {
| "href": "/errors.html#ABC123"
| }
| }
| }]
|}
""".stripMargin
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ object domain {
timeTBA: Boolean,
noSpecificTime: Boolean)

case class Status(code: String)
case class Status(code: Option[String])

case class Image(ratio: Option[String], url: String, width: Int, height: Int, fallback: Boolean)

Expand Down

0 comments on commit fa43013

Please sign in to comment.