add tests for routing

integration-tests
Josha von Gizycki 7 years ago
parent 4aa80950e5
commit 554e69d914

@ -30,20 +30,23 @@
:params params
:id id}))))))
(defn parse-path [path params]
(reduce-kv
(fn [new-path param-id param-value]
(string/replace
new-path
(str ":" (name param-id))
(str param-value)))
path
params))
(defn path
([id]
(path id {}))
([id params]
(let [path (id @all-routes)]
(check-params id path params)
(reduce-kv
(fn [new-path param-id param-value]
(string/replace
new-path
(str ":" (name param-id))
param-value))
path
params))))
(parse-path path params))))
(defn raw-path [id]
(id @all-routes))

@ -0,0 +1,17 @@
(ns wanijo.framework.routing-test
(:require [clojure.test :refer :all]
[wanijo.framework.routing :refer [parse-path]]))
(deftest test-parse-path
(testing "no params in path"
(is (= (parse-path "a" {}) "a"))
(is (= (parse-path "/a/b" {}) "/a/b")))
(testing "params are replaced"
(is (= (parse-path "/a/:b" {:b 1}) "/a/1"))
(is (= (parse-path "/a/:b" {:b "1"}) "/a/1"))
(is (= (parse-path ":b" {:b 1}) "1"))
(is (= (parse-path "/a/:b/c" {:b 1}) "/a/1/c")))
(testing "additional params are ignored"
(is (= (parse-path ":a" {:a 1 :b 2}) "1")))
(testing "all params are required"
(is (thrown? RuntimeException (parse-path ":a")))))
Loading…
Cancel
Save