10
10
{-# LANGUAGE ScopedTypeVariables #-}
11
11
{-# LANGUAGE TypeApplications #-}
12
12
{-# LANGUAGE TypeFamilies #-}
13
- {-# LANGUAGE TypeOperators #-}
14
13
{-# LANGUAGE UndecidableInstances #-}
15
14
{-# OPTIONS_GHC -freduction-depth=100 #-}
16
15
{-# OPTIONS_GHC -fno-warn-orphans #-}
@@ -22,13 +21,11 @@ import Prelude ()
22
21
import Prelude.Compat
23
22
24
23
import Control.Arrow
25
- ((+++) , left )
24
+ (left )
26
25
import Control.Concurrent.STM
27
26
(atomically )
28
27
import Control.Concurrent.STM.TVar
29
28
(newTVar , readTVar )
30
- import qualified Data.ByteString as BS
31
- import qualified Data.ByteString.Lazy as BL
32
29
import Data.Foldable
33
30
(forM_ , toList )
34
31
import Data.Maybe
@@ -56,30 +53,23 @@ import Servant.Test.ComprehensiveAPI
56
53
_ = client comprehensiveAPIWithoutStreaming
57
54
58
55
spec :: Spec
59
- spec = describe " Servant.SuccessSpec" $ do
60
- successSpec
56
+ spec = describe " Servant.SuccessSpec" $ successSpec
61
57
62
58
successSpec :: Spec
63
59
successSpec = beforeAll (startWaiApp server) $ afterAll endWaiApp $ do
64
60
describe " Servant.API.Get" $ do
65
- it " get root endpoint" $ \ (_, baseUrl) -> do
66
- left show <$> runClient getRoot baseUrl `shouldReturn` Right carol
61
+ it " get root endpoint" $ \ (_, baseUrl) -> left show <$> runClient getRoot baseUrl `shouldReturn` Right carol
67
62
68
- it " get simple endpoint" $ \ (_, baseUrl) -> do
69
- left show <$> runClient getGet baseUrl `shouldReturn` Right alice
63
+ it " get simple endpoint" $ \ (_, baseUrl) -> left show <$> runClient getGet baseUrl `shouldReturn` Right alice
70
64
71
- it " get redirection endpoint" $ \ (_, baseUrl) -> do
72
- left show <$> runClient getGet307 baseUrl `shouldReturn` Right " redirecting"
65
+ it " get redirection endpoint" $ \ (_, baseUrl) -> left show <$> runClient getGet307 baseUrl `shouldReturn` Right " redirecting"
73
66
74
67
describe " Servant.API.Delete" $ do
75
- it " allows empty content type" $ \ (_, baseUrl) -> do
76
- left show <$> runClient getDeleteEmpty baseUrl `shouldReturn` Right NoContent
68
+ it " allows empty content type" $ \ (_, baseUrl) -> left show <$> runClient getDeleteEmpty baseUrl `shouldReturn` Right NoContent
77
69
78
- it " allows content type" $ \ (_, baseUrl) -> do
79
- left show <$> runClient getDeleteContentType baseUrl `shouldReturn` Right NoContent
70
+ it " allows content type" $ \ (_, baseUrl) -> left show <$> runClient getDeleteContentType baseUrl `shouldReturn` Right NoContent
80
71
81
- it " Servant.API.Capture" $ \ (_, baseUrl) -> do
82
- left show <$> runClient (getCapture " Paula" ) baseUrl `shouldReturn` Right (Person " Paula" 0 )
72
+ it " Servant.API.Capture" $ \ (_, baseUrl) -> left show <$> runClient (getCapture " Paula" ) baseUrl `shouldReturn` Right (Person " Paula" 0 )
83
73
84
74
it " Servant.API.CaptureAll" $ \ (_, baseUrl) -> do
85
75
let expected = [Person " Paula" 0 , Person " Peta" 1 ]
@@ -107,18 +97,15 @@ successSpec = beforeAll (startWaiApp server) $ afterAll endWaiApp $ do
107
97
`shouldReturn` Right [Person " alice" 0 , Person " bob" 1 ]
108
98
109
99
context " Servant.API.QueryParam.QueryFlag" $
110
- forM_ [False , True ] $ \ flag -> it (show flag) $ \ (_, baseUrl) -> do
111
- left show <$> runClient (getQueryFlag flag) baseUrl `shouldReturn` Right flag
100
+ forM_ [False , True ] $ \ flag -> it (show flag) $ \ (_, baseUrl) -> left show <$> runClient (getQueryFlag flag) baseUrl `shouldReturn` Right flag
112
101
113
102
it " Servant.API.QueryParam.QueryString" $ \ (_, baseUrl) -> do
114
103
let qs = [(" name" , Just " bob" ), (" age" , Just " 1" )]
115
- left show <$> runClient (getQueryString qs) baseUrl `shouldReturn` ( Right (Person " bob" 1 ) )
104
+ left show <$> runClient (getQueryString qs) baseUrl `shouldReturn` Right (Person " bob" 1 )
116
105
117
- it " Servant.API.QueryParam.DeepQuery" $ \ (_, baseUrl) -> do
118
- left show <$> runClient (getDeepQuery $ Filter 1 " bob" ) baseUrl `shouldReturn` (Right (Person " bob" 1 ))
106
+ it " Servant.API.QueryParam.DeepQuery" $ \ (_, baseUrl) -> left show <$> runClient (getDeepQuery $ Filter 1 " bob" ) baseUrl `shouldReturn` (Right (Person " bob" 1 ))
119
107
120
- it " Servant.API.Fragment" $ \ (_, baseUrl) -> do
121
- left id <$> runClient getFragment baseUrl `shouldReturn` Right alice
108
+ it " Servant.API.Fragment" $ \ (_, baseUrl) -> left id <$> runClient getFragment baseUrl `shouldReturn` Right alice
122
109
123
110
it " Servant.API.Raw on success" $ \ (_, baseUrl) -> do
124
111
res <- runClient (getRawSuccess HTTP. methodGet) baseUrl
@@ -180,13 +167,12 @@ successSpec = beforeAll (startWaiApp server) $ afterAll endWaiApp $ do
180
167
Right r ->
181
168
(" X-Added-Header" , " XXX" ) `elem` toList (responseHeaders r) `shouldBe` True
182
169
183
- modifyMaxSuccess (const 20 ) $ do
184
- it " works for a combination of Capture, QueryParam, QueryFlag and ReqBody" $ \ (_, baseUrl) ->
185
- property $ forAllShrink pathGen shrink $ \ (NonEmpty cap) num flag body ->
186
- ioProperty $ do
187
- result <- left show <$> runClient (getMultiple cap num flag body) baseUrl
188
- return $
189
- result === Right (cap, num, flag, body)
170
+ modifyMaxSuccess (const 20 ) $ it " works for a combination of Capture, QueryParam, QueryFlag and ReqBody" $ \ (_, baseUrl) ->
171
+ property $ forAllShrink pathGen shrink $ \ (NonEmpty cap) num flag body ->
172
+ ioProperty $ do
173
+ result <- left show <$> runClient (getMultiple cap num flag body) baseUrl
174
+ return $
175
+ result === Right (cap, num, flag, body)
190
176
191
177
context " With a route that can either return success or redirect" $ do
192
178
it " Redirects when appropriate" $ \ (_, baseUrl) -> do
@@ -203,7 +189,7 @@ successSpec = beforeAll (startWaiApp server) $ afterAll endWaiApp $ do
203
189
204
190
context " with a route that uses uverb but only has a single response" $
205
191
it " returns the expected response" $ \ (_, baseUrl) -> do
206
- eitherResponse <- runClient ( uverbGetCreated) baseUrl
192
+ eitherResponse <- runClient uverbGetCreated baseUrl
207
193
case eitherResponse of
208
194
Left clientError -> fail $ show clientError
209
195
Right response -> matchUnion response `shouldBe` Just (WithStatus @ 201 carol)
0 commit comments