Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests #5

Open
datalek opened this issue Mar 30, 2015 · 0 comments
Open

Add tests #5

datalek opened this issue Mar 30, 2015 · 0 comments
Assignees
Milestone

Comments

@datalek
Copy link
Owner

datalek commented Mar 30, 2015

for example:

package controllers

import org.specs2.mutable._
import play.api.test._
import com.mohiva.play.silhouette.test._
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.authenticators.JWTAuthenticator
import models.users._
import models.authorizations._

class RestApplicationControllerSpec extends PlaySpecification {

  val baseInfo = BaseInfo(
    firstName = Some("Ale"),
    lastName = Some("Random"),
    fullName = None,
    gender = Some("M"))
  val user = User(
    id = java.util.UUID.randomUUID.toString,
    loginInfo = LoginInfo("facebook", "[email protected]"),
    socials = None,
    email = None,
    username = None,
    avatarUrl = None,
    info = baseInfo,
    roles = Set(SimpleUser))

  "The `user` method" should {
    "return status 200 if authenticator and identity was found" in new WithApplication {
      val identity = user
      implicit val fakeEnv = FakeEnvironment[User, JWTAuthenticator](Seq(identity.loginInfo -> identity))
      val request = FakeRequest().withAuthenticator(identity.loginInfo)

      val controller = new controllers.RestApplicationController {
        override implicit lazy val env = fakeEnv
      }
      val result = controller.onlyGodOrUser(request)

      status(result) must equalTo(OK)
      contentAsString(result) mustEqual "{\"result\":\"Oh yess GOD\"}"
    }
  }

}
@datalek datalek self-assigned this Mar 30, 2015
@datalek datalek added this to the 3.0 milestone May 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant