mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 08:21:11 +00:00
Add tests for :strip and :both
This commit is contained in:
parent
b6e8a9d579
commit
da29203cc8
1 changed files with 58 additions and 20 deletions
|
|
@ -240,14 +240,14 @@
|
||||||
(is (= response (app {:request-method :options, :uri "/any"}))))))))
|
(is (= response (app {:request-method :options, :uri "/any"}))))))))
|
||||||
|
|
||||||
(deftest trailing-slash-handler-test
|
(deftest trailing-slash-handler-test
|
||||||
(testing "using :method :add"
|
(let [ok {:status 200, :body "ok"}
|
||||||
(let [ok {:status 200 :body "ok"}
|
routes [["/slash-less" {:get (constantly ok),
|
||||||
app (ring/ring-handler
|
|
||||||
(ring/router
|
|
||||||
[["/slash-less" {:get (constantly ok),
|
|
||||||
:post (constantly ok)}]
|
:post (constantly ok)}]
|
||||||
["/with-slash/" {:get (constantly ok),
|
["/with-slash/" {:get (constantly ok),
|
||||||
:post (constantly ok)}]])
|
:post (constantly ok)}]]]
|
||||||
|
(testing "using :method :add"
|
||||||
|
(let [app (ring/ring-handler
|
||||||
|
(ring/router routes)
|
||||||
(ring/redirect-trailing-slash-handler {:method :add}))]
|
(ring/redirect-trailing-slash-handler {:method :add}))]
|
||||||
|
|
||||||
(testing "exact matches work"
|
(testing "exact matches work"
|
||||||
|
|
@ -262,7 +262,45 @@
|
||||||
|
|
||||||
(testing "does not strip slashes"
|
(testing "does not strip slashes"
|
||||||
(is (= nil (app {:request-method :get, :uri "/slash-less/"})))
|
(is (= nil (app {:request-method :get, :uri "/slash-less/"})))
|
||||||
(is (= nil (app {:request-method :post, :uri "/slash-less/"})))))))
|
(is (= nil (app {:request-method :post, :uri "/slash-less/"}))))))
|
||||||
|
|
||||||
|
(testing "using :method :strip"
|
||||||
|
(let [app (ring/ring-handler
|
||||||
|
(ring/router routes)
|
||||||
|
(ring/redirect-trailing-slash-handler {:method :strip}))]
|
||||||
|
|
||||||
|
(testing "exact matches work"
|
||||||
|
(is (= ok (app {:request-method :get, :uri "/slash-less"})))
|
||||||
|
(is (= ok (app {:request-method :post, :uri "/slash-less"})))
|
||||||
|
(is (= ok (app {:request-method :get, :uri "/with-slash/"})))
|
||||||
|
(is (= ok (app {:request-method :post, :uri "/with-slash/"}))))
|
||||||
|
|
||||||
|
(testing "does not add slashes"
|
||||||
|
(is (= nil (app {:request-method :get, :uri "/with-slash"})))
|
||||||
|
(is (= nil (app {:request-method :post, :uri "/with-slash"}))))
|
||||||
|
|
||||||
|
(testing "strips slashes"
|
||||||
|
(is (= 301 (:status (app {:request-method :get, :uri "/slash-less/"}))))
|
||||||
|
(is (= 308 (:status (app {:request-method :post, :uri "/slash-less/"})))))))
|
||||||
|
|
||||||
|
(testing "without option (equivalent to using :method :both)"
|
||||||
|
(let [app (ring/ring-handler
|
||||||
|
(ring/router routes)
|
||||||
|
(ring/redirect-trailing-slash-handler))]
|
||||||
|
|
||||||
|
(testing "exact matches work"
|
||||||
|
(is (= ok (app {:request-method :get, :uri "/slash-less"})))
|
||||||
|
(is (= ok (app {:request-method :post, :uri "/slash-less"})))
|
||||||
|
(is (= ok (app {:request-method :get, :uri "/with-slash/"})))
|
||||||
|
(is (= ok (app {:request-method :post, :uri "/with-slash/"}))))
|
||||||
|
|
||||||
|
(testing "adds slashes"
|
||||||
|
(is (= 301 (:status (app {:request-method :get, :uri "/with-slash"}))))
|
||||||
|
(is (= 308 (:status (app {:request-method :post, :uri "/with-slash"})))))
|
||||||
|
|
||||||
|
(testing "strips slashes"
|
||||||
|
(is (= 301 (:status (app {:request-method :get, :uri "/slash-less/"}))))
|
||||||
|
(is (= 308 (:status (app {:request-method :post, :uri "/slash-less/"})))))))))
|
||||||
|
|
||||||
(deftest async-ring-test
|
(deftest async-ring-test
|
||||||
(let [promise #(let [value (atom ::nil)]
|
(let [promise #(let [value (atom ::nil)]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue