scala - Testing a page that is loaded after a redirect -


i've got test case supposed verify that, after post call, user redirected correct page.

"redirect page" in {   running(fakeapplication()) {     val some(result) = route(fakerequest(post, "/product/add/something")       .withformurlencodedbody(        "id" -> "666",       )       .withsession("email" -> "user")     )     status(result) must equalto(see_other)     // contentasstring(result) @ point blank 

this verifies redirect url given. how unit test go redirected url can verify content?

you can test url redirected with:

    redirectlocation(result) must besome.which(_ == "/product/666") 

if want check content, follow redirect:

    val nexturl = redirectlocation(result) match {       case some(s: string) => s       case _ => ""     }     nexturl must contain("/product/666")      val newresult = route(fakerequest(get, nexturl)).get      status(newresult) must equalto(ok)     contenttype(newresult) must besome.which(_ == "text/html")     contentasstring(newresult) must contain("something") 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -