|
61 | 61 | (is (nil? ((GET "/foo/:x" [x :<< coercions/as-int] (str x)) |
62 | 62 | (mock/request :get "/foo/bar"))))) |
63 | 63 |
|
| 64 | + (testing "nil coercions in contexts" |
| 65 | + (is (not (nil? ((context "/foo/:x" [x] (GET "/" [] (str x))) |
| 66 | + (mock/request :get "/foo/bar"))))) |
| 67 | + (is (not (nil? ((context "/foo/:x" [x :<< coercions/as-int] (GET "/" [] (str x))) |
| 68 | + (mock/request :get "/foo/100"))))) |
| 69 | + (is (not (nil? ((context "/foo/:x" [x :<< #(Boolean/valueOf %)] (GET "/" [] (str x))) |
| 70 | + (mock/request :get "/foo/false"))))) |
| 71 | + (is (nil? ((context "/foo/:x" [x :<< coercions/as-int] (GET "/" [] (str x))) |
| 72 | + (mock/request :get "/foo/bar"))))) |
| 73 | + |
64 | 74 | (testing "map arguments" |
65 | 75 | ((GET "/foo" {params :params} |
66 | 76 | (is (= params {:x "a", :y "b"})) |
|
397 | 407 | exception (promise)] |
398 | 408 | (route request response exception) |
399 | 409 | (is (not (realized? exception))) |
400 | | - (is (nil? @response)))))) |
| 410 | + (is (nil? @response))))) |
| 411 | + |
| 412 | + (testing "with coercion" |
| 413 | + (let [route (context "/:id" [id :<< coercions/as-int] |
| 414 | + (GET "/" [] (str id)))] |
| 415 | + (testing "matching request" |
| 416 | + (let [request (mock/request :get "/123") |
| 417 | + response (promise) |
| 418 | + exception (promise)] |
| 419 | + (route request response exception) |
| 420 | + (is (not (realized? exception))) |
| 421 | + (is (= (:body @response) "123")))) |
| 422 | + (testing "not-matching request" |
| 423 | + (let [request (mock/request :get "/foo") |
| 424 | + response (promise) |
| 425 | + exception (promise)] |
| 426 | + (route request response exception) |
| 427 | + (is (not (realized? exception))) |
| 428 | + (is (nil? @response))))))) |
401 | 429 |
|
402 | 430 | (testing "wrap-routes" |
403 | 431 | (let [route (wrap-routes |
|
0 commit comments