@@ -4,12 +4,16 @@ module Servant.QuickCheck.InternalSpec (spec) where
4import Control.Concurrent.MVar (newMVar, readMVar, swapMVar)
4import Control.Concurrent.MVar (newMVar, readMVar, swapMVar)
5import Control.Monad.IO.Class (liftIO)
5import Control.Monad.IO.Class (liftIO)
6import qualified Data.ByteString as BS
6import qualified Data.ByteString as BS
7+import qualified Data.ByteString.Char8 as C
7import Prelude.Compat
8import Prelude.Compat
8import Servant
9import Servant
9import Test.Hspec (Spec, context, describe, it, shouldBe,
10import Test.Hspec (Spec, context, describe, it, shouldBe,
10 shouldContain)
11 shouldContain)
11import Test.Hspec.Core.Spec (Arg, Example, Result (..),
12import Test.Hspec.Core.Spec (Arg, Example, Result (..),
12 defaultParams, evaluateExample)
13 defaultParams, evaluateExample)
14+import Test.QuickCheck.Gen (unGen)
15+import Test.QuickCheck.Random (mkQCGen)
16+import Network.HTTP.Client (queryString)
14#if MIN_VERSION_servant(0,8,0)
18#if MIN_VERSION_servant(0,8,0)
15import Servant.API.Internal.Test.ComprehensiveAPI (comprehensiveAPIWithoutRaw)
19import Servant.API.Internal.Test.ComprehensiveAPI (comprehensiveAPIWithoutRaw)
@@ -28,6 +32,8 @@ spec = do
28 isComprehensiveSpec
32 isComprehensiveSpec
29 onlyJsonObjectSpec
33 onlyJsonObjectSpec
30 notLongerThanSpec
34 notLongerThanSpec
32serversEqualSpec :: Spec
38serversEqualSpec :: Spec
33serversEqualSpec = describe "serversEqual" $ do
39serversEqualSpec = describe "serversEqual" $ do
@@ -107,6 +113,27 @@ isComprehensiveSpec = describe "HasGenRequest" $ do
107 let _g = genRequest comprehensiveAPIWithoutRaw
113 let _g = genRequest comprehensiveAPIWithoutRaw
108 True `shouldBe` True -- This is a type-level check
114 True `shouldBe` True -- This is a type-level check
116+queryParamsSpec :: Spec
117+queryParamsSpec = describe "QueryParams" $ do
119+ it "reduce to an HTTP query string correctly" $ do
121+ burl = BaseUrl Http "localhost" 80 ""
122+ gen = genRequest paramsAPI
123+ req = (unGen gen rng 0) burl
124+ qs = C.unpack $ queryString req
125+ qs `shouldBe` "one=_&two=_"
127+queryFlagsSpec :: Spec
128+queryFlagsSpec = describe "QueryFlags" $ do
130+ it "reduce to an HTTP query string correctly" $ do
132+ burl = BaseUrl Http "localhost" 80 ""
133+ gen = genRequest flagsAPI
134+ req = (unGen gen rng 0) burl
135+ qs = C.unpack $ queryString req
136+ qs `shouldBe` "one&two"
111------------------------------------------------------------------------------
138------------------------------------------------------------------------------
@@ -119,6 +146,17 @@ type API = ReqBody '[JSON] String :> Post '[JSON] String
119api :: Proxy API
146api :: Proxy API
120api = Proxy
147api = Proxy
149+type ParamsAPI = QueryParam "one" () :> QueryParam "two" () :> Get '[JSON] ()
151+paramsAPI :: Proxy ParamsAPI
154+type FlagsAPI = QueryFlag "one" :> QueryFlag "two" :> Get '[JSON] ()
156+flagsAPI :: Proxy FlagsAPI
122server :: IO (Server API)
160server :: IO (Server API)
123server = do
161server = do
124 mvar <- newMVar ""
162 mvar <- newMVar ""