I am following spray manual from here. So I put to gather pretty simple test
class AtoImportServiceApiTest extends WordSpecLike with MustMatchers with ScalatestRouteTest {
"AtoImportService" must {
"return HTTP status 401 Unauhorized when accessing withou basic auth" in {
Post("/ato/v1/orders/updateStatus") ~>new AtoImportServiceApi().route ~> check {
handled must be(false)
rejections must have size 1
status === StatusCodes.Unauthorized
}
}
}
}
I am calling route which contains authorized directive. So I would expect that rejection will get transformed to HTTP status code. But that is not happening here and test is failing.
Request was rejected with List(AuthenticationFailedRejection(CredentialsMissing,List(WWW-Authenticate: Basic realm="bd ato import api")))
ScalaTestFailureLocation: spray.testkit.RouteTest$class at (RouteTest.scala:74)
org.scalatest.exceptions.TestFailedException: Request was rejected with List(AuthenticationFailedRejection(CredentialsMissing,List(WWW-Authenticate: Basic realm="bd ato import api")))
at spray.testkit.ScalatestInterface$class.failTest(ScalatestInterface.scala:25)
Am I missing some important concept here?