@@ -21,7 +21,6 @@ import qualified Foo
2121import qualified Headers
2222import qualified Nested
2323import qualified Post
24−import qualified Put
2524import qualified Product
2625import qualified QueryParams
2726import qualified Roboservant as R
@@ -37,7 +36,6 @@ import Servant.Client(ClientEnv, mkClientEnv, baseUrlPort, parseBaseUrl,HasClien
3736import Network.Wai(Application)
3837import qualified Network.Wai.Handler.Warp as Warp
3938import Network.HTTP.Client (newManager, defaultManagerSettings)
40−import Control.Monad((>=>))
4139
4240main :: IO ()
4341main = hspec spec
@@ -48,15 +46,15 @@ fuzzBoth
4846 HasClient ClientM a)
4947 => String -> Server a -> R.Config -> (Maybe R.Report -> IO ()) -> Spec
5048fuzzBoth name server config condition = do
51− it (name <> " via server") $
49+ it (name <> " via server") $ do
5250 RS.fuzz @a server config >>= condition
5351
54− around (withServer (serve (Proxy :: Proxy a) server)) $
52+ around (withServer (serve (Proxy :: Proxy a) server)) $ do
5553 it (name <> " via client") $ \(clientEnv::ClientEnv) -> do
56− RC.fuzz @a clientEnv config >>= condition
54+ RC.fuzz @a clientEnv config >>= condition
5755
5856withServer :: Application -> ActionWith ClientEnv -> IO ()
59−withServer app action = Warp.testWithApplication (pure app) (genClientEnv >=> action)
57+withServer app action = Warp.testWithApplication (pure app) (\p -> genClientEnv p >>= action)
6058 where genClientEnv port = do
6159 baseUrl <- parseBaseUrl "http://localhost"
6260 manager <- newManager defaultManagerSettings
@@ -75,15 +73,9 @@ spec = do
7573 Just (R.InsufficientCoverage _) -> True
7674 _ -> False
7775 ))
78− describe "posted body" $
76+ describe "posted body" $ do
7977 fuzzBoth @Post.Api "passes a coverage check using a posted body" Post.server R.defaultConfig {R.coverageThreshold = 0.99}
80− (`shouldSatisfy` isNothing)
81−
82−
83− describe "PUTted body" $
84− fuzzBoth @Put.Api "passes a coverage check using a posted body" Put.server R.defaultConfig {R.coverageThreshold = 0.99}
85− (`shouldSatisfy` isNothing)
86−
78+ (`shouldSatisfy` isNothing)
8779
8880 describe "seeded" $ do
8981 let res = Seeded.Seed 1
@@ -91,29 +83,31 @@ spec = do
9183 (R.defaultConfig {R.seed = [(toDyn res, hash res)]})
9284 (`shouldSatisfy` isNothing)
9385
94− describe "Foo" $
86+ describe "Foo" $ do
9587 fuzzBoth @Foo.Api "finds an error in a basic app" Foo.server R.defaultConfig (`shouldSatisfy` serverFailure)
9688
97− describe "QueryParams" $
89+ describe "QueryParams" $ do
9890 fuzzBoth @QueryParams.Api "can handle query params" QueryParams.server R.defaultConfig { R.seed = [R.hashedDyn (12::Int)] }
99− (`shouldSatisfy` isNothing)
91+ (`shouldSatisfy` isNothing)
10092
10193 describe "BuildFrom" $ do
102− describe "headers (and sum types)" $
94+ describe "headers (and sum types)" $ do
10395 fuzzBoth @Headers.Api "should find a failure that's dependent on using header info" Headers.server R.defaultConfig
104− (`shouldSatisfy` serverFailure)
105− describe "product types" $
96+ (`shouldSatisfy` serverFailure)
97+ describe "product types" $ do
10698 fuzzBoth @Product.Api "should find a failure that's dependent on creating a product" Product.server
107− R.defaultConfig {R.seed = [R.hashedDyn 'a', R.hashedDyn (1 :: Int)]}
108− (`shouldSatisfy` serverFailure)
99+ R.defaultConfig {R.seed = [R.hashedDyn 'a', R.hashedDyn (1 :: Int)]}
100+ (`shouldSatisfy` serverFailure)
109101 describe "Breakdown" $ do
110102 fuzzBoth @Breakdown.ProductApi "handles products" Breakdown.productServer R.defaultConfig
111103 (`shouldSatisfy` serverFailure)
112104 fuzzBoth @Breakdown.SumApi "handles sums" Breakdown.sumServer R.defaultConfig
113105 (`shouldSatisfy` serverFailure)
114− describe "flattening" $
106+ describe "flattening" $ do
107+ -- we don't actually do much here, this is just here to document the appropriate response
108+ -- if you get a type error with a nested api.
115109 fuzzBoth @Nested.FlatApi "can handle nested apis" Nested.server R.defaultConfig {R.coverageThreshold = 0.99}
116− (`shouldSatisfy` isNothing)
110+ (`shouldSatisfy` isNothing)
117111
118112serverFailure :: Maybe R.Report -> Bool
119113serverFailure = \case
@@ -137,12 +131,8 @@ deriving via (R.Atom Seeded.Seed) instance R.BuildFrom Seeded.Seed
137131deriving via (R.Atom Void) instance R.BuildFrom Void
138132
139133deriving via (R.Atom Post.FooPost) instance R.Breakdown Post.FooPost
140−deriving via (R.Atom Post.FooPost) instance R.BuildFrom Post.FooPost
141−
142−deriving via (R.Atom Put.Foo) instance R.Breakdown Put.Foo
143−deriving via (R.Atom Put.Foo) instance R.BuildFrom Put.Foo
144−
145134
135+deriving via (R.Atom Post.FooPost) instance R.BuildFrom Post.FooPost
146136
147137deriving via (R.Compound Breakdown.Foo) instance R.Breakdown Breakdown.Foo
148138
@@ -158,7 +148,7 @@ shouldFail =
158148 ( \i ->
159149 i
160150 { itemExample = \p a cb -> do
161− r <- itemExample i p a cb
151+ r <- (itemExample i) p a cb
162152 pure
163153 r
164154 { resultStatus = case resultStatus r of