mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11:11 +00:00
Polish tests
This commit is contained in:
parent
91a2945578
commit
9200afe814
1 changed files with 38 additions and 39 deletions
|
|
@ -179,40 +179,39 @@
|
||||||
(is (thrown-with-msg?
|
(is (thrown-with-msg?
|
||||||
ExceptionInfo
|
ExceptionInfo
|
||||||
#"Response coercion failed"
|
#"Response coercion failed"
|
||||||
(app invalid-request2))))
|
(app invalid-request2))))))
|
||||||
|
|
||||||
(testing "with exception handling"
|
(testing "with exception handling"
|
||||||
(let [app (create [rrc/coerce-exceptions-middleware
|
(let [app (create [rrc/coerce-exceptions-middleware
|
||||||
rrc/coerce-request-middleware
|
rrc/coerce-request-middleware
|
||||||
rrc/coerce-response-middleware])]
|
rrc/coerce-response-middleware])]
|
||||||
|
|
||||||
(testing "all good"
|
(testing "all good"
|
||||||
(is (= {:status 200
|
(is (= {:status 200
|
||||||
:body {:total 15}}
|
:body {:total 15}}
|
||||||
(app valid-request1))))
|
(app valid-request1))))
|
||||||
|
|
||||||
(testing "invalid request"
|
(testing "invalid request"
|
||||||
(let [{:keys [status]} (app invalid-request1)]
|
(let [{:keys [status]} (app invalid-request1)]
|
||||||
(is (= 400 status))))
|
(is (= 400 status))))
|
||||||
|
|
||||||
(testing "invalid response"
|
(testing "invalid response"
|
||||||
(let [{:keys [status]} (app invalid-request2)]
|
(let [{:keys [status]} (app invalid-request2)]
|
||||||
(is (= 500 status))))))))))
|
(is (= 500 status))))))))
|
||||||
|
|
||||||
(deftest malli-coercion-test
|
(deftest malli-coercion-test
|
||||||
(let [create (fn [middleware]
|
(let [create (fn [middleware]
|
||||||
(ring/ring-handler
|
(ring/ring-handler
|
||||||
(ring/router
|
(ring/router
|
||||||
["/api"
|
["/api"
|
||||||
["/plus/:e"
|
["/plus/:e" {:get {:parameters {:query [:map [:a {:optional true} int?]]
|
||||||
{:get {:parameters {:query [:map [:a {:optional true} int?]]
|
:body [:map [:b int?]]
|
||||||
:body [:map [:b int?]]
|
:form [:map [:c [int? {:default 3}]]]
|
||||||
:form [:map [:c [int? {:default 3}]]]
|
:header [:map [:d int?]]
|
||||||
:header [:map [:d int?]]
|
:path [:map [:e int?]]}
|
||||||
:path [:map [:e int?]]}
|
:responses {200 {:body [:map [:total pos-int?]]}
|
||||||
:responses {200 {:body [:map [:total pos-int?]]}
|
500 {:description "fail"}}
|
||||||
500 {:description "fail"}}
|
:handler handler}}]]
|
||||||
:handler handler}}]]
|
|
||||||
{:data {:middleware middleware
|
{:data {:middleware middleware
|
||||||
:coercion malli/coercion}})))]
|
:coercion malli/coercion}})))]
|
||||||
|
|
||||||
|
|
@ -248,25 +247,25 @@
|
||||||
(is (thrown-with-msg?
|
(is (thrown-with-msg?
|
||||||
ExceptionInfo
|
ExceptionInfo
|
||||||
#"Response coercion failed"
|
#"Response coercion failed"
|
||||||
(app invalid-request2))))
|
(app invalid-request2))))))
|
||||||
|
|
||||||
(testing "with exception handling"
|
(testing "with exception handling"
|
||||||
(let [app (create [rrc/coerce-exceptions-middleware
|
(let [app (create [rrc/coerce-exceptions-middleware
|
||||||
rrc/coerce-request-middleware
|
rrc/coerce-request-middleware
|
||||||
rrc/coerce-response-middleware])]
|
rrc/coerce-response-middleware])]
|
||||||
|
|
||||||
(testing "all good"
|
(testing "all good"
|
||||||
(is (= {:status 200
|
(is (= {:status 200
|
||||||
:body {:total 15}}
|
:body {:total 15}}
|
||||||
(app valid-request1))))
|
(app valid-request1))))
|
||||||
|
|
||||||
(testing "invalid request"
|
(testing "invalid request"
|
||||||
(let [{:keys [status]} (app invalid-request1)]
|
(let [{:keys [status]} (app invalid-request1)]
|
||||||
(is (= 400 status))))
|
(is (= 400 status))))
|
||||||
|
|
||||||
(testing "invalid response"
|
(testing "invalid response"
|
||||||
(let [{:keys [status]} (app invalid-request2)]
|
(let [{:keys [status]} (app invalid-request2)]
|
||||||
(is (= 500 status))))))))))
|
(is (= 500 status))))))))
|
||||||
|
|
||||||
#?(:clj
|
#?(:clj
|
||||||
(deftest muuntaja-test
|
(deftest muuntaja-test
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue