Skip to content

Instantly share code, notes, and snippets.

@EnverOsmanov
Created March 31, 2017 16:46
Show Gist options
  • Save EnverOsmanov/e1f7eb17f7208f002e09b07494fe4429 to your computer and use it in GitHub Desktop.
Save EnverOsmanov/e1f7eb17f7208f002e09b07494fe4429 to your computer and use it in GitHub Desktop.
Test for PlayFramework developers guys
import org.junit.runner._
import org.specs2.mutable._
import org.specs2.runner._
import play.api.mvc.{Cookie, DiscardingCookie, Results}
import play.api.test._
/**
* Add your spec here.
* You can mock out a whole application including requests, plugins etc.
* For more information, consult the wiki.
*/
@RunWith(classOf[JUnitRunner])
class ApplicationSpec extends Specification {
val initCookie = Cookie(
name = "cName",
value = "cValue",
maxAge = Some(43200),
path = "/",
domain = None,
secure = true,
httpOnly = true,
sameSite = None
)
val discardedCookie = DiscardingCookie(initCookie.name)
"Application" should {
"discard old cookie" in new WithApplication{
val initResult = Results.Ok.withCookies(initCookie)
val result = initResult.discardingCookies(discardedCookie)
//Cookie name should be unique
result.newCookies.count(_.name == initCookie.name) must be equalTo 1
//Cookies count should not change
result.newCookies.length must be equalTo initResult.newCookies.length
//Cookies should have same name
result.newCookies.count(_.name == initCookie.name) must be equalTo initResult.newCookies.count(_.name == initCookie.name)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment