c208dffb7b
* v0.8.1 * Add the HTTP version to `Request` The `node-http` `Request` has the HTTP version on it. We can make it available in our `Request` for consumers. We went the naive approach first and typed it as a string. There is some structure to the version, so we could attempt to parse it. It's unclear what we would do if parsing failed though. Maybe we want something like: ```PureScript data Version = Known { major :: Int, minor :: Int } | Unknown String ``` That would allow us to parse the known format, and fallback to accepting anything else. It's definitely something to discuss anyway. * Make HTTP version its own data type There are only a handful of HTTP versions that are commonly used. We can talk about those explicitly and fallback to any arbitrary version. The changes here try to follow the patterns elsewhere in the code base. Hopefully, it's not too far off.
41 lines
1.4 KiB
Haskell
41 lines
1.4 KiB
Haskell
module Test.HTTPure.PathSpec where
|
|
|
|
import Prelude
|
|
|
|
import Test.Spec as Spec
|
|
|
|
import HTTPure.Path as Path
|
|
|
|
import Test.HTTPure.TestHelpers as TestHelpers
|
|
import Test.HTTPure.TestHelpers ((?=))
|
|
|
|
readSpec :: TestHelpers.Test
|
|
readSpec = Spec.describe "read" do
|
|
Spec.describe "with a query string" do
|
|
Spec.it "is just the path" do
|
|
request <- TestHelpers.mockRequest "" "GET" "test/path?blabla" "" []
|
|
Path.read request ?= [ "test", "path" ]
|
|
Spec.describe "with no query string" do
|
|
Spec.it "is the path" do
|
|
request <- TestHelpers.mockRequest "" "GET" "test/path" "" []
|
|
Path.read request ?= [ "test", "path" ]
|
|
Spec.describe "with no segments" do
|
|
Spec.it "is an empty array" do
|
|
request <- TestHelpers.mockRequest "" "GET" "" "" []
|
|
Path.read request ?= []
|
|
Spec.describe "with empty segments" do
|
|
Spec.it "strips the empty segments" do
|
|
request <- TestHelpers.mockRequest "" "GET" "//test//path///?query" "" []
|
|
Path.read request ?= [ "test", "path" ]
|
|
Spec.describe "with percent encoded segments" do
|
|
Spec.it "decodes percent encoding" do
|
|
request <- TestHelpers.mockRequest "" "GET" "/test%20path/%2Fthis" "" []
|
|
Path.read request ?= [ "test path", "/this" ]
|
|
Spec.it "does not decode a plus sign" do
|
|
request <- TestHelpers.mockRequest "" "GET" "/test+path/this" "" []
|
|
Path.read request ?= [ "test+path", "this" ]
|
|
|
|
pathSpec :: TestHelpers.Test
|
|
pathSpec = Spec.describe "Path" do
|
|
readSpec
|