Add an illustrative test demonstrating single question mark result
This commit is contained in:
parent
7d2997098a
commit
cee0763507
3 changed files with 11 additions and 4 deletions
|
@ -22,8 +22,6 @@ import Control.Monad
|
||||||
import Control.Monad.Trans.Writer
|
import Control.Monad.Trans.Writer
|
||||||
(Writer, runWriter, tell)
|
(Writer, runWriter, tell)
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
import Data.Data
|
|
||||||
(Data)
|
|
||||||
import Data.List
|
import Data.List
|
||||||
(isInfixOf)
|
(isInfixOf)
|
||||||
import Data.Proxy
|
import Data.Proxy
|
||||||
|
@ -161,7 +159,7 @@ spec = describe "Servant.Docs" $ do
|
||||||
|
|
||||||
data Datatype1 = Datatype1 { dt1field1 :: String
|
data Datatype1 = Datatype1 { dt1field1 :: String
|
||||||
, dt1field2 :: Int
|
, dt1field2 :: Int
|
||||||
} deriving (Eq, Show, Data, Generic)
|
} deriving (Eq, Show, Generic)
|
||||||
|
|
||||||
instance ToJSON Datatype1
|
instance ToJSON Datatype1
|
||||||
instance ToForm Datatype1
|
instance ToForm Datatype1
|
||||||
|
|
|
@ -607,7 +607,7 @@ instance
|
||||||
mev :: Maybe (Either T.Text a)
|
mev :: Maybe (Either T.Text a)
|
||||||
mev = case B.length rawQS of
|
mev = case B.length rawQS of
|
||||||
0 -> Nothing
|
0 -> Nothing
|
||||||
_ -> Just $ urlDecodeAsForm (BL.drop 1 . BL.fromStrict $ rawQS)
|
_ -> Just $ urlDecodeAsForm $ BL.drop 1 $ BL.fromStrict rawQS
|
||||||
|
|
||||||
errReq = delayedFailFatal err400
|
errReq = delayedFailFatal err400
|
||||||
{ errBody = "Query parameter form is required"
|
{ errBody = "Query parameter form is required"
|
||||||
|
|
|
@ -514,6 +514,15 @@ queryParamFormSpec = do
|
||||||
}
|
}
|
||||||
liftIO $ do
|
liftIO $ do
|
||||||
decode' (simpleBody response1) `shouldBe` (Just $ Animal { species = "bimac", numberOfLegs = 7})
|
decode' (simpleBody response1) `shouldBe` (Just $ Animal { species = "bimac", numberOfLegs = 7})
|
||||||
|
it "Just a question mark will match but return a Left" $
|
||||||
|
(flip runSession) (serve queryParamFormApi qpFormServer) $ do
|
||||||
|
let paramsQ = "?"
|
||||||
|
response1 <- Network.Wai.Test.request defaultRequest{
|
||||||
|
rawQueryString = paramsQ,
|
||||||
|
queryString = parseQuery paramsQ
|
||||||
|
}
|
||||||
|
liftIO $ do
|
||||||
|
decode' (simpleBody response1) `shouldBe` (Just $ Animal { species = "broken", numberOfLegs = 0})
|
||||||
it "allows no query params at all" $
|
it "allows no query params at all" $
|
||||||
(flip runSession) (serve queryParamFormApi qpFormServer) $ do
|
(flip runSession) (serve queryParamFormApi qpFormServer) $ do
|
||||||
response1 <- Network.Wai.Test.request defaultRequest
|
response1 <- Network.Wai.Test.request defaultRequest
|
||||||
|
|
Loading…
Reference in a new issue