Add an illustrative test demonstrating single question mark result

This commit is contained in:
Erik Aker 2020-01-16 21:22:56 -08:00
parent 7d2997098a
commit cee0763507
3 changed files with 11 additions and 4 deletions

View file

@ -22,8 +22,6 @@ import Control.Monad
import Control.Monad.Trans.Writer
(Writer, runWriter, tell)
import Data.Aeson
import Data.Data
(Data)
import Data.List
(isInfixOf)
import Data.Proxy
@ -161,7 +159,7 @@ spec = describe "Servant.Docs" $ do
data Datatype1 = Datatype1 { dt1field1 :: String
, dt1field2 :: Int
} deriving (Eq, Show, Data, Generic)
} deriving (Eq, Show, Generic)
instance ToJSON Datatype1
instance ToForm Datatype1

View file

@ -607,7 +607,7 @@ instance
mev :: Maybe (Either T.Text a)
mev = case B.length rawQS of
0 -> Nothing
_ -> Just $ urlDecodeAsForm (BL.drop 1 . BL.fromStrict $ rawQS)
_ -> Just $ urlDecodeAsForm $ BL.drop 1 $ BL.fromStrict rawQS
errReq = delayedFailFatal err400
{ errBody = "Query parameter form is required"

View file

@ -514,6 +514,15 @@ queryParamFormSpec = do
}
liftIO $ do
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" $
(flip runSession) (serve queryParamFormApi qpFormServer) $ do
response1 <- Network.Wai.Test.request defaultRequest