@@ -21,6 +21,7 @@ import qualified Foo
2121import qualified Headers
2222import qualified Nested
2323import qualified Post
24+import qualified Put
2425import qualified Product
2526import qualified QueryParams
2627import qualified Roboservant as R
@@ -36,7 +37,7 @@ import Servant.Client(ClientEnv, mkClientEnv, baseUrlPort, parseBaseUrl,HasClien
3637import Network.Wai(Application)
3738import qualified Network.Wai.Handler.Warp as Warp
3839import Network.HTTP.Client (newManager, defaultManagerSettings)
39−import Servant(Endpoints,HasServer)
40+import Control.Monad((>=>))
4041
4142main :: IO ()
4243main = hspec spec
@@ -47,15 +48,15 @@ fuzzBoth
4748 HasClient ClientM a)
4849 => String -> Server a -> R.Config -> (Maybe R.Report -> IO ()) -> Spec
4950fuzzBoth name server config condition = do
50− it (name <> " via server") $ do
51+ it (name <> " via server") $
5152 RS.fuzz @a server config >>= condition
5253
53− around (withServer (serve (Proxy :: Proxy a) server)) $ do
54+ around (withServer (serve (Proxy :: Proxy a) server)) $
5455 it (name <> " via client") $ \(clientEnv::ClientEnv) -> do
55− RC.fuzz @a clientEnv config >>= condition
56+ RC.fuzz @a clientEnv config >>= condition
5657
5758withServer :: Application -> ActionWith ClientEnv -> IO ()
58−withServer app action = Warp.testWithApplication (pure app) (\p -> genClientEnv p >>= action)
59+withServer app action = Warp.testWithApplication (pure app) (genClientEnv >=> action)
5960 where genClientEnv port = do
6061 baseUrl <- parseBaseUrl "http://localhost"
6162 manager <- newManager defaultManagerSettings
@@ -74,9 +75,15 @@ spec = do
7475 Just (R.InsufficientCoverage _) -> True
7576 _ -> False
7677 ))
77− describe "posted body" $ do
78+ describe "posted body" $
7879 fuzzBoth @Post.Api "passes a coverage check using a posted body" Post.server R.defaultConfig {R.coverageThreshold = 0.99}
79− (`shouldSatisfy` isNothing)
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+
8087
8188 describe "seeded" $ do
8289 let res = Seeded.Seed 1
@@ -84,31 +91,29 @@ spec = do
8491 (R.defaultConfig {R.seed = [(toDyn res, hash res)]})
8592 (`shouldSatisfy` isNothing)
8693
87− describe "Foo" $ do
94+ describe "Foo" $
8895 fuzzBoth @Foo.Api "finds an error in a basic app" Foo.server R.defaultConfig (`shouldSatisfy` serverFailure)
8996
90− describe "QueryParams" $ do
97+ describe "QueryParams" $
9198 fuzzBoth @QueryParams.Api "can handle query params" QueryParams.server R.defaultConfig { R.seed = [R.hashedDyn (12::Int)] }
92− (`shouldSatisfy` isNothing)
99+ (`shouldSatisfy` isNothing)
93100
94101 describe "BuildFrom" $ do
95− describe "headers (and sum types)" $ do
102+ describe "headers (and sum types)" $
96103 fuzzBoth @Headers.Api "should find a failure that's dependent on using header info" Headers.server R.defaultConfig
97− (`shouldSatisfy` serverFailure)
98− describe "product types" $ do
104+ (`shouldSatisfy` serverFailure)
105+ describe "product types" $
99106 fuzzBoth @Product.Api "should find a failure that's dependent on creating a product" Product.server
100− R.defaultConfig {R.seed = [R.hashedDyn 'a', R.hashedDyn (1 :: Int)]}
101− (`shouldSatisfy` serverFailure)
107+ R.defaultConfig {R.seed = [R.hashedDyn 'a', R.hashedDyn (1 :: Int)]}
108+ (`shouldSatisfy` serverFailure)
102109 describe "Breakdown" $ do
103110 fuzzBoth @Breakdown.ProductApi "handles products" Breakdown.productServer R.defaultConfig
104111 (`shouldSatisfy` serverFailure)
105112 fuzzBoth @Breakdown.SumApi "handles sums" Breakdown.sumServer R.defaultConfig
106113 (`shouldSatisfy` serverFailure)
107− describe "flattening" $ do
108− -- we don't actually do much here, this is just here to document the appropriate response
109− -- if you get a type error with a nested api.
114+ describe "flattening" $
110115 fuzzBoth @Nested.FlatApi "can handle nested apis" Nested.server R.defaultConfig {R.coverageThreshold = 0.99}
111− (`shouldSatisfy` isNothing)
116+ (`shouldSatisfy` isNothing)
112117
113118serverFailure :: Maybe R.Report -> Bool
114119serverFailure = \case
@@ -132,9 +137,13 @@ deriving via (R.Atom Seeded.Seed) instance R.BuildFrom Seeded.Seed
132137deriving via (R.Atom Void) instance R.BuildFrom Void
133138
134139deriving via (R.Atom Post.FooPost) instance R.Breakdown Post.FooPost
135−
136140deriving via (R.Atom Post.FooPost) instance R.BuildFrom Post.FooPost
137141
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+
145+
146+
138147deriving via (R.Compound Breakdown.Foo) instance R.Breakdown Breakdown.Foo
139148
140149deriving via (R.Compound Product.Foo) instance R.BuildFrom Product.Foo
@@ -149,7 +158,7 @@ shouldFail =
149158 ( \i ->
150159 i
151160 { itemExample = \p a cb -> do
152− r <- (itemExample i) p a cb
161+ r <- itemExample i p a cb
153162 pure
154163 r
155164 { resultStatus = case resultStatus r of