mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 16:31:11 +00:00
Cleanup codes
This commit is contained in:
parent
3d4737b3fb
commit
b4ceaf1318
2 changed files with 24 additions and 32 deletions
|
|
@ -19,15 +19,15 @@
|
||||||
|
|
||||||
(extend-protocol ExpandArgs
|
(extend-protocol ExpandArgs
|
||||||
|
|
||||||
#?(:clj clojure.lang.Keyword
|
#?(:clj clojure.lang.Keyword
|
||||||
:cljs cljs.core.Keyword)
|
:cljs cljs.core.Keyword)
|
||||||
(expand [this] {:handler this})
|
(expand [this] {:handler this})
|
||||||
|
|
||||||
#?(:clj clojure.lang.PersistentArrayMap
|
#?(:clj clojure.lang.PersistentArrayMap
|
||||||
:cljs cljs.core.PersistentArrayMap)
|
:cljs cljs.core.PersistentArrayMap)
|
||||||
(expand [this] this)
|
(expand [this] this)
|
||||||
|
|
||||||
#?(:clj clojure.lang.PersistentHashMap
|
#?(:clj clojure.lang.PersistentHashMap
|
||||||
:cljs cljs.core.PersistentHashMap)
|
:cljs cljs.core.PersistentHashMap)
|
||||||
(expand [this] this)
|
(expand [this] this)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,37 +2,29 @@
|
||||||
(:require [clojure.test :refer [deftest testing is are]]
|
(:require [clojure.test :refer [deftest testing is are]]
|
||||||
[reitit.core :as reitit]))
|
[reitit.core :as reitit]))
|
||||||
|
|
||||||
(def routes2
|
|
||||||
["/api" {:mw [:api]}
|
|
||||||
["/ping" :kikka]
|
|
||||||
["/user/:id" {:parameters {:id String}}
|
|
||||||
["/:sub-id" {:parameters {:sub-id String}}]]
|
|
||||||
["/pong"]
|
|
||||||
["/admin" {:mw [:admin] :roles #{:admin}}
|
|
||||||
["/user" {:roles #{:user}}]
|
|
||||||
["/db" {:mw [:db]}]]])
|
|
||||||
|
|
||||||
(deftest reitit-test
|
(deftest reitit-test
|
||||||
|
|
||||||
(testing "bide sample"
|
(testing "bide sample"
|
||||||
(let [routes [["/auth/login" :auth/login]
|
(let [routes [["/auth/login" :auth/login]
|
||||||
["/auth/recovery/token/:token" :auth/recovery]
|
["/auth/recovery/token/:token" :auth/recovery]
|
||||||
["/workspace/:project-uuid/:page-uuid" :workspace/page]]]
|
["/workspace/:project-uuid/:page-uuid" :workspace/page]]
|
||||||
(is (= [["/auth/login" {:handler :auth/login}]
|
expected [["/auth/login" {:handler :auth/login}]
|
||||||
["/auth/recovery/token/:token" {:handler :auth/recovery}]
|
["/auth/recovery/token/:token" {:handler :auth/recovery}]
|
||||||
["/workspace/:project-uuid/:page-uuid" {:handler :workspace/page}]]
|
["/workspace/:project-uuid/:page-uuid" {:handler :workspace/page}]]]
|
||||||
(reitit/resolve-routes routes)))))
|
(is (= expected (reitit/resolve-routes routes)))))
|
||||||
|
|
||||||
(testing "ring sample"
|
(testing "ring sample"
|
||||||
(let [routes ["/api" {:mw [:api]}
|
(let [routes ["/api" {:mw [:api]}
|
||||||
["/ping" :kikka]
|
["/ping" :kikka]
|
||||||
["/user/:id" {:parameters {:id String}}
|
["/user/:id" {:parameters {:id String}}
|
||||||
["/:sub-id" {:parameters {:sub-id String}}]]
|
["/:sub-id" {:parameters {:sub-id String}}]]
|
||||||
["/pong"]
|
["/pong"]
|
||||||
["/admin" {:mw [:admin] :roles #{:admin}}
|
["/admin" {:mw [:admin] :roles #{:admin}}
|
||||||
["/user" {:roles #{:user}}]
|
["/user" {:roles #{:user}}]
|
||||||
["/db" {:mw [:db]}]]]]
|
["/db" {:mw [:db]}]]]
|
||||||
(is (= [["/api/ping" {:mw [:api], :handler :kikka}]
|
expected [["/api/ping" {:mw [:api], :handler :kikka}]
|
||||||
["/api/user/:id/:sub-id" {:mw [:api], :parameters {:id String, :sub-id String}}]
|
["/api/user/:id/:sub-id" {:mw [:api], :parameters {:id String, :sub-id String}}]
|
||||||
["/api/pong" {:mw [:api]}]
|
["/api/pong" {:mw [:api]}]
|
||||||
["/api/admin/user" {:mw [:api :admin], :roles #{:user}}]
|
["/api/admin/user" {:mw [:api :admin], :roles #{:user}}]
|
||||||
["/api/admin/db" {:mw [:api :admin :db], :roles #{:admin}}]]
|
["/api/admin/db" {:mw [:api :admin :db], :roles #{:admin}}]]]
|
||||||
(reitit/resolve-routes {:mw :into} routes))))))
|
(is (= expected (reitit/resolve-routes {:mw :into} routes))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue