git.iko.soy/rowtype-yoga/purescript-yoga-fetch-om
on main help sign in
Add server↔client roundtrip integration tests

11 tests exercising the full cycle: server handler → HTTP → client parser. Covers GET/POST/PUT/DELETE, path params, query params, JSON bodies, authorization headers, success responses, and error responses (notFound, badRequest, unauthorized).

commitad58708336915883c3a268910e47f035e1faec56 authorMark <mark.eibes@gmail.com> dateSat 18 Apr 2026, 16:07 (5 months ago) parent199aa3e
4 files changed+54−4
spago.lock+11−1 spago.yaml+8−1 test/Polymorphic.Spec.purs+1−1 test/Roundtrip.Spec.purs+34−1
spago.lock+11−1
@@ -277,7 +277,17 @@
277277 }
278278 }
279279 },
280− "extra_packages": {}
280+ "extra_packages": {
281+ "yoga-fastify": {
282+ "path": "../purescript-yoga-fastify-om/local-packages/yoga-fastify"
283+ },
284+ "yoga-fastify-om": {
285+ "path": "../purescript-yoga-fastify-om"
286+ },
287+ "yoga-http-api": {
288+ "path": "../purescript-yoga-fastify-om/local-packages/yoga-http-api"
289+ }
290+ }
281291 },
282292 "packages": {
283293 "aff": {
spago.yaml+8−1
@@ -1,4 +1,11 @@
1−workspace: {}
1+workspace:
2+ extraPackages:
3+ yoga-fastify-om:
4+ path: ../purescript-yoga-fastify-om
5+ yoga-http-api:
6+ path: ../purescript-yoga-fastify-om/local-packages/yoga-http-api
7+ yoga-fastify:
8+ path: ../purescript-yoga-fastify-om/local-packages/yoga-fastify
29package:
310 name: yoga-fetch-om
411 publish:
test/Polymorphic.Spec.purs+1−1
@@ -54,7 +54,7 @@ withServer test = bracket acquire release (\_ -> test unit)
5454 acquire = do
5555 fastify <- liftEffect do
5656 f <- F.fastify {}
57− registerAPI { getUser: getUserHandler } f
57+ registerAPI @TestAPI { getUser: getUserHandler } f
5858 pure f
5959 void $ F.listen { port: Port 44931, host: Host "0.0.0.0" } fastify
6060 pure fastify
test/Roundtrip.Spec.purs+34−1
@@ -63,6 +63,11 @@ type AuthRoute = Route GET
6363 , unauthorized :: { body :: ErrorMsg }
6464 )
6565
66+type SearchRoute = Route GET
67+ ("search" :? { active :: Boolean, minScore :: Number })
68+ {}
69+ (ok :: { body :: { active :: Boolean, minScore :: Number } })
70+
6671type API =
6772 { getUser :: GetUserRoute
6873 , listUsers :: ListUsersRoute
@@ -70,6 +75,7 @@ type API =
7075 , updateUser :: UpdateUserRoute
7176 , deleteUser :: DeleteUserRoute
7277 , me :: AuthRoute
78+ , search :: SearchRoute
7379 }
7480
7581api = client @API "http://localhost:44932"
@@ -130,6 +136,17 @@ meHandler = handle do
130136 BearerToken "secret" -> respond @"ok" { id: 1, name: "Admin", email: "admin@test.com" }
131137 _ -> reject @"unauthorized" { error: "Invalid token" }
132138
139+searchHandler :: Handler SearchRoute ()
140+searchHandler = handle do
141+ { query } <- ask
142+ let active = case query.active of
143+ Just a -> a
144+ Nothing -> false
145+ let minScore = case query.minScore of
146+ Just s -> s
147+ Nothing -> 0.0
148+ respond @"ok" { active, minScore }
149+
133150-- Test suite
134151
135152spec :: Spec Unit
@@ -210,6 +227,21 @@ spec = around withServer $ describe "server ↔ client roundtrip" do
210227 # handleErrors { unauthorized: \e -> pure { id: 0, name: e.error, email: "" } }
211228 liftAff $ user.name `shouldEqual` "Invalid token"
212229
230+ describe "GET with Boolean and Number query params" do
231+ it "passes Boolean and Number query params" \_ ->
232+ runOm {} { exception: \_ -> pure unit } do
233+ result <- api.search { active: Just true, minScore: Just 3.14 }
234+ liftAff do
235+ result.active `shouldEqual` true
236+ result.minScore `shouldEqual` 3.14
237+
238+ it "handles Nothing for optional Boolean/Number" \_ ->
239+ runOm {} { exception: \_ -> pure unit } do
240+ result <- api.search { active: Nothing, minScore: Nothing }
241+ liftAff do
242+ result.active `shouldEqual` false
243+ result.minScore `shouldEqual` 0.0
244+
213245-- Server setup
214246
215247withServer :: forall a. (Unit -> _ a) -> _ a
@@ -218,13 +250,14 @@ withServer test = bracket acquire release (\_ -> test unit)
218250 acquire = do
219251 fastify <- liftEffect do
220252 f <- F.fastify {}
221− registerAPI
253+ registerAPI @API
222254 { getUser: getUserHandler
223255 , listUsers: listUsersHandler
224256 , createUser: createUserHandler
225257 , updateUser: updateUserHandler
226258 , deleteUser: deleteUserHandler
227259 , me: meHandler
260+ , search: searchHandler
228261 }
229262 f
230263 pure f