lundi 30 avril 2018

How can I supply a cookie in a Scalatra test request?

I have a Scalatra controller method that reads and sets some cookies. It looks something like this:

get("/cookietest") {
  cookies.get("testcookie") match {
    case Some(value) =>
      cookies.update("testcookie",s"pong:$value")
      cookies.set("testcookie_set", "0")
      Ok(value)
    case None =>
      BadRequest("No cookie")
  }
}

I cannot seem to find a way to send cookies with the request in the test method:

// I want to do something like this:
test("GET / on DownloadsServlet should return status 200"){
  request.setCookies("testcookie", "wtf")
  get("/cookietest"){
    cookies("testcookie") should equal ("pong:wtf")
    cookies("testcookie_set") should equal ("0")
    status should equal (HttpStatus.OK_200)
  }
}

There is no request or cookies in scope, though.

Aucun commentaire:

Enregistrer un commentaire