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,51 +53,79 @@ responseBodyLbs response = do
|
||||||
|
|
||||||
spec :: Spec
|
spec :: Spec
|
||||||
spec = do
|
spec = do
|
||||||
it "allows to write capture combinators" $ do
|
describe "makeCaptureCombinator" $ do
|
||||||
let server = return
|
it "allows to write capture combinators" $ do
|
||||||
app = serve (Proxy :: Proxy (StringCapture :> Get' String)) server
|
let server = return
|
||||||
request = defaultRequest{
|
app = serve (Proxy :: Proxy (StringCapture :> Get' String)) server
|
||||||
rawPathInfo = "/foo",
|
request = defaultRequest{
|
||||||
pathInfo = ["foo"]
|
rawPathInfo = "/foo",
|
||||||
}
|
pathInfo = ["foo"]
|
||||||
response <- runApp app request
|
}
|
||||||
responseBodyLbs response `shouldReturn` "\"foo\""
|
response <- runApp app request
|
||||||
|
responseBodyLbs response `shouldReturn` "\"foo\""
|
||||||
|
|
||||||
it "allows to write request check combinators" $ do
|
it "allows to write a combinator that errors out" $ do
|
||||||
let server = return ()
|
let server = return
|
||||||
app = serve (Proxy :: Proxy (CheckFooHeader :> Get' ())) server
|
app = serve (Proxy :: Proxy (StringCapture :> Get' String)) server
|
||||||
request = defaultRequest{
|
request = defaultRequest {
|
||||||
requestHeaders =
|
rawPathInfo = "/error",
|
||||||
("Foo", "foo") :
|
pathInfo = ["error"]
|
||||||
requestHeaders defaultRequest
|
}
|
||||||
}
|
response <- runApp app request
|
||||||
response <- runApp app request
|
responseStatus response `shouldBe` status418
|
||||||
responseBodyLbs response `shouldReturn` "[]"
|
|
||||||
|
|
||||||
it "allows to write an auth combinator" $ do
|
describe "makeRequestCheckCombinator" $ do
|
||||||
let server (User name) = return name
|
it "allows to write request check combinators" $ do
|
||||||
app = serve (Proxy :: Proxy (AuthCombinator :> Get' String)) server
|
let server = return ()
|
||||||
request = defaultRequest{
|
app = serve (Proxy :: Proxy (CheckFooHeader :> Get' ())) server
|
||||||
requestHeaders =
|
request = defaultRequest{
|
||||||
("Auth", "secret") :
|
requestHeaders =
|
||||||
requestHeaders defaultRequest
|
("Foo", "foo") :
|
||||||
}
|
requestHeaders defaultRequest
|
||||||
response <- runApp app request
|
}
|
||||||
responseStatus response `shouldBe` ok200
|
response <- runApp app request
|
||||||
responseBodyLbs response `shouldReturn` "\"Alice\""
|
responseBodyLbs response `shouldReturn` "[]"
|
||||||
|
|
||||||
it "allows to write a combinator by providing a function (Request -> a)" $ do
|
it "disallows to access the request body" $ do
|
||||||
let server = return
|
let server = return ()
|
||||||
app = serve (Proxy :: Proxy (FooHeader :> Get' String)) server
|
app = serve (Proxy :: Proxy (InvalidRequestCheckCombinator :> Get' ())) server
|
||||||
request = defaultRequest{
|
request = defaultRequest
|
||||||
requestHeaders =
|
runApp app request `shouldThrow`
|
||||||
("Foo", "foo") :
|
errorCall "ERROR: makeRequestCheckCombinator: combinator must not access the request body"
|
||||||
requestHeaders defaultRequest
|
|
||||||
}
|
|
||||||
response <- runApp app request
|
|
||||||
responseBodyLbs response `shouldReturn` "\"foo\""
|
|
||||||
|
|
||||||
context "streaming request bodies" $ do
|
describe "makeAuthCombinator" $ do
|
||||||
|
it "allows to write an auth combinator" $ do
|
||||||
|
let server (User name) = return name
|
||||||
|
app = serve (Proxy :: Proxy (AuthCombinator :> Get' String)) server
|
||||||
|
request = defaultRequest{
|
||||||
|
requestHeaders =
|
||||||
|
("Auth", "secret") :
|
||||||
|
requestHeaders defaultRequest
|
||||||
|
}
|
||||||
|
response <- runApp app request
|
||||||
|
responseStatus response `shouldBe` ok200
|
||||||
|
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
|
||||||
|
let server = return
|
||||||
|
app = serve (Proxy :: Proxy (FooHeader :> Get' String)) server
|
||||||
|
request = defaultRequest{
|
||||||
|
requestHeaders =
|
||||||
|
("Foo", "foo") :
|
||||||
|
requestHeaders defaultRequest
|
||||||
|
}
|
||||||
|
response <- runApp app request
|
||||||
|
responseBodyLbs response `shouldReturn` "\"foo\""
|
||||||
|
|
||||||
|
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