@@ -128,6 +128,17 @@
|
||||
(assert-eq "Body" {:result 5} (edn/read-string (:body resp))))
|
||||
(println)
|
||||
|
||||
(println "Test 9b: the API answers in the format the Accept header asks for, EDN by default")
|
||||
(let [json (http/get (str base-url "/api/add?x=2&y=3") {:throw false :headers {"Accept" "application/json"}})
|
||||
any (http/get (str base-url "/api/add?x=2&y=3") {:throw false :headers {"Accept" "*/*"}})
|
||||
err (http/get (str base-url "/api/todos") {:throw false :headers {"Accept" "application/json"}})]
|
||||
(assert-contains "JSON Content-Type" "application/json" (get (:headers json) "content-type" ""))
|
||||
(assert-eq "JSON body" "{\"result\":5}" (:body json))
|
||||
(assert-contains "Accept */* is EDN" "application/edn" (get (:headers any) "content-type" ""))
|
||||
(assert-contains "Errors are JSON too" "application/json" (get (:headers err) "content-type" ""))
|
||||
(assert-eq "Error body" "{\"error\":\"login required\"}" (:body err)))
|
||||
(println)
|
||||
|
||||
(println "Test 10: GET /api/add with a missing or non-numeric param returns 400")
|
||||
(assert-eq "Missing y" 400 (:status (get* (str base-url "/api/add?x=2"))))
|
||||
(assert-eq "Non-numeric x" 400 (:status (get* (str base-url "/api/add?x=abc&y=3"))))
|
||||
|
||||
Reference in New Issue
Block a user