Skip to content

Commit 7ab4d21

Browse files
committed
Add test when functions are returned from endpoints
1 parent a0f7250 commit 7ab4d21

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

test/compojure/api/integration_test.clj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,3 +1158,27 @@
11581158
=> (just {:400 (just {:schema anything :description ""})
11591159
:200 (just {:schema anything :description ""})
11601160
:500 (just {:schema anything :description ""})})))
1161+
1162+
(fact "when functions are returned"
1163+
(let [wrap-mw-params (fn [handler value] #(handler (update % ::mw (partial str value))))]
1164+
(fact "from endpoint"
1165+
(let [app (GET "/ping" []
1166+
:middleware [[wrap-mw-params "1"]]
1167+
:query-params [{a :- s/Str "a"}]
1168+
(fn [req] (str (::mw req) a)))]
1169+
1170+
(app {:request-method :get, :uri "/ping", :query-params {}}) => (contains {:body "1a"})
1171+
(app {:request-method :get, :uri "/ping", :query-params {:a "A"}}) => (contains {:body "1A"})))
1172+
1173+
(fact "from endpoint under context"
1174+
(let [app (context "/api" []
1175+
:middleware [[wrap-mw-params "1"]]
1176+
:query-params [{a :- s/Str "a"}]
1177+
(GET "/ping" []
1178+
:middleware [[wrap-mw-params "2"]]
1179+
:query-params [{b :- s/Str "b"}]
1180+
(fn [req] (str (::mw req) a b))))]
1181+
1182+
(app {:request-method :get, :uri "/api/ping", :query-params {}}) => (contains {:body "12ab"})
1183+
(app {:request-method :get, :uri "/api/ping", :query-params {:a "A"}}) => (contains {:body "12Ab"})
1184+
(app {:request-method :get, :uri "/api/ping", :query-params {:a "A", :b "B"}}) => (contains {:body "12AB"})))))

0 commit comments

Comments
 (0)