I wrote an action constructor and applied this new action to my controller with Injection.
Below is my code:
class AuthAction @Inject()(authService: AuthService) {
def AuthAction(userId: Int) = new ActionBuilder[Request] with ActionFilter[Request] {
def filter[A](request: Request[A]): Future[Option[Result]] = {
request.headers.get("Authorization").map(header => {
authService.isAuth(header).flatMap {
case true => Future.successfuly(None)
case false => Future.successfuly(Some(Forbidden))
}
})
}
}
}
class UserController @Inject()(auth: AuthAction, xxxService: XxxService) extends Controller {
def xxx(userId: Int) = auth.AuthAction(userId).async { implicit request =>
xxxService.xxx().map.......
}
}
Without using custom actions, I can easily test UserController with ScalaTest and Mockito (Fake request and mock xxxService)
My question is, how can I make fun of AuthAction and test UserController with ScalaTest and Mockito?
thanks
source
share