mirror of
https://github.com/metosin/reitit.git
synced 2026-02-20 01:26:03 +00:00
name the doseq-tests
This commit is contained in:
parent
b1404ada6d
commit
0728154751
1 changed files with 68 additions and 64 deletions
|
|
@ -606,70 +606,74 @@
|
||||||
{:request any? :response (clojure.spec.alpha/spec #{:end})}
|
{:request any? :response (clojure.spec.alpha/spec #{:end})}
|
||||||
{:request any? :response (clojure.spec.alpha/spec #{:default})}]]]
|
{:request any? :response (clojure.spec.alpha/spec #{:default})}]]]
|
||||||
(testing (str coercion)
|
(testing (str coercion)
|
||||||
(doseq [app [(ring/ring-handler
|
(doseq [{:keys [name app]}
|
||||||
(ring/router
|
[{:name "using top-level :body"
|
||||||
["/foo" {:post {:request {:content {"application/json" {:schema json-request}
|
:app (ring/ring-handler
|
||||||
"application/edn" {:schema edn-request}}
|
(ring/router
|
||||||
:body default-request}
|
["/foo" {:post {:request {:content {"application/json" {:schema json-request}
|
||||||
:responses {200 {:content {"application/json" {:schema json-response}
|
"application/edn" {:schema edn-request}}
|
||||||
"application/edn" {:schema edn-response}}
|
:body default-request}
|
||||||
:body default-response}}
|
:responses {200 {:content {"application/json" {:schema json-response}
|
||||||
:handler (fn [req]
|
"application/edn" {:schema edn-response}}
|
||||||
{:status 200
|
:body default-response}}
|
||||||
:body (-> req :parameters :request)})}}]
|
:handler (fn [req]
|
||||||
{:validate reitit.ring.spec/validate
|
{:status 200
|
||||||
:data {:middleware [rrc/coerce-request-middleware
|
:body (-> req :parameters :request)})}}]
|
||||||
rrc/coerce-response-middleware]
|
{:validate reitit.ring.spec/validate
|
||||||
:coercion coercion}}))
|
:data {:middleware [rrc/coerce-request-middleware
|
||||||
(ring/ring-handler
|
rrc/coerce-response-middleware]
|
||||||
(ring/router
|
:coercion coercion}}))}
|
||||||
["/foo" {:post {:request {:content {"application/json" {:schema json-request}
|
{:name "using :default content"
|
||||||
"application/edn" {:schema edn-request}
|
:app (ring/ring-handler
|
||||||
:default {:schema default-request}}
|
(ring/router
|
||||||
:body json-request} ;; not applied as :default exists
|
["/foo" {:post {:request {:content {"application/json" {:schema json-request}
|
||||||
:responses {200 {:content {"application/json" {:schema json-response}
|
"application/edn" {:schema edn-request}
|
||||||
"application/edn" {:schema edn-response}
|
:default {:schema default-request}}
|
||||||
:default {:schema default-response}}
|
:body json-request} ;; not applied as :default exists
|
||||||
:body json-response}} ;; not applied as :default exists
|
:responses {200 {:content {"application/json" {:schema json-response}
|
||||||
:handler (fn [req]
|
"application/edn" {:schema edn-response}
|
||||||
{:status 200
|
:default {:schema default-response}}
|
||||||
:body (-> req :parameters :request)})}}]
|
:body json-response}} ;; not applied as :default exists
|
||||||
{:validate reitit.ring.spec/validate
|
:handler (fn [req]
|
||||||
:data {:middleware [rrc/coerce-request-middleware
|
{:status 200
|
||||||
rrc/coerce-response-middleware]
|
:body (-> req :parameters :request)})}}]
|
||||||
:coercion coercion}}))]]
|
{:validate reitit.ring.spec/validate
|
||||||
(let [call (fn [request]
|
:data {:middleware [rrc/coerce-request-middleware
|
||||||
(try
|
rrc/coerce-response-middleware]
|
||||||
(app request)
|
:coercion coercion}}))}]]
|
||||||
(catch ExceptionInfo e
|
(testing name
|
||||||
(select-keys (ex-data e) [:type :in]))))
|
(let [call (fn [request]
|
||||||
request (fn [request-format response-format body]
|
(try
|
||||||
{:request-method :post
|
(app request)
|
||||||
:uri "/foo"
|
(catch ExceptionInfo e
|
||||||
:muuntaja/request {:format request-format}
|
(select-keys (ex-data e) [:type :in]))))
|
||||||
:muuntaja/response {:format response-format}
|
request (fn [request-format response-format body]
|
||||||
:body-params body})]
|
{:request-method :post
|
||||||
(testing "succesful call"
|
:uri "/foo"
|
||||||
(is (= {:status 200 :body {:request :json, :response :json}}
|
:muuntaja/request {:format request-format}
|
||||||
(call (request "application/json" "application/json" {:request :json :response :json}))))
|
:muuntaja/response {:format response-format}
|
||||||
(is (= {:status 200 :body {:request :edn, :response :json}}
|
:body-params body})]
|
||||||
(call (request "application/edn" "application/json" {:request :edn :response :json}))))
|
(testing "succesful call"
|
||||||
(is (= {:status 200 :body {:request :default, :response :default}}
|
(is (= {:status 200 :body {:request :json, :response :json}}
|
||||||
(call (request "application/transit" "application/transit" {:request :default :response :default})))))
|
(call (request "application/json" "application/json" {:request :json :response :json}))))
|
||||||
(testing "request validation fails"
|
(is (= {:status 200 :body {:request :edn, :response :json}}
|
||||||
(is (= {:type :reitit.coercion/request-coercion :in [:request :body-params]}
|
(call (request "application/edn" "application/json" {:request :edn :response :json}))))
|
||||||
(call (request "application/edn" "application/json" {:request :json :response :json}))))
|
(is (= {:status 200 :body {:request :default, :response :default}}
|
||||||
(is (= {:type :reitit.coercion/request-coercion :in [:request :body-params]}
|
(call (request "application/transit" "application/transit" {:request :default :response :default})))))
|
||||||
(call (request "application/json" "application/json" {:request :edn :response :json}))))
|
(testing "request validation fails"
|
||||||
(is (= {:type :reitit.coercion/request-coercion :in [:request :body-params]}
|
(is (= {:type :reitit.coercion/request-coercion :in [:request :body-params]}
|
||||||
(call (request "application/transit" "application/json" {:request :edn :response :json})))))
|
(call (request "application/edn" "application/json" {:request :json :response :json}))))
|
||||||
(testing "response validation fails"
|
(is (= {:type :reitit.coercion/request-coercion :in [:request :body-params]}
|
||||||
(is (= {:type :reitit.coercion/response-coercion :in [:response :body]}
|
(call (request "application/json" "application/json" {:request :edn :response :json}))))
|
||||||
(call (request "application/json" "application/json" {:request :json :response :edn}))))
|
(is (= {:type :reitit.coercion/request-coercion :in [:request :body-params]}
|
||||||
(is (= {:type :reitit.coercion/response-coercion :in [:response :body]}
|
(call (request "application/transit" "application/json" {:request :edn :response :json})))))
|
||||||
(call (request "application/json" "application/edn" {:request :json :response :json}))))
|
(testing "response validation fails"
|
||||||
(is (= {:type :reitit.coercion/response-coercion :in [:response :body]}
|
(is (= {:type :reitit.coercion/response-coercion :in [:response :body]}
|
||||||
(call (request "application/json" "application/transit" {:request :json :response :json}))))))))))
|
(call (request "application/json" "application/json" {:request :json :response :edn}))))
|
||||||
|
(is (= {:type :reitit.coercion/response-coercion :in [:response :body]}
|
||||||
|
(call (request "application/json" "application/edn" {:request :json :response :json}))))
|
||||||
|
(is (= {:type :reitit.coercion/response-coercion :in [:response :body]}
|
||||||
|
(call (request "application/json" "application/transit" {:request :json :response :json})))))))))))
|
||||||
|
|
||||||
|
|
||||||
#?(:clj
|
#?(:clj
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue