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

56 lines
1.9 KiB
Haskell
Raw Normal View History

2017-10-26 21:19:30 +00:00
module Test.HTTPure.QuerySpec where
2017-09-26 06:08:07 +00:00
import Prelude
import Data.Tuple as Tuple
import Foreign.Object as Object
2017-09-26 06:08:07 +00:00
import Test.Spec as Spec
import HTTPure.Query as Query
2017-10-26 21:19:30 +00:00
import Test.HTTPure.TestHelpers as TestHelpers
import Test.HTTPure.TestHelpers ((?=))
2017-09-26 06:08:07 +00:00
2017-10-26 21:19:30 +00:00
readSpec :: TestHelpers.Test
2017-09-26 06:08:07 +00:00
readSpec = Spec.describe "read" do
Spec.describe "with no query string" do
Spec.it "is an empty Map" do
2017-10-26 21:19:30 +00:00
req <- TestHelpers.mockRequest "" "/test" "" []
Query.read req ?= Object.empty
Spec.describe "with an empty query string" do
Spec.it "is an empty Map" do
2017-10-26 21:19:30 +00:00
req <- TestHelpers.mockRequest "" "/test?" "" []
Query.read req ?= Object.empty
Spec.describe "with a query parameter in the query string" do
Spec.it "is a correct Map" do
2017-10-26 21:19:30 +00:00
req <- TestHelpers.mockRequest "" "/test?a=b" "" []
Query.read req ?= Object.singleton "a" "b"
Spec.describe "with empty fields in the query string" do
Spec.it "ignores the empty fields" do
2017-10-26 21:19:30 +00:00
req <- TestHelpers.mockRequest "" "/test?&&a=b&&" "" []
Query.read req ?= Object.singleton "a" "b"
Spec.describe "with duplicated params" do
Spec.it "takes the last param value" do
2017-10-26 21:19:30 +00:00
req <- TestHelpers.mockRequest "" "/test?a=b&a=c" "" []
Query.read req ?= Object.singleton "a" "c"
Spec.describe "with empty params" do
Spec.it "uses 'true' as the value" do
2017-10-26 21:19:30 +00:00
req <- TestHelpers.mockRequest "" "/test?a" "" []
Query.read req ?= Object.singleton "a" "true"
Spec.describe "with complex params" do
Spec.it "is the correct Map" do
2017-10-26 21:19:30 +00:00
req <- TestHelpers.mockRequest "" "/test?&&a&b=c&b=d&&&e=f&g=&" "" []
Query.read req ?= expectedComplexResult
where
expectedComplexResult =
Object.fromFoldable
[ Tuple.Tuple "a" "true"
, Tuple.Tuple "b" "d"
, Tuple.Tuple "e" "f"
, Tuple.Tuple "g" "true"
]
2017-09-26 06:08:07 +00:00
2017-10-26 21:19:30 +00:00
querySpec :: TestHelpers.Test
2017-09-26 06:08:07 +00:00
querySpec = Spec.describe "Query" do
readSpec