Skip to content

Commit

Permalink
Fix #407
Browse files Browse the repository at this point in the history
  • Loading branch information
ikitommi committed May 25, 2020
1 parent 28962e7 commit a2d8208
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/cljc/reitit/ring_coercion_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,22 @@
(let [{:keys [status]} (app invalid-request2)]
(is (= 500 status))))))))

(def or-maps-schema
[:or [:map [:x int?]] [:map [:y int?]]])

(deftest malli-coercion-test
(let [create (fn [middleware]
(ring/ring-handler
(ring/router
["/api"

["/or" {:post {:summary "accepts either of two map schemas"
:parameters {:body or-maps-schema}
:responses {200 {:body [:map [:msg string?]]}}
:handler (fn [{{{:keys [x]} :body} :parameters}]
{:status 200
:body {:msg (if x "you sent x" "you sent y")}})}}]

["/plus/:e" {:get {:parameters {:query [:map [:a {:optional true} int?]]
:body [:map [:b int?]]
:form [:map [:c [int? {:default 3}]]]
Expand Down Expand Up @@ -254,6 +265,13 @@
rrc/coerce-request-middleware
rrc/coerce-response-middleware])]

(testing "or #407"
(is (= {:status 200
:body {:msg "you sent x"}}
(app {:uri "/api/or"
:request-method :post
:body-params {:x 1}}))))

(testing "all good"
(is (= {:status 200
:body {:total 15}}
Expand Down

0 comments on commit a2d8208

Please sign in to comment.