Add Spec test for Redirect combinator
This commit is contained in:
parent
56f639b581
commit
363d142571
1 changed files with 50 additions and 1 deletions
|
@ -56,7 +56,7 @@ import Servant.API
|
||||||
HasStatus (StatusOf), Header, Headers, HttpVersion,
|
HasStatus (StatusOf), Header, Headers, HttpVersion,
|
||||||
IsSecure (..), JSON, Lenient, NoContent (..), NoContentVerb,
|
IsSecure (..), JSON, Lenient, NoContent (..), NoContentVerb,
|
||||||
NoFraming, OctetStream, Patch, PlainText, Post, Put,
|
NoFraming, OctetStream, Patch, PlainText, Post, Put,
|
||||||
QueryFlag, QueryParam, QueryParams, Raw, RemoteHost, ReqBody,
|
QueryFlag, QueryParam, QueryParams, Raw, Redirect, RemoteHost, ReqBody,
|
||||||
SourceIO, StdMethod (..), Stream, StreamGet, Strict, UVerb,
|
SourceIO, StdMethod (..), Stream, StreamGet, Strict, UVerb,
|
||||||
Union, Verb, WithRoutingHeader, WithStatus (..), addHeader)
|
Union, Verb, WithRoutingHeader, WithStatus (..), addHeader)
|
||||||
import Servant.Server
|
import Servant.Server
|
||||||
|
@ -108,6 +108,7 @@ spec = do
|
||||||
basicAuthSpec
|
basicAuthSpec
|
||||||
genAuthSpec
|
genAuthSpec
|
||||||
routedPathHeadersSpec
|
routedPathHeadersSpec
|
||||||
|
redirectionSpec
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
-- * verbSpec {{{
|
-- * verbSpec {{{
|
||||||
|
@ -943,6 +944,54 @@ routedPathHeadersSpec = do
|
||||||
liftIO $ simpleHeaders response `shouldSatisfy`
|
liftIO $ simpleHeaders response `shouldSatisfy`
|
||||||
(notMember "Servant-Routed-Path") . fromList
|
(notMember "Servant-Routed-Path") . fromList
|
||||||
|
|
||||||
|
-- }}}
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
-- * Redirection {{{
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
type RedirectionApi
|
||||||
|
= "old-api" :> Redirect "/new-api" :>
|
||||||
|
( Verb 'GET 307 '[JSON] NoContent
|
||||||
|
:<|> Verb 'POST 307 '[JSON] NoContent
|
||||||
|
:<|> "sub-api" :> Redirect "/new-api/sub-api" :> Verb 'GET 301 '[JSON] NoContent
|
||||||
|
)
|
||||||
|
:<|> "new-api" :>
|
||||||
|
( Get '[JSON] Person
|
||||||
|
:<|> Post '[JSON] Person
|
||||||
|
:<|> "sub-api" :> Get '[JSON] Person
|
||||||
|
)
|
||||||
|
|
||||||
|
redirectionApi :: Proxy RedirectionApi
|
||||||
|
redirectionApi = Proxy
|
||||||
|
|
||||||
|
redirectionServer :: Server RedirectionApi
|
||||||
|
redirectionServer =
|
||||||
|
( return NoContent
|
||||||
|
:<|> return NoContent
|
||||||
|
:<|> return NoContent
|
||||||
|
) :<|>
|
||||||
|
( return alice
|
||||||
|
:<|> return alice
|
||||||
|
:<|> return alice
|
||||||
|
)
|
||||||
|
|
||||||
|
redirectionSpec :: Spec
|
||||||
|
redirectionSpec = do
|
||||||
|
describe "Redirect combinator" $ do
|
||||||
|
with (return $ serve redirectionApi redirectionServer) $ do
|
||||||
|
it "fills the Location header" $ do
|
||||||
|
response <- THW.request methodGet "/old-api" [] ""
|
||||||
|
liftIO $ simpleHeaders response `shouldContain`
|
||||||
|
[("Location", "/new-api")]
|
||||||
|
it "gets trumped by more specific redirections" $ do
|
||||||
|
response <- THW.request methodGet "/old-api/sub-api" [] ""
|
||||||
|
liftIO $ simpleHeaders response `shouldContain`
|
||||||
|
[("Location", "/new-api/sub-api")]
|
||||||
|
it "only fills Location header in nested apis" $ do
|
||||||
|
response <- THW.request methodGet "/new-api" [] ""
|
||||||
|
liftIO $ simpleHeaders response `shouldSatisfy`
|
||||||
|
(notMember "Location") . fromList
|
||||||
|
|
||||||
-- }}}
|
-- }}}
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
-- * UVerb {{{
|
-- * UVerb {{{
|
||||||
|
|
Loading…
Reference in a new issue