@@ -21,7 +21,9 @@ import qualified Foo
2121import qualified Headers
2222import qualified Nested
2323import qualified Post
24+import qualified Put
2425import qualified Product
26+import qualified QueryParams
2527import qualified Roboservant as R
2628import qualified Roboservant.Server as RS
2729import qualified Roboservant.Client as RC
@@ -35,26 +37,26 @@ import Servant.Client(ClientEnv, mkClientEnv, baseUrlPort, parseBaseUrl,HasClien
3537import Network.Wai(Application)
3638import qualified Network.Wai.Handler.Warp as Warp
3739import Network.HTTP.Client (newManager, defaultManagerSettings)
38−import Servant(Endpoints,HasServer)
40+import Control.Monad((>=>))
3941
4042main :: IO ()
4143main = hspec spec
4244
4345fuzzBoth
44− :: forall a .
46+ :: forall a .
4547 (R.ToReifiedApi (Endpoints a), HasServer a '[], RS.FlattenServer a, RC.ToReifiedClientApi (Endpoints a), RC.FlattenClient a,
4648 HasClient ClientM a)
4749 => String -> Server a -> R.Config -> (Maybe R.Report -> IO ()) -> Spec
4850fuzzBoth name server config condition = do
49− it (name <> " via server") $ do
51+ it (name <> " via server") $
5052 RS.fuzz @a server config >>= condition
5153
52− around (withServer (serve (Proxy :: Proxy a) server)) $ do
54+ around (withServer (serve (Proxy :: Proxy a) server)) $
5355 it (name <> " via client") $ \(clientEnv::ClientEnv) -> do
54− RC.fuzz @a clientEnv config >>= condition
56+ RC.fuzz @a clientEnv config >>= condition
5557
5658withServer :: Application -> ActionWith ClientEnv -> IO ()
57−withServer app action = Warp.testWithApplication (pure app) (\p -> genClientEnv p >>= action)
59+withServer app action = Warp.testWithApplication (pure app) (genClientEnv >=> action)
5860 where genClientEnv port = do
5961 baseUrl <- parseBaseUrl "http://localhost"
6062 manager <- newManager defaultManagerSettings
@@ -73,37 +75,45 @@ spec = do
7375 Just (R.InsufficientCoverage _) -> True
7476 _ -> False
7577 ))
76− describe "posted body" $ do
78+ describe "posted body" $
7779 fuzzBoth @Post.Api "passes a coverage check using a posted body" Post.server R.defaultConfig {R.coverageThreshold = 0.99}
78− (`shouldSatisfy` isNothing)
79−
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+
87+
8088 describe "seeded" $ do
8189 let res = Seeded.Seed 1
8290 shouldFail $ fuzzBoth @Seeded.Api "finds an error using information passed in" Seeded.server
8391 (R.defaultConfig {R.seed = [(toDyn res, hash res)]})
8492 (`shouldSatisfy` isNothing)
85−
86− describe "Foo" $ do
93+
94+ describe "Foo" $
8795 fuzzBoth @Foo.Api "finds an error in a basic app" Foo.server R.defaultConfig (`shouldSatisfy` serverFailure)
8896
97+ describe "QueryParams" $
98+ fuzzBoth @QueryParams.Api "can handle query params" QueryParams.server R.defaultConfig { R.seed = [R.hashedDyn (12::Int)] }
99+ (`shouldSatisfy` isNothing)
100+
89101 describe "BuildFrom" $ do
90− describe "headers (and sum types)" $ do
102+ describe "headers (and sum types)" $
91103 fuzzBoth @Headers.Api "should find a failure that's dependent on using header info" Headers.server R.defaultConfig
92− (`shouldSatisfy` serverFailure)
93− describe "product types" $ do
94− fuzzBoth @Product.Api "should find a failure that's dependent on creating a product" Product.server
95− R.defaultConfig {R.seed = [R.hashedDyn 'a', R.hashedDyn (1 :: Int)]}
96− (`shouldSatisfy` serverFailure)
104+ (`shouldSatisfy` serverFailure)
105+ describe "product types" $
106+ 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)
97109 describe "Breakdown" $ do
98110 fuzzBoth @Breakdown.ProductApi "handles products" Breakdown.productServer R.defaultConfig
99111 (`shouldSatisfy` serverFailure)
100112 fuzzBoth @Breakdown.SumApi "handles sums" Breakdown.sumServer R.defaultConfig
101113 (`shouldSatisfy` serverFailure)
102− describe "flattening" $ do
103− -- we don't actually do much here, this is just here to document the appropriate response
104− -- if you get a type error with a nested api.
114+ describe "flattening" $
105115 fuzzBoth @Nested.FlatApi "can handle nested apis" Nested.server R.defaultConfig {R.coverageThreshold = 0.99}
106− (`shouldSatisfy` isNothing)
116+ (`shouldSatisfy` isNothing)
107117
108118serverFailure :: Maybe R.Report -> Bool
109119serverFailure = \case
@@ -127,9 +137,13 @@ deriving via (R.Atom Seeded.Seed) instance R.BuildFrom Seeded.Seed
127137deriving via (R.Atom Void) instance R.BuildFrom Void
128138
129139deriving via (R.Atom Post.FooPost) instance R.Breakdown Post.FooPost
130−
131140deriving via (R.Atom Post.FooPost) instance R.BuildFrom Post.FooPost
132141
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+
133147deriving via (R.Compound Breakdown.Foo) instance R.Breakdown Breakdown.Foo
134148
135149deriving via (R.Compound Product.Foo) instance R.BuildFrom Product.Foo
@@ -144,7 +158,7 @@ shouldFail =
144158 ( \i ->
145159 i
146160 { itemExample = \p a cb -> do
147− r <- (itemExample i) p a cb
161+ r <- itemExample i p a cb
148162 pure
149163 r
150164 { resultStatus = case resultStatus r of