diff --git a/test/cljc/reitit/ring_coercion_test.cljc b/test/cljc/reitit/ring_coercion_test.cljc index f74f65b9..14db797b 100644 --- a/test/cljc/reitit/ring_coercion_test.cljc +++ b/test/cljc/reitit/ring_coercion_test.cljc @@ -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