@@ -4,12 +4,16 @@ module Servant.QuickCheck.InternalSpec (spec) where
44import Control.Concurrent.MVar (newMVar, readMVar, swapMVar)
55import Control.Monad.IO.Class (liftIO)
66import qualified Data.ByteString as BS
7+import qualified Data.ByteString.Char8 as C
78import Prelude.Compat
89import Servant
910import Test.Hspec (Spec, context, describe, it, shouldBe,
1011 shouldContain)
1112import Test.Hspec.Core.Spec (Arg, Example, Result (..),
1213 defaultParams, evaluateExample)
14+import Test.QuickCheck.Gen (unGen)
15+import Test.QuickCheck.Random (mkQCGen)
16+import Network.HTTP.Client (queryString)
1317
1418#if MIN_VERSION_servant(0,8,0)
1519import Servant.API.Internal.Test.ComprehensiveAPI (comprehensiveAPIWithoutRaw)
@@ -28,6 +32,7 @@ spec = do
2832 isComprehensiveSpec
2933 onlyJsonObjectSpec
3034 notLongerThanSpec
35+ queryParamsSpec
3136
3237serversEqualSpec :: Spec
3338serversEqualSpec = describe "serversEqual" $ do
@@ -107,6 +112,17 @@ isComprehensiveSpec = describe "HasGenRequest" $ do
107112 let _g = genRequest comprehensiveAPIWithoutRaw
108113 True `shouldBe` True -- This is a type-level check
109114
115+queryParamsSpec :: Spec
116+queryParamsSpec = describe "QueryParams" $ do
117+
118+ it "reduce to an HTTP query string correctly" $ do
119+ let rng = mkQCGen 0
120+ burl = BaseUrl Http "localhost" 80 ""
121+ gen = genRequest paramsAPI
122+ req = (unGen gen rng 0) burl
123+ qs = C.unpack $ queryString req
124+ qs `shouldContain` ("one=")
125+ qs `shouldContain` ("&two=")
110126
111127------------------------------------------------------------------------------
112128-- APIs
@@ -119,6 +135,11 @@ type API = ReqBody '[JSON] String :> Post '[JSON] String
119135api :: Proxy API
120136api = Proxy
121137
138+type ParamsAPI = QueryParam "one" String :> QueryParam "two" String :> Get '[JSON] String
139+
140+paramsAPI :: Proxy ParamsAPI
141+paramsAPI = Proxy
142+
122143server :: IO (Server API)
123144server = do
124145 mvar <- newMVar ""