purescript-httpurple/Test/HTTPure/ResponseSpec.purs
Connor Prussin 44df22e331 #22 add support for writing headers and status (#32)
* Add support for writing status code

* Add support for writing headers

* Code cleanup
2017-07-17 16:42:13 -07:00

39 lines
1.3 KiB
Haskell

module HTTPure.ResponseSpec where
import Prelude (bind, discard, pure, ($))
import Control.Monad.Eff.Class as EffClass
import Data.StrMap as StrMap
import Test.Spec as Spec
import Test.Spec.Assertions as Assertions
import HTTPure.Response as Response
import HTTPure.SpecHelpers as SpecHelpers
sendSpec :: SpecHelpers.Test
sendSpec = Spec.describe "send" do
Spec.describe "with an OK" do
Spec.it "writes the headers" do
header <- EffClass.liftEff do
resp <- SpecHelpers.mockResponse
Response.send resp $ Response.OK (StrMap.singleton "X-Test" "test") ""
pure $ SpecHelpers.getResponseHeader "X-Test" resp
header `Assertions.shouldEqual` "test"
Spec.it "writes the status" do
status <- EffClass.liftEff do
resp <- SpecHelpers.mockResponse
Response.send resp $ Response.OK StrMap.empty ""
pure $ SpecHelpers.getResponseStatus resp
status `Assertions.shouldEqual` 200
Spec.it "writes the body" do
body <- EffClass.liftEff do
resp <- SpecHelpers.mockResponse
Response.send resp $ Response.OK StrMap.empty "test"
pure $ SpecHelpers.getResponseBody resp
body `Assertions.shouldEqual` "test"
responseSpec :: SpecHelpers.Test
responseSpec = Spec.describe "Response" do
sendSpec