mirror of
https://github.com/metosin/reitit.git
synced 2025-12-18 17:01:11 +00:00
test: add test for malli coercion :humanize-opts
This commit is contained in:
parent
a4576cc622
commit
ea58100fec
1 changed files with 29 additions and 1 deletions
|
|
@ -583,7 +583,35 @@
|
||||||
:request-method :get}))]
|
: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 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
|
#?(:clj
|
||||||
(deftest per-content-type-test
|
(deftest per-content-type-test
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue