This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-03
Channels
- # announcements (21)
- # aws (6)
- # babashka (28)
- # beginners (39)
- # biff (1)
- # calva (23)
- # cider (5)
- # clj-kondo (108)
- # clojure (11)
- # clojure-europe (17)
- # clojure-nl (2)
- # clojure-nlp (10)
- # clojure-uk (8)
- # clojurescript (29)
- # community-development (4)
- # conjure (20)
- # css (3)
- # datalevin (9)
- # datomic (3)
- # events (2)
- # figwheel-main (11)
- # fulcro (36)
- # honeysql (7)
- # humbleui (5)
- # interceptors (4)
- # introduce-yourself (3)
- # jobs (1)
- # lsp (51)
- # malli (1)
- # meander (71)
- # minecraft (8)
- # other-languages (18)
- # pathom (15)
- # polylith (25)
- # portal (10)
- # re-frame (5)
- # reitit (15)
- # releases (1)
- # remote-jobs (1)
- # shadow-cljs (11)
- # tools-deps (27)
anyone got any tests that call a router, passing a json body and handling it ? I am noting that my route is not decoding the json so think I am missing a step and would like to see some examples wondering if its something silly like some data I am not sending
then (-> (request :post "/your/route") (json-body {:your body}) your-handler)
will invoke the ring handler on it and you can test yourself
Then it's up to you if you want to use example based testing, or even generative tests
I actually just got it working, not sure why but I had muuntaja specified in the router config and it was messing up things
(def test-router
(->
(ring/ring-handler
(ring/router [["/test"
["/cors" {:get {:middleware [cors-headers]
:handler (fn [_] {:status 200 :body "ok"})}}]
["/cache" {:get {:middleware [cache-header-one-hour]
:handler (fn [_] {:status 200 :body "ok"})}}]
["/pubsub" {:post {:summary "test"
:parameters {:body [:map {:closed false}]}
:middleware [decode-pubsub-json-middleware]
:handler (fn [payload] {:status 200 :body (-> payload :parameters :body)})}}]]]
{:data {:coercion reitit.coercion.malli/coercion
:middleware [parameters/parameters-middleware
muuntaja/format-negotiate-middleware
muuntaja/format-response-middleware
muuntaja/format-request-middleware
coercion/coerce-response-middleware
coercion/coerce-request-middleware
coercion/coerce-exceptions-middleware]}}))))
(test-router
{:uri "/test/pubsub" :request-method :post
:content-type "application/json"
:body-params {:message {:data "decode"}})