import org.scalatestplus.play.OneAppPerTest
import org.scalatestplus.play.PlaySpec

import play.api.test.FakeRequest
import play.api.test.Helpers._
import services.UserService
import models.User
import org.scalatest.concurrent.ScalaFutures

class UserControllerSpec extends PlaySpec with OneAppPerTest with ScalaFutures {
  "UserController" should {
    "render empty the users page" in {
      val users = route(app, FakeRequest(GET, "/")).get

      status(users) mustBe OK
      contentType(users) mustBe Some("text/html")
      contentAsString(users) must include ("Users")
    }
    
    "render the users page" in {
      val userService = app.injector.instanceOf[UserService]
      whenReady(userService.insert(User(None, "a@b.com", Some("Tom"), Some("Tommyknocker")))) { user =>
        user.id mustBe defined
      }
      
      val users = route(app, FakeRequest(GET, "/")).get
      status(users) mustBe OK
      contentType(users) mustBe Some("text/html")
      contentAsString(users) must include("a@b.com").and(include ("Tommyknocker"))
    }
  }
}