summaryrefslogtreecommitdiff
path: root/test/ruuter/core_test.clj
diff options
context:
space:
mode:
authorAsko Nõmm <asko@bien.ee>2021-10-03 17:49:46 -0300
committerAsko Nõmm <asko@bien.ee>2021-10-03 17:49:46 -0300
commit06a5272e1dc9619cf5bf5ccaf690e2d993aedeec (patch)
treec128ca0cb3fc1739bc669f63b39c31555b8ce3c0 /test/ruuter/core_test.clj
parent0c037271d6d11641e095bc53728f8bf60db50e0e (diff)
Make test runnable for CLJS and CLJ
Diffstat (limited to 'test/ruuter/core_test.clj')
-rw-r--r--test/ruuter/core_test.clj62
1 files changed, 0 insertions, 62 deletions
diff --git a/test/ruuter/core_test.clj b/test/ruuter/core_test.clj
deleted file mode 100644
index 4f60054..0000000
--- a/test/ruuter/core_test.clj
+++ /dev/null
@@ -1,62 +0,0 @@
-(ns ruuter.core-test
- (:require [clojure.test :refer :all]
- [ruuter.core :as ruuter]))
-
-
-(deftest path+uri->path-params-test
- (let [testfn #'ruuter/path+uri->path-params]
- (testing "No params returns an empty map"
- (is (= {}
- (testfn "/hello/world" "/hello/world"))))
- (testing "Having a param returns a map accordingly"
- (is (= {:who "world"}
- (testfn "/hello/:who" "/hello/world"))))
- (testing "Multiple params returns a map accordingly"
- (is (= {:who "world"
- :why "because"}
- (testfn "/hello/:who/:why" "/hello/world/because"))))
- (testing "Multiple params, but one is optional"
- (is (= {:who "world"}
- (testfn "/hello/:who/:why?" "/hello/world")))
- (is (= {:who "world"
- :why "because"}
- (testfn "/hello/:who/:why?" "/hello/world/because"))))))
-
-
-(deftest match-route-test
- (let [testfn #'ruuter/match-route]
- (testing "Find a route that exists"
- (is (= {:path "/hello"
- :method :get
- :response {:status 200
- :body "Hello."}}
- (testfn [{:path "/hello"
- :method :get
- :response {:status 200
- :body "Hello."}}] "/hello" :get))))
- (testing "No route found"
- (is (= nil
- (testfn [] "/hello" :get))))))
-
-
-(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"})))))