2017-05-25 19:12:29 +00:00
|
|
|
module HTTPure.ResponseSpec where
|
|
|
|
|
2017-07-17 23:42:13 +00:00
|
|
|
import Prelude (bind, discard, pure, ($))
|
2017-05-25 19:12:29 +00:00
|
|
|
|
2017-07-10 10:17:13 +00:00
|
|
|
import Control.Monad.Eff.Class as EffClass
|
2017-07-14 06:28:57 +00:00
|
|
|
import Data.StrMap as StrMap
|
2017-07-10 10:17:13 +00:00
|
|
|
import Test.Spec as Spec
|
|
|
|
import Test.Spec.Assertions as Assertions
|
2017-05-25 19:12:29 +00:00
|
|
|
|
2017-07-10 10:17:13 +00:00
|
|
|
import HTTPure.Response as Response
|
2017-05-25 19:12:29 +00:00
|
|
|
|
2017-07-14 06:28:57 +00:00
|
|
|
import HTTPure.SpecHelpers as SpecHelpers
|
|
|
|
|
|
|
|
sendSpec :: SpecHelpers.Test
|
|
|
|
sendSpec = Spec.describe "send" do
|
|
|
|
Spec.describe "with an OK" do
|
2017-07-17 23:42:13 +00:00
|
|
|
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
|
2017-07-14 06:28:57 +00:00
|
|
|
Spec.it "writes the body" do
|
|
|
|
body <- EffClass.liftEff do
|
2017-07-17 23:42:13 +00:00
|
|
|
resp <- SpecHelpers.mockResponse
|
2017-07-14 06:28:57 +00:00
|
|
|
Response.send resp $ Response.OK StrMap.empty "test"
|
2017-07-17 23:42:13 +00:00
|
|
|
pure $ SpecHelpers.getResponseBody resp
|
2017-07-14 06:28:57 +00:00
|
|
|
body `Assertions.shouldEqual` "test"
|
2017-07-10 10:17:13 +00:00
|
|
|
|
|
|
|
responseSpec :: SpecHelpers.Test
|
2017-07-14 06:28:57 +00:00
|
|
|
responseSpec = Spec.describe "Response" do
|
|
|
|
sendSpec
|