@@ -7,6 +7,7 @@ module Servant.Utils.LinksSpec where
77import Data.Proxy (Proxy (..))
88import Test.Hspec (Expectation, Spec, describe, it,
99 shouldBe)
10+import Data.String (fromString)
1011
1112import Servant.API
1213
@@ -32,38 +33,38 @@ apiLink = safeLink (Proxy :: Proxy TestApi)
3233
3334-- | Convert a link to a URI and ensure that this maps to the given string
3435-- given string
35−shouldBeURI :: URI -> String -> Expectation
36−shouldBeURI link expected =
37− show link `shouldBe` expected
36+shouldBeLink :: Link -> String -> Expectation
37+shouldBeLink link expected =
38+ toUrlPiece link `shouldBe` fromString expected
3839
3940spec :: Spec
4041spec = describe "Servant.Utils.Links" $ do
4142 it "generates correct links for capture query params" $ do
4243 let l1 = Proxy :: Proxy ("hello" :> Capture "name" String :> Delete '[JSON] NoContent)
43− apiLink l1 "hi" `shouldBeURI` "hello/hi"
44+ apiLink l1 "hi" `shouldBeLink` "hello/hi"
4445
4546 let l2 = Proxy :: Proxy ("hello" :> Capture "name" String
4647 :> QueryParam "capital" Bool
4748 :> Delete '[JSON] NoContent)
48− apiLink l2 "bye" (Just True) `shouldBeURI` "hello/bye?capital=true"
49+ apiLink l2 "bye" (Just True) `shouldBeLink` "hello/bye?capital=true"
4950
5051 it "generates correct links for CaptureAll" $ do
5152 apiLink (Proxy :: Proxy ("all" :> CaptureAll "names" String :> Get '[JSON] NoContent))
5253 ["roads", "lead", "to", "rome"]
53− `shouldBeURI` "all/roads/lead/to/rome"
54+ `shouldBeLink` "all/roads/lead/to/rome"
5455
5556 it "generates correct links for query flags" $ do
5657 let l1 = Proxy :: Proxy ("balls" :> QueryFlag "bouncy"
5758 :> QueryFlag "fast" :> Delete '[JSON] NoContent)
58− apiLink l1 True True `shouldBeURI` "balls?bouncy&fast"
59− apiLink l1 False True `shouldBeURI` "balls?fast"
59+ apiLink l1 True True `shouldBeLink` "balls?bouncy&fast"
60+ apiLink l1 False True `shouldBeLink` "balls?fast"
6061
6162 it "generates correct links for all of the verbs" $ do
62− apiLink (Proxy :: Proxy ("get" :> Get '[JSON] NoContent)) `shouldBeURI` "get"
63− apiLink (Proxy :: Proxy ("put" :> Put '[JSON] NoContent)) `shouldBeURI` "put"
64− apiLink (Proxy :: Proxy ("post" :> Post '[JSON] NoContent)) `shouldBeURI` "post"
65− apiLink (Proxy :: Proxy ("delete" :> Delete '[JSON] NoContent)) `shouldBeURI` "delete"
66− apiLink (Proxy :: Proxy ("raw" :> Raw)) `shouldBeURI` "raw"
63+ apiLink (Proxy :: Proxy ("get" :> Get '[JSON] NoContent)) `shouldBeLink` "get"
64+ apiLink (Proxy :: Proxy ("put" :> Put '[JSON] NoContent)) `shouldBeLink` "put"
65+ apiLink (Proxy :: Proxy ("post" :> Post '[JSON] NoContent)) `shouldBeLink` "post"
66+ apiLink (Proxy :: Proxy ("delete" :> Delete '[JSON] NoContent)) `shouldBeLink` "delete"
67+ apiLink (Proxy :: Proxy ("raw" :> Raw)) `shouldBeLink` "raw"
6768
6869
6970-- |
@@ -96,8 +97,8 @@ spec = describe "Servant.Utils.Links" $ do
9697-- ...
9798--
9899-- sanity check
99−-- >>> apiLink (Proxy :: Proxy AllGood)
100−-- get
100+-- >>> toUrlPiece $ apiLink (Proxy :: Proxy AllGood)
101+-- "get"
101102type WrongPath = "getTypo" :> Get '[JSON] NoContent
102103type WrongReturnType = "get" :> Get '[JSON] Bool
103104type WrongContentType = "get" :> Get '[OctetStream] NoContent