@@ -2,6 +2,7 @@ module MakeRequest.Spec where
22
33import Prelude
44
5+import Data.HTTP.Method as HTTP
56import Data.Tuple.Nested ((/\))
67import JS.Fetch.Headers as Headers
78import Prim.RowList as RL
@@ -9,23 +10,30 @@ import Test.Spec (Spec, describe, it)
910import Test.Spec.Assertions (shouldEqual, shouldSatisfy)
1011import Type.Proxy (Proxy(..))
1112import Yoga.Fetch.Om (toHeaders)
13+import Yoga.Fetch.Om.MakeRequest (httpMethod)
14+import Yoga.HTTP.API.Route.Method as Route
1215
1316spec :: Spec Unit
14−spec = describe "toHeaders" do
15− it "empty headers produces no entries" do
16− let hdrs = toHeaders (Proxy :: _ RL.Nil) {}
17− Headers.toArray hdrs `shouldEqual` []
17+spec = do
18+ describe "MakeRequest" do
19+ it "maps a QUERY route method to the QUERY runtime method" do
20+ httpMethod (Proxy :: Proxy Route.QUERY) `shouldEqual` HTTP.QUERY
1821
19− it "single header is included" do
20− let hdrs = toHeaders (Proxy :: _ (RL.Cons "authorization" String RL.Nil)) { authorization: "Bearer abc123" }
21− Headers.toArray hdrs `shouldEqual` [ "authorization" /\ "Bearer abc123" ]
22+ describe "toHeaders" do
23+ it "empty headers produces no entries" do
24+ let hdrs = toHeaders (Proxy :: _ RL.Nil) {}
25+ Headers.toArray hdrs `shouldEqual` []
2226
23− it "multiple headers are included" do
24− let
25− hdrs = toHeaders
26− (Proxy :: _ (RL.Cons "authorization" String (RL.Cons "x-custom" String RL.Nil)))
27− { authorization: "Bearer abc123", "x-custom": "value" }
28− arr = Headers.toArray hdrs
29− arr `shouldSatisfy` \a ->
30− a == [ "authorization" /\ "Bearer abc123", "x-custom" /\ "value" ]
31− || a == [ "x-custom" /\ "value", "authorization" /\ "Bearer abc123" ]
27+ it "single header is included" do
28+ let hdrs = toHeaders (Proxy :: _ (RL.Cons "authorization" String RL.Nil)) { authorization: "Bearer abc123" }
29+ Headers.toArray hdrs `shouldEqual` [ "authorization" /\ "Bearer abc123" ]
30+
31+ it "multiple headers are included" do
32+ let
33+ hdrs = toHeaders
34+ (Proxy :: _ (RL.Cons "authorization" String (RL.Cons "x-custom" String RL.Nil)))
35+ { authorization: "Bearer abc123", "x-custom": "value" }
36+ arr = Headers.toArray hdrs
37+ arr `shouldSatisfy` \a ->
38+ a == [ "authorization" /\ "Bearer abc123", "x-custom" /\ "value" ]
39+ || a == [ "x-custom" /\ "value", "authorization" /\ "Bearer abc123" ]