purescript-httpurple/test/HTTPure/ResponseSpec.purs

99 lines
3.0 KiB
Haskell
Raw Normal View History

module HTTPure.ResponseSpec where
import Prelude
2017-07-10 10:17:13 +00:00
import Control.Monad.Eff.Class as EffClass
import Test.Spec as Spec
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
import HTTPure.SpecHelpers as SpecHelpers
import HTTPure.SpecHelpers ((?=))
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.header "Test" "test"
2017-09-27 19:34:00 +00:00
mockResponse = { status: 123, headers: mockHeaders, body: "test" }
2017-09-26 06:08:07 +00:00
responseFunctionSpec :: SpecHelpers.Test
responseFunctionSpec = Spec.describe "response" do
Spec.it "has the right status" do
resp <- Response.response 123 "test"
resp.status ?= 123
Spec.it "has empty headers" do
resp <- Response.response 123 "test"
resp.headers ?= Headers.empty
Spec.it "has the right body" do
resp <- Response.response 123 "test"
resp.body ?= "test"
response'Spec :: SpecHelpers.Test
response'Spec = Spec.describe "response'" do
2017-09-26 06:08:07 +00:00
Spec.it "has the right status" do
resp <- mockResponse
2017-09-27 19:34:00 +00:00
resp.status ?= 123
2017-09-26 06:08:07 +00:00
Spec.it "has the right headers" do
resp <- mockResponse
2017-09-27 19:34:00 +00:00
resp.headers ?= mockHeaders
2017-09-26 06:08:07 +00:00
Spec.it "has the right body" do
resp <- mockResponse
2017-09-27 19:34:00 +00:00
resp.body ?= "test"
2017-09-26 06:08:07 +00:00
where
mockHeaders = Headers.header "Test" "test"
mockResponse = Response.response' 123 mockHeaders "test"
2017-09-26 06:08:07 +00:00
emptyResponseSpec :: SpecHelpers.Test
emptyResponseSpec = Spec.describe "emptyResponse" do
Spec.it "has the right status" do
resp <- Response.emptyResponse 123
resp.status ?= 123
Spec.it "has empty headers" do
resp <- Response.emptyResponse 123
resp.headers ?= Headers.empty
Spec.it "has an empty body" do
resp <- Response.emptyResponse 123
resp.body ?= ""
emptyResponse'Spec :: SpecHelpers.Test
emptyResponse'Spec = Spec.describe "emptyResponse'" do
2017-09-26 06:08:07 +00:00
Spec.it "has the right status" do
resp <- mockResponse
2017-09-27 19:34:00 +00:00
resp.status ?= 123
2017-09-26 06:08:07 +00:00
Spec.it "has the right headers" do
resp <- mockResponse
2017-09-27 19:34:00 +00:00
resp.headers ?= mockHeaders
2017-09-26 06:08:07 +00:00
Spec.it "has an empty body" do
resp <- mockResponse
2017-09-27 19:34:00 +00:00
resp.body ?= ""
2017-09-26 06:08:07 +00:00
where
mockHeaders = Headers.header "Test" "test"
mockResponse = Response.emptyResponse' 123 mockHeaders
2017-07-10 10:17:13 +00:00
responseSpec :: SpecHelpers.Test
responseSpec = Spec.describe "Response" do
sendSpec
2017-09-26 06:08:07 +00:00
responseFunctionSpec
response'Spec
emptyResponseSpec
emptyResponse'Spec