handle formats
CI / Test + coverage (push) Successful in 34s

This commit is contained in:
2026-09-19 07:49:15 -09:00
parent b1783e3f85
commit 31e03d552b
5 changed files with 129 additions and 5 deletions
+11
View File
@@ -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"))))