mirror of
https://github.com/metosin/reitit.git
synced 2025-12-23 18:41:11 +00:00
Cleanup
This commit is contained in:
parent
708fa24590
commit
07bcd2ea59
5 changed files with 29 additions and 31 deletions
|
|
@ -1,7 +1,6 @@
|
|||
(ns reitit.spec
|
||||
(:require [clojure.spec.alpha :as s]
|
||||
[clojure.spec.gen.alpha :as gen]
|
||||
[clojure.string :as str]
|
||||
[reitit.core :as reitit]))
|
||||
|
||||
;;
|
||||
|
|
|
|||
|
|
@ -48,4 +48,3 @@
|
|||
(is (= nil (coercion/coerce! m))))
|
||||
(let [m (r/match-by-path r "/none/kikka/abba")]
|
||||
(is (= nil (coercion/coerce! m))))))))
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
(is (= name (r/router-name router)))
|
||||
(is (= [["/api/ipa/:size" {:name ::beer} nil]]
|
||||
(r/routes router)))
|
||||
(is (= true (map? (r/options router))))
|
||||
(is (map? (r/options router)))
|
||||
(is (= (r/map->Match
|
||||
{:template "/api/ipa/:size"
|
||||
:data {:name ::beer}
|
||||
|
|
@ -39,7 +39,7 @@
|
|||
:required #{:size}
|
||||
:params nil})
|
||||
(r/match-by-name router ::beer)))
|
||||
(is (= true (r/partial-match? (r/match-by-name router ::beer))))
|
||||
(is (r/partial-match? (r/match-by-name router ::beer)))
|
||||
(is (thrown-with-msg?
|
||||
ExceptionInfo
|
||||
#"^missing path-params for route /api/ipa/:size -> \#\{:size\}$"
|
||||
|
|
@ -72,7 +72,7 @@
|
|||
(is (= name (r/router-name router)))
|
||||
(is (= [["/api/ipa/large" {:name ::beer} nil]]
|
||||
(r/routes router)))
|
||||
(is (= true (map? (r/options router))))
|
||||
(is (map? (r/options router)))
|
||||
(is (= (r/map->Match
|
||||
{:template "/api/ipa/large"
|
||||
:data {:name ::beer}
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@
|
|||
|
||||
(deftest route-data-validation-test
|
||||
(testing "validation is turned off by default"
|
||||
(is (true? (r/router?
|
||||
(r/router
|
||||
["/api" {:handler "identity"}])))))
|
||||
(is (r/router?
|
||||
(r/router
|
||||
["/api" {:handler "identity"}]))))
|
||||
|
||||
(testing "with default spec validates :name, :handler and :middleware"
|
||||
(is (thrown-with-msg?
|
||||
|
|
@ -40,11 +40,11 @@
|
|||
{:validate rrs/validate-spec!}))))
|
||||
|
||||
(testing "spec can be overridden"
|
||||
(is (true? (r/router?
|
||||
(ring/router
|
||||
["/api" {:handler "identity"}]
|
||||
{:spec (s/spec any?)
|
||||
:validate rrs/validate-spec!}))))
|
||||
(is (r/router?
|
||||
(ring/router
|
||||
["/api" {:handler "identity"}]
|
||||
{:spec (s/spec any?)
|
||||
:validate rrs/validate-spec!})))
|
||||
|
||||
(testing "predicates are not allowed"
|
||||
(is (thrown-with-msg?
|
||||
|
|
@ -56,15 +56,15 @@
|
|||
:validate rrs/validate-spec!})))))
|
||||
|
||||
(testing "middleware can contribute to specs"
|
||||
(is (true? (r/router?
|
||||
(ring/router
|
||||
["/api" {:get {:handler identity
|
||||
:roles #{:admin}}}]
|
||||
{:validate rrs/validate-spec!
|
||||
:data {:middleware [{:spec (s/keys :opt-un [::roles])
|
||||
:wrap (fn [handler]
|
||||
(fn [request]
|
||||
(handler request)))}]}}))))
|
||||
(is (r/router?
|
||||
(ring/router
|
||||
["/api" {:get {:handler identity
|
||||
:roles #{:admin}}}]
|
||||
{:validate rrs/validate-spec!
|
||||
:data {:middleware [{:spec (s/keys :opt-un [::roles])
|
||||
:wrap (fn [handler]
|
||||
(fn [request]
|
||||
(handler request)))}]}})))
|
||||
(is (thrown-with-msg?
|
||||
ExceptionInfo
|
||||
#"Invalid route data"
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
(testing "route-data"
|
||||
(are [data]
|
||||
(is (= true (r/router? (r/router data))))
|
||||
(is (r/router? (r/router data)))
|
||||
|
||||
["/api" {}]
|
||||
|
||||
|
|
@ -45,12 +45,12 @@
|
|||
["/ipa"]])))
|
||||
|
||||
(testing "routes conform to spec (can't spec protocol functions)"
|
||||
(is (= true (s/valid? ::rs/routes (r/routes (r/router ["/ping"]))))))
|
||||
(is (s/valid? ::rs/routes (r/routes (r/router ["/ping"])))))
|
||||
|
||||
(testing "options"
|
||||
|
||||
(are [opts]
|
||||
(is (= true (r/router? (r/router ["/api"] opts))))
|
||||
(is (r/router? (r/router ["/api"] opts)))
|
||||
|
||||
{:path "/"}
|
||||
{:data {}}
|
||||
|
|
@ -78,8 +78,8 @@
|
|||
|
||||
(deftest route-data-validation-test
|
||||
(testing "validation is turned off by default"
|
||||
(is (true? (r/router? (r/router
|
||||
["/api" {:handler "identity"}])))))
|
||||
(is (r/router? (r/router
|
||||
["/api" {:handler "identity"}]))))
|
||||
|
||||
(testing "with default spec validates :name and :handler"
|
||||
(is (thrown-with-msg?
|
||||
|
|
@ -96,7 +96,7 @@
|
|||
{:validate rs/validate-spec!}))))
|
||||
|
||||
(testing "spec can be overridden"
|
||||
(is (true? (r/router? (r/router
|
||||
["/api" {:handler "identity"}]
|
||||
{:spec any?
|
||||
:validate rs/validate-spec!}))))))
|
||||
(is (r/router? (r/router
|
||||
["/api" {:handler "identity"}]
|
||||
{:spec any?
|
||||
:validate rs/validate-spec!})))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue