jeudi 4 janvier 2018

Testing routes of Controllers with parameters

I have a controller that receives 3 parameters and I want to create a test to its routes. It has to return a Json.

class RackController(cc: ControllerComponents, rackRepository: RackRepository, gpuRepository: GpuRepository)
  extends AbstractController(cc) with I18nSupport {

How do I create a Spec class to test the routes od this controller and pass the parameters rackRepository and gpuRepository?

class RackControllerSpec extends PlaySpec with GuiceOneAppPerTest with Injecting {

  "RackController GET" should {
    "render the rack page from a new instance of controller" in {
      // val controller = new RackController(stubControllerComponents(), rack, gpu)
      val home = controller.all().apply(FakeRequest(GET, "/api/all"))

      status(home) mustBe OK
      contentType(home) mustBe Some("application/json")
    }
  }
}

Thanks, Felipe

Aucun commentaire:

Enregistrer un commentaire