2017-05-25 19:12:29 +00:00
|
|
|
module HTTPure.ResponseSpec where
|
|
|
|
|
2017-07-18 05:31:46 +00:00
|
|
|
import Prelude
|
2017-05-25 19:12:29 +00:00
|
|
|
|
2017-07-10 10:17:13 +00:00
|
|
|
import Control.Monad.Eff.Class as EffClass
|
2017-09-26 06:08:07 +00:00
|
|
|
import Data.Tuple as Tuple
|
|
|
|
|
2017-07-10 10:17:13 +00:00
|
|
|
import Test.Spec as Spec
|
2017-05-25 19:12:29 +00:00
|
|
|
|
2017-09-26 06:08:07 +00:00
|
|
|
import HTTPure.Headers as Headers
|
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
|
2017-07-19 05:36:56 +00:00
|
|
|
import HTTPure.SpecHelpers ((?=))
|
2017-07-14 06:28:57 +00:00
|
|
|
|
|
|
|
sendSpec :: SpecHelpers.Test
|
|
|
|
sendSpec = Spec.describe "send" do
|
2017-07-19 18:59:55 +00:00
|
|
|
Spec.it "writes the headers" do
|
|
|
|
header <- EffClass.liftEff do
|
2017-09-26 06:08:07 +00:00
|
|
|
httpResponse <- SpecHelpers.mockResponse
|
|
|
|
Response.send httpResponse mockResponse
|
|
|
|
pure $ SpecHelpers.getResponseHeader "Test" httpResponse
|
2017-07-19 18:59:55 +00:00
|
|
|
header ?= "test"
|
|
|
|
Spec.it "writes the status" do
|
|
|
|
status <- EffClass.liftEff do
|
2017-09-26 06:08:07 +00:00
|
|
|
httpResponse <- SpecHelpers.mockResponse
|
|
|
|
Response.send httpResponse mockResponse
|
|
|
|
pure $ SpecHelpers.getResponseStatus httpResponse
|
|
|
|
status ?= 123
|
2017-07-19 18:59:55 +00:00
|
|
|
Spec.it "writes the body" do
|
|
|
|
body <- EffClass.liftEff do
|
2017-09-26 06:08:07 +00:00
|
|
|
httpResponse <- SpecHelpers.mockResponse
|
|
|
|
Response.send httpResponse mockResponse
|
|
|
|
pure $ SpecHelpers.getResponseBody httpResponse
|
2017-07-19 18:59:55 +00:00
|
|
|
body ?= "test"
|
2017-09-26 06:08:07 +00:00
|
|
|
where
|
|
|
|
mockHeaders = Headers.headers [ Tuple.Tuple "Test" "test" ]
|
|
|
|
mockResponse = Response.Response 123 mockHeaders "test"
|
|
|
|
|
|
|
|
responseFunctionSpec :: SpecHelpers.Test
|
|
|
|
responseFunctionSpec = Spec.describe "response" do
|
|
|
|
Spec.it "has the right status" do
|
|
|
|
resp <- mockResponse
|
|
|
|
case resp of (Response.Response status _ _) -> status ?= 123
|
|
|
|
Spec.it "has the right headers" do
|
|
|
|
resp <- mockResponse
|
|
|
|
case resp of (Response.Response _ headers _) -> headers ?= mockHeaders
|
|
|
|
Spec.it "has the right body" do
|
|
|
|
resp <- mockResponse
|
|
|
|
case resp of (Response.Response _ _ body) -> body ?= "test"
|
|
|
|
where
|
|
|
|
mockHeaders = Headers.headers [ Tuple.Tuple "Test" "test" ]
|
2017-09-27 13:55:36 +00:00
|
|
|
mockResponse = Response.response 123 mockHeaders "test"
|
2017-09-26 06:08:07 +00:00
|
|
|
|
|
|
|
response'Spec :: SpecHelpers.Test
|
|
|
|
response'Spec = Spec.describe "response'" do
|
|
|
|
Spec.it "has the right status" do
|
|
|
|
resp <- mockResponse
|
|
|
|
case resp of (Response.Response status _ _) -> status ?= 123
|
|
|
|
Spec.it "has the right headers" do
|
|
|
|
resp <- mockResponse
|
|
|
|
case resp of (Response.Response _ headers _) -> headers ?= mockHeaders
|
|
|
|
Spec.it "has an empty body" do
|
|
|
|
resp <- mockResponse
|
|
|
|
case resp of (Response.Response _ _ body) -> body ?= ""
|
|
|
|
where
|
|
|
|
mockHeaders = Headers.headers [ Tuple.Tuple "Test" "test" ]
|
2017-09-27 13:55:36 +00:00
|
|
|
mockResponse = Response.response' 123 mockHeaders
|
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
|
2017-09-26 06:08:07 +00:00
|
|
|
responseFunctionSpec
|
|
|
|
response'Spec
|