Fix tests

This commit is contained in:
Tommi Reiman 2019-04-28 17:36:43 +03:00
parent c8eaa955c3
commit c3de6ff3dd
6 changed files with 12 additions and 18 deletions

View file

@ -16,7 +16,7 @@
(defn compile-result [[path data] {:keys [::default-options-handler] :as opts}] (defn compile-result [[path data] {:keys [::default-options-handler] :as opts}]
(let [[top childs] (ring/group-keys data) (let [[top childs] (ring/group-keys data)
childs (cond-> childs childs (cond-> childs
(and (not (:options childs)) default-options-handler) (and (not (:options childs)) (not (:handler top)) default-options-handler)
(assoc :options {:no-doc true, :handler default-options-handler})) (assoc :options {:no-doc true, :handler default-options-handler}))
compile (fn [[path data] opts scope] compile (fn [[path data] opts scope]
(interceptor/compile-result [path data] opts scope)) (interceptor/compile-result [path data] opts scope))

View file

@ -31,7 +31,7 @@
(defn compile-result [[path data] {:keys [::default-options-handler] :as opts}] (defn compile-result [[path data] {:keys [::default-options-handler] :as opts}]
(let [[top childs] (group-keys data) (let [[top childs] (group-keys data)
childs (cond-> childs childs (cond-> childs
(and (not (:options childs)) default-options-handler) (and (not (:options childs)) (not (:handler top)) default-options-handler)
(assoc :options {:no-doc true, :handler default-options-handler})) (assoc :options {:no-doc true, :handler default-options-handler}))
->endpoint (fn [p d m s] ->endpoint (fn [p d m s]
(-> (middleware/compile-result [p d] opts s) (-> (middleware/compile-result [p d] opts s)

View file

@ -20,14 +20,8 @@
(s/def ::patch map?) (s/def ::patch map?)
(s/def ::endpoint
(s/keys :req-un [::rs/handler]
:opt-un [::rs/name ::rs/no-doc ::middleware]))
(s/def ::data (s/def ::data
(s/merge (s/keys :opt-un [::rs/handler ::rs/name ::rs/no-doc ::middleware]))
::endpoint
(s/map-of #{:get :head :post :put :delete :connect :options :trace :patch} map?)))
;; ;;
;; Validator ;; Validator

View file

@ -495,11 +495,11 @@
(fn [{:keys [::r/router]}] (fn [{:keys [::r/router]}]
(is router)) (is router))
{:executor sieppari/executor}) {:executor sieppari/executor})
{})) {}))
(testing "3-arity" (testing "3-arity"
((http/ring-handler ((http/ring-handler
(http/router []) (http/router [])
(fn [{:keys [::r/router]}] (fn [{:keys [::r/router]}]
(is router)) (is router))
{:executor sieppari/executor}) {:executor sieppari/executor})
{} ::respond ::raise))) {} ::respond ::raise)))

View file

@ -21,13 +21,13 @@
(testing "with default spec validates :name, :handler and :middleware" (testing "with default spec validates :name, :handler and :middleware"
(is (thrown-with-msg? (is (thrown-with-msg?
ExceptionInfo ExceptionInfo
#":reitit.ring.spec/invalid-route-data" #"Invalid route data"
(ring/router (ring/router
["/api" {:handler "identity"}] ["/api" {:handler "identity"}]
{:validate rrs/validate}))) {:validate rrs/validate})))
(is (thrown-with-msg? (is (thrown-with-msg?
ExceptionInfo ExceptionInfo
#":reitit.ring.spec/invalid-route-data" #"Invalid route data"
(ring/router (ring/router
["/api" {:handler identity ["/api" {:handler identity
:name "kikka"}] :name "kikka"}]
@ -36,7 +36,7 @@
(testing "all endpoints are validated" (testing "all endpoints are validated"
(is (thrown-with-msg? (is (thrown-with-msg?
ExceptionInfo ExceptionInfo
#":reitit.ring.spec/invalid-route-data" #"Invalid route data"
(ring/router (ring/router
["/api" {:patch {:handler "identity"}}] ["/api" {:patch {:handler "identity"}}]
{:validate rrs/validate})))) {:validate rrs/validate}))))
@ -69,7 +69,7 @@
(handler request)))}]}}))) (handler request)))}]}})))
(is (thrown-with-msg? (is (thrown-with-msg?
ExceptionInfo ExceptionInfo
#":reitit.ring.spec/invalid-route-data" #"Invalid route data"
(ring/router (ring/router
["/api" {:get {:handler identity ["/api" {:get {:handler identity
:roles #{:adminz}}}] :roles #{:adminz}}}]
@ -113,7 +113,7 @@
(is (thrown-with-msg? (is (thrown-with-msg?
ExceptionInfo ExceptionInfo
#":reitit.ring.spec/invalid-route-data" #"Invalid route data"
(ring/router (ring/router
["/api" ["/api"
["/plus/:e" ["/plus/:e"

View file

@ -570,10 +570,10 @@
(ring/router []) (ring/router [])
(fn [{:keys [::r/router]}] (fn [{:keys [::r/router]}]
(is router))) (is router)))
{})) {}))
(testing "3-arity" (testing "3-arity"
((ring/ring-handler ((ring/ring-handler
(ring/router []) (ring/router [])
(fn [{:keys [::r/router]} _ _] (fn [{:keys [::r/router]} _ _]
(is router))) (is router)))
{} ::respond ::raise))) {} ::respond ::raise)))