2017-05-25 19:12:29 +00:00
|
|
|
module HTTPure.RequestSpec where
|
|
|
|
|
2017-07-18 01:51:43 +00:00
|
|
|
import Prelude (discard, pure, show, unit, (<>), ($), (<<<))
|
2017-05-25 19:12:29 +00:00
|
|
|
|
2017-07-14 06:28:57 +00:00
|
|
|
import Data.StrMap as StrMap
|
2017-07-10 10:17:13 +00:00
|
|
|
import Test.Spec as Spec
|
|
|
|
import Test.Spec.Assertions as Assertions
|
2017-05-25 19:12:29 +00:00
|
|
|
|
2017-07-18 01:51:43 +00:00
|
|
|
import HTTPure.Headers as Headers
|
2017-07-14 06:28:57 +00:00
|
|
|
import HTTPure.Request as Request
|
|
|
|
|
2017-07-10 10:17:13 +00:00
|
|
|
import HTTPure.SpecHelpers as SpecHelpers
|
2017-05-25 19:12:29 +00:00
|
|
|
|
2017-07-14 06:28:57 +00:00
|
|
|
showSpec :: SpecHelpers.Test
|
|
|
|
showSpec = Spec.describe "show" do
|
|
|
|
Spec.describe "with a POST" do
|
|
|
|
Spec.it "is the method and the path" do
|
|
|
|
show (Request.Post none "test" "") `Assertions.shouldEqual` "POST: test"
|
|
|
|
Spec.describe "with a PUT" do
|
|
|
|
Spec.it "is the method and the path" do
|
|
|
|
show (Request.Put none "test" "") `Assertions.shouldEqual` "PUT: test"
|
|
|
|
Spec.describe "with a DELETE" do
|
|
|
|
Spec.it "is the method and the path" do
|
|
|
|
show (Request.Delete none "test") `Assertions.shouldEqual` "DELETE: test"
|
|
|
|
Spec.describe "with a GET" do
|
|
|
|
Spec.it "is the method and the path" do
|
|
|
|
show (Request.Get none "test") `Assertions.shouldEqual` "GET: test"
|
|
|
|
where
|
|
|
|
none = StrMap.empty
|
|
|
|
|
|
|
|
fromHTTPRequestSpec :: SpecHelpers.Test
|
|
|
|
fromHTTPRequestSpec = Spec.describe "fromHTTPRequest" do
|
|
|
|
|
|
|
|
Spec.describe "with a POST" do
|
|
|
|
Spec.it "is a Post" do
|
2017-07-18 01:51:43 +00:00
|
|
|
case mock "POST" "" StrMap.empty of
|
2017-07-14 06:28:57 +00:00
|
|
|
(Request.Post _ _ _) -> pure unit
|
|
|
|
a -> Assertions.fail $ "expected a Post, got " <> show a
|
2017-07-18 01:51:43 +00:00
|
|
|
Spec.it "has the correct headers" do
|
|
|
|
case mock "POST" "" mockHeader of
|
|
|
|
(Request.Post headers _ _) ->
|
|
|
|
Headers.lookup headers "X-Test" `Assertions.shouldEqual` "test"
|
|
|
|
a -> Assertions.fail $ "expected a Post, got " <> show a
|
2017-07-14 06:28:57 +00:00
|
|
|
Spec.it "has the correct path" do
|
2017-07-18 01:51:43 +00:00
|
|
|
case mock "POST" "test" StrMap.empty of
|
2017-07-14 06:28:57 +00:00
|
|
|
(Request.Post _ "test" _) -> pure unit
|
|
|
|
a -> Assertions.fail $ "expected the path 'test', got " <> show a
|
|
|
|
Spec.pending "has the correct body"
|
|
|
|
|
|
|
|
Spec.describe "with a PUT" do
|
|
|
|
Spec.it "is a Put" do
|
2017-07-18 01:51:43 +00:00
|
|
|
case mock "PUT" "" StrMap.empty of
|
2017-07-14 06:28:57 +00:00
|
|
|
(Request.Put _ _ _) -> pure unit
|
|
|
|
a -> Assertions.fail $ "expected a Put, got " <> show a
|
2017-07-18 01:51:43 +00:00
|
|
|
Spec.it "has the correct headers" do
|
|
|
|
case mock "PUT" "" mockHeader of
|
|
|
|
(Request.Put headers _ _) ->
|
|
|
|
Headers.lookup headers "X-Test" `Assertions.shouldEqual` "test"
|
|
|
|
a -> Assertions.fail $ "expected a Put, got " <> show a
|
2017-07-14 06:28:57 +00:00
|
|
|
Spec.it "has the correct path" do
|
2017-07-18 01:51:43 +00:00
|
|
|
case mock "PUT" "test" StrMap.empty of
|
2017-07-14 06:28:57 +00:00
|
|
|
(Request.Put _ "test" _) -> pure unit
|
|
|
|
a -> Assertions.fail $ "expected the path 'test', got " <> show a
|
|
|
|
Spec.pending "has the correct body"
|
|
|
|
|
|
|
|
Spec.describe "with a DELETE" do
|
|
|
|
Spec.it "is a Delete" do
|
2017-07-18 01:51:43 +00:00
|
|
|
case mock "DELETE" "" StrMap.empty of
|
2017-07-14 06:28:57 +00:00
|
|
|
(Request.Delete _ _) -> pure unit
|
|
|
|
a -> Assertions.fail $ "expected a Delete, got " <> show a
|
2017-07-18 01:51:43 +00:00
|
|
|
Spec.it "has the correct headers" do
|
|
|
|
case mock "DELETE" "" mockHeader of
|
|
|
|
(Request.Delete headers _) ->
|
|
|
|
Headers.lookup headers "X-Test" `Assertions.shouldEqual` "test"
|
|
|
|
a -> Assertions.fail $ "expected a Delete, got " <> show a
|
2017-07-14 06:28:57 +00:00
|
|
|
Spec.it "has the correct path" do
|
2017-07-18 01:51:43 +00:00
|
|
|
case mock "DELETE" "test" StrMap.empty of
|
2017-07-14 06:28:57 +00:00
|
|
|
(Request.Delete _ "test") -> pure unit
|
|
|
|
a -> Assertions.fail $ "expected the path 'test', got " <> show a
|
2017-07-10 10:17:13 +00:00
|
|
|
|
2017-07-14 06:28:57 +00:00
|
|
|
Spec.describe "with a GET" do
|
|
|
|
Spec.it "is a Get" do
|
2017-07-18 01:51:43 +00:00
|
|
|
case mock "GET" "" StrMap.empty of
|
2017-07-14 06:28:57 +00:00
|
|
|
(Request.Get _ _) -> pure unit
|
|
|
|
a -> Assertions.fail $ "expected a Get, got " <> show a
|
2017-07-18 01:51:43 +00:00
|
|
|
Spec.it "has the correct headers" do
|
|
|
|
case mock "GET" "" mockHeader of
|
|
|
|
(Request.Get headers _) ->
|
|
|
|
Headers.lookup headers "X-Test" `Assertions.shouldEqual` "test"
|
|
|
|
a -> Assertions.fail $ "expected a Get, got " <> show a
|
2017-07-14 06:28:57 +00:00
|
|
|
Spec.it "has the correct path" do
|
2017-07-18 01:51:43 +00:00
|
|
|
case mock "GET" "test" StrMap.empty of
|
2017-07-14 06:28:57 +00:00
|
|
|
(Request.Get _ "test") -> pure unit
|
|
|
|
a -> Assertions.fail $ "expected the path 'test', got " <> show a
|
2017-07-18 01:51:43 +00:00
|
|
|
|
|
|
|
where
|
|
|
|
mock path body =
|
|
|
|
Request.fromHTTPRequest <<< SpecHelpers.mockRequest path body
|
|
|
|
mockHeader = StrMap.singleton "x-test" "test"
|
2017-07-10 10:17:13 +00:00
|
|
|
|
|
|
|
requestSpec :: SpecHelpers.Test
|
2017-07-14 06:28:57 +00:00
|
|
|
requestSpec = Spec.describe "Request" do
|
|
|
|
showSpec
|
|
|
|
fromHTTPRequestSpec
|