Skip to content

Commit e69436f

Browse files
committed
Add a middleware test
1 parent 2ffd39e commit e69436f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/compojure/api/core_integration_test.clj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@
8787
(-> (ok "true")
8888
(header mw* (str (get-in request [:headers mw*]) 7))))
8989

90+
(defn middleware-x
91+
"If request has query-param x, presume it's a integer and multiply it by two
92+
before passing request to next handler."
93+
[handler]
94+
(fn [req]
95+
(handler (update-in req [:query-params "x"] #(* (Integer. %) 2)))))
96+
9097
;;
9198
;; Facts
9299
;;
@@ -141,6 +148,18 @@
141148
status => 200
142149
body => {:value "third"})))
143150

151+
(facts "middlewares - editing request"
152+
(defapi api
153+
(swaggered +name+
154+
(GET* "/first" []
155+
:query-params [x :- Long]
156+
:middlewares [middleware-x]
157+
(ok {:value x}))))
158+
(fact "middleware edits the parameter before route body"
159+
(let [[status body headers] (get* api "/first?x=5" {})]
160+
status => 200
161+
body => {:value 10})))
162+
144163
(fact ":body, :query and :return"
145164
(defapi api
146165
(swaggered +name+

0 commit comments

Comments
 (0)