test: add test for malli coercion :humanize-opts

This commit is contained in:
Joel Kaasinen 2025-11-14 13:51:23 +02:00
parent a4576cc622
commit ea58100fec
No known key found for this signature in database

View file

@ -583,7 +583,35 @@
:request-method :get}))]
(is (= {:status 200, :body {:total "FOO: this, BAR: that"}} (call m/schema custom-meta-merge-checking-schema)))
(is (= {:status 200, :body {:total "FOO: this, BAR: that"}} (call identity custom-meta-merge-checking-parameters)))))))
(is (= {:status 200, :body {:total "FOO: this, BAR: that"}} (call identity custom-meta-merge-checking-parameters)))))
(testing "options"
(let [->app (fn [options]
(ring/ring-handler
(ring/router
["/api" {:get {:parameters {:body [:map
[:i :int]
[:x :string]]}
:handler (fn [{{:keys [body]} :parameters}]
{:status 200 :body {}})}}]
{:data {:middleware [rrc/coerce-exceptions-middleware
rrc/coerce-request-middleware
rrc/coerce-response-middleware]
:coercion (malli/create options)}})))
request {:uri "/api"
:request-method :get
:muuntaja/request {:format "application/json"}}]
(testing "humanize options"
(is (= {:i ["should be an integer"] :x ["missing required key"]}
(-> ((->app nil) (assoc request :body-params {:i "x"}))
:body
:humanized)))
(is (= {:i ["SHOULD INT"] :x ["MISSING"]}
(-> ((->app {:humanize-opts {:errors {:int {:error/message {:en "SHOULD INT"}}
:malli.core/missing-key {:error/message {:en "MISSING"}}}}})
(assoc request :body-params {:i "x"}))
:body
:humanized))))))))
#?(:clj
(deftest per-content-type-test