Skip to content
This repository has been archived by the owner on Oct 24, 2022. It is now read-only.

Commit

Permalink
starting the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JPrevost committed Mar 31, 2015
1 parent 036f62b commit c202a31
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/views/index.scala.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@(message: String, redirectUrl: String)

@layout.main("Welcome to Play") {
@layout.main("Login to SCOAP3 - TopicHub") {
<h2>Not Yet Authenticated</h2>
<a href="@redirectUrl"><em><b>Log in with MITID!</b></em></a>
<a id="openid" href="@redirectUrl"><em><b>Log in with MITID!</b></em></a>
}
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ libraryDependencies ++= Seq(
"org.scalesxml" %% "scales-xml" % "0.6.0-M3",
"org.scalesxml" %% "scales-jaxen" % "0.6.0-M3" intransitive(),
"jaxen" % "jaxen" % "1.1.6" intransitive(),
"org.postgresql" % "postgresql" % "9.4-1200-jdbc41"
"org.postgresql" % "postgresql" % "9.4-1200-jdbc41",
"org.mockito" % "mockito-core" % "1.10.19" % "test"
)
22 changes: 22 additions & 0 deletions test/ApplicationSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.junit.runner._

import play.api.test._
import play.api.test.Helpers._
import play.api.libs.json._

/**
* Add your spec here.
Expand All @@ -26,5 +27,26 @@ class ApplicationSpec extends Specification {
contentType(home) must beSome.which(_ == "text/html")
contentAsString(home) must contain ("Welcome to SCOAP")
}

"display a login screen" in new WithBrowser {
val action = route(FakeRequest(GET, "/login")).get
status(action) must equalTo(OK)
contentType(action) must beSome.which(_ == "text/html")
contentAsString(action) must contain ("Log in with MITID")
}

// "parse returned user json" in new WithBrowser {
// val action = route(
// FakeRequest(GET, "/_oauth-success")
// .withHeaders(CONTENT_TYPE -> "application/json")
// .withSession(("oauth-token", "asdffdsa"))
// .withBody("""
// {"sub":"asdffdsa","name":"Some M User","preferred_username":"suser","given_name":"Some","family_name":"User","middle_name":"M","email":"suser@example.edu","email_verified":true}
// """)
// ).get
// status(action) must equalTo(OK)
// contentType(action) must beSome.which(_ == "application/json")
// contentAsString(action) must contain ("Log in with MITID")
// }
}
}
28 changes: 28 additions & 0 deletions test/AuthenticationSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import org.specs2.mutable._
import org.specs2.runner._
import org.junit.runner._
import org.specs2.mock._

import play.api.test._
import play.api.test.Helpers._
import org.fest.assertions.Assertions.assertThat

/**
* add your integration spec here.
* An integration test will fire up a whole play application in a real (or headless) browser
*/
class AuthenticationSpec extends Specification with Mockito {
"Application" should {
"display a login screen" in new WithBrowser {
browser.goTo("http://localhost:" + port + "/login")
browser.pageSource must contain("Log in with MITID")
assertThat(browser.title()).isEqualTo("Login to SCOAP3 - TopicHub")
}

"redirect when login is clicked" in new WithBrowser {
browser.goTo("http://localhost:" + port + "/login")
browser.$("#openid").click();
assertThat(browser.title()).isEqualTo("MIT OpenID Connect Pilot - Log In")
}
}
}

0 comments on commit c202a31

Please sign in to comment.