@@ -7,6 +7,7 @@ module Servant.Utils.LinksSpec where
7
7
import Data.Proxy (Proxy (.. ))
8
8
import Test.Hspec (Expectation , Spec , describe , it ,
9
9
shouldBe )
10
+ import Data.String (fromString )
10
11
11
12
import Servant.API
12
13
@@ -32,38 +33,38 @@ apiLink = safeLink (Proxy :: Proxy TestApi)
32
33
33
34
-- | Convert a link to a URI and ensure that this maps to the given string
34
35
-- 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
38
39
39
40
spec :: Spec
40
41
spec = describe " Servant.Utils.Links" $ do
41
42
it " generates correct links for capture query params" $ do
42
43
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"
44
45
45
46
let l2 = Proxy :: Proxy (" hello" :> Capture " name" String
46
47
:> QueryParam " capital" Bool
47
48
:> 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"
49
50
50
51
it " generates correct links for CaptureAll" $ do
51
52
apiLink (Proxy :: Proxy (" all" :> CaptureAll " names" String :> Get '[JSON ] NoContent ))
52
53
[" roads" , " lead" , " to" , " rome" ]
53
- `shouldBeURI ` " all/roads/lead/to/rome"
54
+ `shouldBeLink ` " all/roads/lead/to/rome"
54
55
55
56
it " generates correct links for query flags" $ do
56
57
let l1 = Proxy :: Proxy (" balls" :> QueryFlag " bouncy"
57
58
:> 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"
60
61
61
62
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"
67
68
68
69
69
70
-- |
@@ -96,8 +97,8 @@ spec = describe "Servant.Utils.Links" $ do
96
97
-- ...
97
98
--
98
99
-- sanity check
99
- -- >>> apiLink (Proxy :: Proxy AllGood)
100
- -- get
100
+ -- >>> toUrlPiece $ apiLink (Proxy :: Proxy AllGood)
101
+ -- " get"
101
102
type WrongPath = " getTypo" :> Get '[JSON ] NoContent
102
103
type WrongReturnType = " get" :> Get '[JSON ] Bool
103
104
type WrongContentType = " get" :> Get '[OctetStream ] NoContent
0 commit comments