Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
963
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. diff --git a/build.sbt b/build.sbt
  2. index 8fa493a9..cde2dde3 100644
  3. --- a/build.sbt
  4. +++ b/build.sbt
  5. @@ -44,7 +44,9 @@ libraryDependencies ++= Seq(
  6. "joda-time" % "joda-time" % "2.4",
  7. "org.joda" % "joda-convert" % "1.6",
  8. "com.github.tototoshi" %% "slick-joda-mapper" % "1.2.0",
  9. - "org.scalaz" %% "scalaz-core" % "7.2.10"
  10. + "org.scalaz" %% "scalaz-core" % "7.0.6",
  11. + "org.scalaz" % "scalaz-concurrent_2.11" % "7.0.6",
  12. + "org.specs2" % "specs2-junit_2.11" % "3.6.6"
  13. )
  14.  
  15. javaOptions in Test += "-Dconfig.file=conf/test.conf"
  16. \ No newline at end of file
  17. diff --git a/conf/test.conf b/conf/test.conf
  18. index 18a6b670..b3ce5046 100644
  19. --- a/conf/test.conf
  20. +++ b/conf/test.conf
  21. @@ -3,4 +3,6 @@ include "staging.conf"
  22. db.default.driver = com.mysql.jdbc.Driver
  23. db.default.url="jdbc:mysql://localhost:3307/marketmuse"
  24. db.default.user = marketmuse
  25. -db.default.password = ycombinator14
  26. \ No newline at end of file
  27. +db.default.password = ycombinator14
  28. +
  29. +smtp.mock = true
  30. \ No newline at end of file
  31. diff --git a/test/ApplicationSpec.scala b/test/ApplicationSpec.scala
  32. index ba256055..1aec913a 100644
  33. --- a/test/ApplicationSpec.scala
  34. +++ b/test/ApplicationSpec.scala
  35. @@ -5,14 +5,16 @@ import play.api.libs.json.Json
  36. import play.api.test._
  37. import play.api.test.Helpers._
  38. import play.api.Logger._
  39. +import play.api.mvc.Result
  40.  
  41. +import scala.concurrent.Future
  42. import scala.sys.process._
  43.  
  44. /**
  45. - * Add your spec here.
  46. - * You can mock out a whole application including requests, plugins etc.
  47. - * For more information, consult the wiki.
  48. - */
  49. + * Add your spec here.
  50. + * You can mock out a whole application including requests, plugins etc.
  51. + * For more information, consult the wiki.
  52. + */
  53. @RunWith(classOf[JUnitRunner])
  54. class ApplicationSpec extends Specification with BeforeAfter {
  55.  
  56. @@ -67,7 +69,7 @@ class ApplicationSpec extends Specification with BeforeAfter {
  57. )).get
  58.  
  59. status(apiSave) mustEqual OK
  60. - //controllers.Sites.apiSave(publicToken, id : Int)
  61. + //controllers.Sites.apiSave(publicToken, id : Int)
  62.  
  63. val crawl = route(FakeRequest(GET, s"/auth/web/crawl?url=blog.hubspot.com&publicToken=$publicToken")).get
  64.  
  65. @@ -75,12 +77,46 @@ class ApplicationSpec extends Specification with BeforeAfter {
  66.  
  67. }
  68.  
  69. -// "render the index page" in new WithApplication{
  70. -// val home = route(FakeRequest(GET, "/")).get
  71. -//
  72. -// status(home) must equalTo(OK)
  73. -// contentType(home) must beSome.which(_ == "text/html")
  74. -// contentAsString(home) must contain ("Your new application is ready.")
  75. -// }
  76. + "limit API calls per one user" in new WithApplication {
  77. + val register = route(FakeRequest(POST, "/auth/users/register").withJsonBody(
  78. + Json.obj(
  79. + "email" -> "test@test.com",
  80. + "name" -> "test_user",
  81. + "fullName" -> "Test User",
  82. + "company" -> "Test Company",
  83. + "password" -> "Test Password",
  84. + "agree" -> true
  85. + ))).get
  86. +
  87. + status(register) mustEqual OK
  88. +
  89. + val login = route(FakeRequest(POST, "/auth/users/login").withJsonBody(
  90. + Json.obj(
  91. + "email" -> "test@test.com",
  92. + "password" -> "Test Password",
  93. + "remember" -> true
  94. + ))).get
  95. +
  96. + status(login) mustEqual OK
  97. +
  98. + val publicToken = (contentAsJson(login) \ "publicToken").as[String]
  99. +
  100. + def apiRequest(): Future[Result] =
  101. + route(FakeRequest(POST, s"/auth/users/publicToken/$publicToken?url=test")).get
  102. +
  103. + for(_ <- 1 to 1000) {
  104. + status(apiRequest()) mustEqual OK
  105. + }
  106. +
  107. + status(apiRequest()) mustEqual TOO_MANY_REQUEST
  108. + }
  109. +
  110. + // "render the index page" in new WithApplication{
  111. + // val home = route(FakeRequest(GET, "/")).get
  112. + //
  113. + // status(home) must equalTo(OK)
  114. + // contentType(home) must beSome.which(_ == "text/html")
  115. + // contentAsString(home) must contain ("Your new application is ready.")
  116. + // }
  117. }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement