@@ -21,9 +21,7 @@ import qualified Foo
2121import qualified Headers
2222import qualified Nested
2323import qualified Post
24−import qualified Put
2524import qualified Product
26−import qualified QueryParams
2725import qualified Roboservant as R
2826import qualified Roboservant.Server as RS
2927import qualified Roboservant.Client as RC
@@ -37,26 +35,26 @@ import Servant.Client(ClientEnv, mkClientEnv, baseUrlPort, parseBaseUrl,HasClien
3735import Network.Wai(Application)
3836import qualified Network.Wai.Handler.Warp as Warp
3937import Network.HTTP.Client (newManager, defaultManagerSettings)
40−import Control.Monad((>=>))
38+import Servant(Endpoints,HasServer)
4139
4240main :: IO ()
4341main = hspec spec
4442
4543fuzzBoth
46− :: forall a .
44+ :: forall a .
4745 (R.ToReifiedApi (Endpoints a), HasServer a '[], RS.FlattenServer a, RC.ToReifiedClientApi (Endpoints a), RC.FlattenClient a,
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,45 +73,37 @@ 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−
87−
78+ (`shouldSatisfy` isNothing)
79+
8880 describe "seeded" $ do
8981 let res = Seeded.Seed 1
9082 shouldFail $ fuzzBoth @Seeded.Api "finds an error using information passed in" Seeded.server
9183 (R.defaultConfig {R.seed = [(toDyn res, hash res)]})
9284 (`shouldSatisfy` isNothing)
93−
94− describe "Foo" $
85+
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" $
98− fuzzBoth @QueryParams.Api "can handle query params" QueryParams.server R.defaultConfig { R.seed = [R.hashedDyn (12::Int)] }
99− (`shouldSatisfy` isNothing)
100−
10189 describe "BuildFrom" $ do
102− describe "headers (and sum types)" $
90+ describe "headers (and sum types)" $ do
10391 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" $
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)
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)
10997 describe "Breakdown" $ do
11098 fuzzBoth @Breakdown.ProductApi "handles products" Breakdown.productServer R.defaultConfig
11199 (`shouldSatisfy` serverFailure)
112100 fuzzBoth @Breakdown.SumApi "handles sums" Breakdown.sumServer R.defaultConfig
113101 (`shouldSatisfy` serverFailure)
114− describe "flattening" $
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.
115105 fuzzBoth @Nested.FlatApi "can handle nested apis" Nested.server R.defaultConfig {R.coverageThreshold = 0.99}
116− (`shouldSatisfy` isNothing)
106+ (`shouldSatisfy` isNothing)
117107
118108serverFailure :: Maybe R.Report -> Bool
119109serverFailure = \case
@@ -137,12 +127,8 @@ deriving via (R.Atom Seeded.Seed) instance R.BuildFrom Seeded.Seed
137127deriving via (R.Atom Void) instance R.BuildFrom Void
138128
139129deriving 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−
145130
131+deriving via (R.Atom Post.FooPost) instance R.BuildFrom Post.FooPost
146132
147133deriving via (R.Compound Breakdown.Foo) instance R.Breakdown Breakdown.Foo
148134
@@ -158,7 +144,7 @@ shouldFail =
158144 ( \i ->
159145 i
160146 { itemExample = \p a cb -> do
161− r <- itemExample i p a cb
147+ r <- (itemExample i) p a cb
162148 pure
163149 r
164150 { resultStatus = case resultStatus r of