purescript-httpurple/test/Test/HTTPure/BodySpec.purs

52 lines
1.5 KiB
Haskell
Raw Normal View History

2017-10-26 21:19:30 +00:00
module Test.HTTPure.BodySpec where
import Prelude
import Effect.Class as EffectClass
import Node.Buffer as Buffer
import Node.Encoding as Encoding
import Test.Spec as Spec
import HTTPure.Body as Body
2017-10-26 21:19:30 +00:00
import Test.HTTPure.TestHelpers as TestHelpers
import Test.HTTPure.TestHelpers ((?=))
2017-10-26 21:19:30 +00:00
readSpec :: TestHelpers.Test
2017-07-18 05:25:14 +00:00
readSpec = Spec.describe "read" do
2017-09-26 06:08:07 +00:00
Spec.it "is the body of the Request" do
2017-10-26 21:19:30 +00:00
request <- TestHelpers.mockRequest "GET" "" "test" []
2017-07-18 05:25:14 +00:00
body <- Body.read request
body ?= "test"
2017-07-18 05:25:14 +00:00
sizeSpec :: TestHelpers.Test
sizeSpec = Spec.describe "size" do
Spec.it "returns the correct size for ASCII string body" do
size <- EffectClass.liftEffect $ Body.size $ Body.StringBody "ascii"
size ?= 5
Spec.it "returns the correct size for UTF-8 string body" do
size <- EffectClass.liftEffect $ Body.size $ Body.StringBody "\x2603" -- snowman
size ?= 3
Spec.it "returns the correct size for binary body" do
size <- EffectClass.liftEffect do
buf <- Buffer.fromString "foobar" Encoding.UTF8
Body.size $ Body.BinaryBody buf
size ?= 6
2017-10-26 21:19:30 +00:00
writeSpec :: TestHelpers.Test
writeSpec = Spec.describe "write" do
Spec.it "writes the string to the Response body" do
body <- EffectClass.liftEffect do
2017-10-26 21:19:30 +00:00
resp <- TestHelpers.mockResponse
Body.write resp $ Body.StringBody "test"
2017-10-26 21:19:30 +00:00
pure $ TestHelpers.getResponseBody resp
body ?= "test"
2017-10-26 21:19:30 +00:00
bodySpec :: TestHelpers.Test
bodySpec = Spec.describe "Body" do
2017-07-18 05:25:14 +00:00
readSpec
sizeSpec
writeSpec