|
1 | 1 | (ns clj-http.lite.client-sanity-test |
2 | | - "A small subset of tests suitable for sanity testing. |
3 | | - Used by babashka libs tests." |
| 2 | + "A small subset of tests suitable for sanity testing." |
4 | 3 | (:require [clj-http.lite.client :as client] |
| 4 | + [cheshire.core :as json] |
| 5 | + [matcher-combinators.test] |
| 6 | + [matcher-combinators.matchers :as m] |
5 | 7 | [clojure.test :as t :refer [deftest is]])) |
6 | 8 |
|
7 | 9 | (deftest client-test |
8 | 10 | (is (= 200 (:status (client/get "https://www.clojure.org" {:throw-exceptions false})))) |
9 | 11 |
|
10 | | - (is (= 200 (:status (client/get "https://postman-echo.com/get?foo1=bar1&foo2=bar2" {:throw-exceptions false})))) |
| 12 | + (is (match? {:status 200 |
| 13 | + :body (m/via json/decode {"method" "GET" |
| 14 | + "args" {"foo1" ["bar1"] |
| 15 | + "foo2" ["bar2"]}})} |
| 16 | + (client/get "https://httpbingo.org/get?foo1=bar1&foo2=bar2" {:throw-exceptions false}))) |
11 | 17 |
|
12 | | - (is (= 200 (:status (client/post "https://postman-echo.com/post" {:throw-exceptions false})))) |
| 18 | + (is (match? {:status 200 |
| 19 | + :body (m/via json/decode {"method" "POST" |
| 20 | + "headers" {"Content-Type" m/absent} |
| 21 | + "args" {} |
| 22 | + "data" ""})} |
| 23 | + (client/post "https://httpbingo.org/post" {:throw-exceptions false}))) |
13 | 24 |
|
14 | | - (is (= 200 (:status (client/post "https://postman-echo.com/post" |
15 | | - {:body "{\"a\": 1}" |
16 | | - :headers {"X-Hasura-Role" "admin"} |
17 | | - :content-type :json |
18 | | - :accept :json |
19 | | - :throw-exceptions false})))) |
| 25 | + (is (match? {:status 200 |
| 26 | + :body (m/via json/decode {"method" "POST" |
| 27 | + "headers" {"Content-Type" ["application/json; charset=UTF-8"] |
| 28 | + "X-Hasura-Role" ["admin"]} |
| 29 | + "data" "{\"a\": 1}"})} |
| 30 | + (client/post "https://httpbingo.org/post" |
| 31 | + {:body "{\"a\": 1}" |
| 32 | + :headers {"X-Hasura-Role" "admin"} |
| 33 | + :content-type :json |
| 34 | + :accept :json |
| 35 | + :throw-exceptions false}))) |
20 | 36 |
|
21 | | - (is (= 200 (:status (client/put "https://postman-echo.com/put" |
22 | | - {:body "{\"a\": 1}" |
23 | | - :headers {"X-Hasura-Role" "admin"} |
24 | | - :content-type :json |
25 | | - :accept :json |
26 | | - :throw-exceptions false}))))) |
| 37 | + (is (match? {:status 200 |
| 38 | + :body (m/via json/decode {"method" "PUT" |
| 39 | + "headers" {"Content-Type" ["application/json; charset=UTF-8"] |
| 40 | + "X-Hasura-Role" ["admin"]} |
| 41 | + "data" "{\"a\": 1}"})} |
| 42 | + (client/put "https://httpbingo.org/put" |
| 43 | + {:body "{\"a\": 1}" |
| 44 | + :headers {"X-Hasura-Role" "admin"} |
| 45 | + :content-type :json |
| 46 | + :accept :json |
| 47 | + :throw-exceptions false})))) |
27 | 48 |
|
28 | 49 | (deftest exception-test |
29 | | - (try (client/get "https://httpbin.org/status/404") |
| 50 | + (try (client/get "https://httpbingo.org/status/404") |
30 | 51 | (is false "should not reach here") |
31 | 52 | (catch Exception e |
32 | 53 | (is (:headers (ex-data e)))))) |
|
37 | 58 | (is (= 200 (:status (client/get "https://expired.badssl.com" {:insecure? true})))) |
38 | 59 | (is (thrown? Exception |
39 | 60 | (client/get "https://expired.badssl.com")))) |
| 61 | + |
0 commit comments