diff options
author | adamw <adam@warski.org> | 2017-07-15 14:09:40 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-07-15 14:09:40 +0200 |
commit | d7177124da41e1893efb79b76f5d40c798356a83 (patch) | |
tree | d047208ce116aff7d90a4cfa744e75c91f62722e /core/src/test/scala/com/softwaremill | |
parent | fd127928c0ba3eb9386a7ca9c3106c349d5baa71 (diff) | |
download | sttp-d7177124da41e1893efb79b76f5d40c798356a83.tar.gz sttp-d7177124da41e1893efb79b76f5d40c798356a83.tar.bz2 sttp-d7177124da41e1893efb79b76f5d40c798356a83.zip |
Setting cookies
Diffstat (limited to 'core/src/test/scala/com/softwaremill')
-rw-r--r-- | core/src/test/scala/com/softwaremill/sttp/RequestTests.scala | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/core/src/test/scala/com/softwaremill/sttp/RequestTests.scala b/core/src/test/scala/com/softwaremill/sttp/RequestTests.scala new file mode 100644 index 0000000..e6db3d7 --- /dev/null +++ b/core/src/test/scala/com/softwaremill/sttp/RequestTests.scala @@ -0,0 +1,43 @@ +package com.softwaremill.sttp + +import org.scalatest.{FlatSpec, Matchers} + +class RequestTests extends FlatSpec with Matchers { + "request cookies" should "be set from a name-value pair" in { + sttp + .cookie("k", "v") + .headers + .find(_._1 == CookieHeader) + .map(_._2) should be(Some("k=v")) + } + + it should "be set from multiple name-value pairs" in { + sttp + .cookies("k1" -> "v1", "k2" -> "v2") + .headers + .find(_._1 == CookieHeader) + .map(_._2) should be(Some("k1=v1; k2=v2")) + } + + it should "add multiple headers if invoked multiple times" in { + sttp + .cookie("k1", "v1") + .cookie("k2" -> "v2") + .headers + .filter(_._1 == CookieHeader) + .map(_._2) + .toSet should be(Set("k1=v1", "k2=v2")) + } + + it should "set cookies from a response" in { + val response = + Response((), + 0, + List((SetCookieHeader, "k1=v1"), (SetCookieHeader, "k2=v2"))) + sttp + .cookies(response) + .headers + .find(_._1 == CookieHeader) + .map(_._2) should be(Some("k1=v1; k2=v2")) + } +} |