|
1158 | 1158 | => (just {:400 (just {:schema anything :description ""}) |
1159 | 1159 | :200 (just {:schema anything :description ""}) |
1160 | 1160 | :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