Мое приложение использует инъекцию времени компиляции.Загрузчик определяется следующим образом (фрагмент кода):
class AppLoader extends ApplicationLoader { ...}
class AppComponents (context: Context) extends BuiltInComponentsFromContext(context) {
...
//within this I have created instances of my controller and created a route
lazy val userController = new UserController(userRepository, controllerComponents, silhouetteJWTProvider)
lazy val router = new Routes(httpErrorHandler, homeController,userWSRoutes, countController,asyncController, assets)
}
Класс UserController
имеет signupUser
Action
@Singleton
class UserController @Inject()(
userRepo: UsersRepository,cc: ControllerComponents, silhouette: Silhouette[JWTEnv])(implicit exec: ExecutionContext) extends AbstractController(cc){
...
def signupUser = silhouette.UserAwareAction.async{ implicit request => {
...
}
}
Я хочу проверить signupUser
Action
но я не знаю, как это сделать.Я создал следующий класс спецификации, но я застрял в том, как написать спецификацию и проверить ее.
class UserControllerSpec extends PlaySpec {
"User signup request with non-JSON body" must {
"return 400 (Bad Request) and the validation text 'Incorrect body type. Body type must be JSON'" in {
//I want to create instance of a `FakeRequest` annd pass it to UserController.signupUser. I should test a Future[Result] which I should then assert.
//How do I get instance of userController which I created in my Apploader? I don't want to repeat/duplicate the code of AppLoader here.
}
}
}