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}]
(let [[top childs] (ring/group-keys data)
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}))
compile (fn [[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}]
(let [[top childs] (group-keys data)
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}))
->endpoint (fn [p d m s]
(-> (middleware/compile-result [p d] opts s)

View file

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

View file

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

View file

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

View file

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