From d724906cf6ed789e2dcead20967ac6371367357a Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Thu, 27 Jul 2023 14:23:16 +0000 Subject: Release 1.3.4. --- test/ruuter/core_test.cljc | 63 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 19 deletions(-) (limited to 'test/ruuter') diff --git a/test/ruuter/core_test.cljc b/test/ruuter/core_test.cljc index 1164124..7464fe0 100644 --- a/test/ruuter/core_test.cljc +++ b/test/ruuter/core_test.cljc @@ -49,22 +49,47 @@ (deftest route+req->response-test (let [testfn #'ruuter/route+req->response] - (testing "Returning a map when the response is a direct map" - (= {:status 200 - :body "Hello."} - (testfn {:path "/hello" - :response {:status 200 - :body "Hello."}} - {:uri "/hello"}))) - (testing "Returning a map via a fn when the response is a fn" - (= {:status 200 - :body "Hello, world."} - (testfn {:path "/hello/:who" - :response (fn [req] - {:status 200 - :body (str "Hello, " (:who (:params req)))})} - {:uri "/hello/world"}))) - (testing "Returning an error map when route is invalid" - (= {:status 404 - :body "Not found."} - (testfn nil {:uri "/hello"}))))) + (testing "Returns a map when the response is a direct map" + (is (= {:status 200 + :body "Hello."} + (testfn {:path "/hello" + :response {:status 200 + :body "Hello."}} + {:uri "/hello"})))) + (testing "Returns a map via a fn when the response is a fn" + (is (= {:status 200 + :body "Hello, world."} + (testfn {:path "/hello/:who" + :response (fn [req] + {:status 200 + :body (str "Hello, " (:who (:params req)) ".")})} + {:uri "/hello/world"})))) + (testing "Returns an error map when route is invalid" + (is (= {:status 404 + :body "Not found."} + (testfn nil {:uri "/hello"})))) + + (testing "Returns a combined :params map" + (let [params (atom nil)] + (testfn {:path "/hello/:who" + :response (fn [req] + (reset! params (:params req)) + {:status 200 + :body ""})} + {:uri "/hello/world" + :params {:some-params :from-elsewhere}}) + (is (= {:who "world" + :some-params :from-elsewhere} + @params)))) + + (testing "Overwrites :params if needed" + (let [params (atom nil)] + (testfn {:path "/hello/:who" + :response (fn [req] + (reset! params (:params req)) + {:status 200 + :body ""})} + {:uri "/hello/world" + :params {:who "overwritten"}}) + (is (= {:who "overwritten"} + @params)))))) -- cgit v1.2.3