reorder tests
This commit is contained in:
parent
6a5256c3ff
commit
ea43025d65
2 changed files with 73 additions and 69 deletions
|
@ -4,6 +4,9 @@
|
||||||
{-# LANGUAGE TypeFamilies #-}
|
{-# LANGUAGE TypeFamilies #-}
|
||||||
{-# LANGUAGE TypeOperators #-}
|
{-# LANGUAGE TypeOperators #-}
|
||||||
|
|
||||||
|
-- fixme: document phases
|
||||||
|
-- fixme: add doctests
|
||||||
|
|
||||||
module Servant.Server.Utils.CustomCombinators (
|
module Servant.Server.Utils.CustomCombinators (
|
||||||
CombinatorImplementation,
|
CombinatorImplementation,
|
||||||
runCI,
|
runCI,
|
||||||
|
|
|
@ -53,6 +53,7 @@ responseBodyLbs response = do
|
||||||
|
|
||||||
spec :: Spec
|
spec :: Spec
|
||||||
spec = do
|
spec = do
|
||||||
|
describe "makeCaptureCombinator" $ do
|
||||||
it "allows to write capture combinators" $ do
|
it "allows to write capture combinators" $ do
|
||||||
let server = return
|
let server = return
|
||||||
app = serve (Proxy :: Proxy (StringCapture :> Get' String)) server
|
app = serve (Proxy :: Proxy (StringCapture :> Get' String)) server
|
||||||
|
@ -63,6 +64,17 @@ spec = do
|
||||||
response <- runApp app request
|
response <- runApp app request
|
||||||
responseBodyLbs response `shouldReturn` "\"foo\""
|
responseBodyLbs response `shouldReturn` "\"foo\""
|
||||||
|
|
||||||
|
it "allows to write a combinator that errors out" $ do
|
||||||
|
let server = return
|
||||||
|
app = serve (Proxy :: Proxy (StringCapture :> Get' String)) server
|
||||||
|
request = defaultRequest {
|
||||||
|
rawPathInfo = "/error",
|
||||||
|
pathInfo = ["error"]
|
||||||
|
}
|
||||||
|
response <- runApp app request
|
||||||
|
responseStatus response `shouldBe` status418
|
||||||
|
|
||||||
|
describe "makeRequestCheckCombinator" $ do
|
||||||
it "allows to write request check combinators" $ do
|
it "allows to write request check combinators" $ do
|
||||||
let server = return ()
|
let server = return ()
|
||||||
app = serve (Proxy :: Proxy (CheckFooHeader :> Get' ())) server
|
app = serve (Proxy :: Proxy (CheckFooHeader :> Get' ())) server
|
||||||
|
@ -74,6 +86,14 @@ spec = do
|
||||||
response <- runApp app request
|
response <- runApp app request
|
||||||
responseBodyLbs response `shouldReturn` "[]"
|
responseBodyLbs response `shouldReturn` "[]"
|
||||||
|
|
||||||
|
it "disallows to access the request body" $ do
|
||||||
|
let server = return ()
|
||||||
|
app = serve (Proxy :: Proxy (InvalidRequestCheckCombinator :> Get' ())) server
|
||||||
|
request = defaultRequest
|
||||||
|
runApp app request `shouldThrow`
|
||||||
|
errorCall "ERROR: makeRequestCheckCombinator: combinator must not access the request body"
|
||||||
|
|
||||||
|
describe "makeAuthCombinator" $ do
|
||||||
it "allows to write an auth combinator" $ do
|
it "allows to write an auth combinator" $ do
|
||||||
let server (User name) = return name
|
let server (User name) = return name
|
||||||
app = serve (Proxy :: Proxy (AuthCombinator :> Get' String)) server
|
app = serve (Proxy :: Proxy (AuthCombinator :> Get' String)) server
|
||||||
|
@ -86,6 +106,14 @@ spec = do
|
||||||
responseStatus response `shouldBe` ok200
|
responseStatus response `shouldBe` ok200
|
||||||
responseBodyLbs response `shouldReturn` "\"Alice\""
|
responseBodyLbs response `shouldReturn` "\"Alice\""
|
||||||
|
|
||||||
|
it "disallows to access the request body" $ do
|
||||||
|
let server _user = return "foo"
|
||||||
|
app = serve (Proxy :: Proxy (InvalidAuthCombinator :> Get' String)) server
|
||||||
|
request = defaultRequest
|
||||||
|
runApp app request `shouldThrow`
|
||||||
|
errorCall "ERROR: makeAuthCombinator: combinator must not access the request body"
|
||||||
|
|
||||||
|
describe "makeCombinator" $ do
|
||||||
it "allows to write a combinator by providing a function (Request -> a)" $ do
|
it "allows to write a combinator by providing a function (Request -> a)" $ do
|
||||||
let server = return
|
let server = return
|
||||||
app = serve (Proxy :: Proxy (FooHeader :> Get' String)) server
|
app = serve (Proxy :: Proxy (FooHeader :> Get' String)) server
|
||||||
|
@ -97,7 +125,7 @@ spec = do
|
||||||
response <- runApp app request
|
response <- runApp app request
|
||||||
responseBodyLbs response `shouldReturn` "\"foo\""
|
responseBodyLbs response `shouldReturn` "\"foo\""
|
||||||
|
|
||||||
context "streaming request bodies" $ do
|
describe "makeReqBodyCombinator" $ do
|
||||||
let toBody :: [IO SBS.ByteString] -> IO (IO SBS.ByteString)
|
let toBody :: [IO SBS.ByteString] -> IO (IO SBS.ByteString)
|
||||||
toBody list = do
|
toBody list = do
|
||||||
mvar <- newMVar list
|
mvar <- newMVar list
|
||||||
|
@ -133,39 +161,12 @@ spec = do
|
||||||
response <- runApp app request
|
response <- runApp app request
|
||||||
responseBodyLbs response `shouldReturn` "\"foobar\""
|
responseBodyLbs response `shouldReturn` "\"foobar\""
|
||||||
|
|
||||||
it "allows to write a combinator that errors out" $ do
|
|
||||||
let server = return
|
|
||||||
app = serve (Proxy :: Proxy (StringCapture :> Get' String)) server
|
|
||||||
request = defaultRequest {
|
|
||||||
rawPathInfo = "/error",
|
|
||||||
pathInfo = ["error"]
|
|
||||||
}
|
|
||||||
response <- runApp app request
|
|
||||||
responseStatus response `shouldBe` status418
|
|
||||||
|
|
||||||
it "disallows to access the request body unless in the checkBody phase" $ do
|
|
||||||
let server = return ()
|
|
||||||
app = serve (Proxy :: Proxy (InvalidRequestCheckCombinator :> Get' ())) server
|
|
||||||
request = defaultRequest
|
|
||||||
runApp app request `shouldThrow`
|
|
||||||
errorCall "ERROR: makeRequestCheckCombinator: combinator must not access the request body"
|
|
||||||
|
|
||||||
it "disallows to access the request body unless in the auth phase" $ do
|
|
||||||
let server _user = return "foo"
|
|
||||||
app = serve (Proxy :: Proxy (InvalidAuthCombinator :> Get' String)) server
|
|
||||||
request = defaultRequest
|
|
||||||
runApp app request `shouldThrow`
|
|
||||||
errorCall "ERROR: makeAuthCombinator: combinator must not access the request body"
|
|
||||||
|
|
||||||
-- fixme: reorder tests
|
-- fixme: reorder tests
|
||||||
|
|
||||||
it "allows to access the context" $ do
|
it "allows to access the context" $ do
|
||||||
pending
|
pending
|
||||||
|
|
||||||
it "allows to write combinators without args" $ do
|
it "allows to implement combinators in terms of existing combinators" $ do
|
||||||
pending
|
|
||||||
|
|
||||||
it "allows to implement combinators based in terms of existing combinators" $ do
|
|
||||||
pending
|
pending
|
||||||
|
|
||||||
type Get' = Get '[JSON]
|
type Get' = Get '[JSON]
|
||||||
|
|
Loading…
Reference in a new issue