Files
yohoho/test/yohoho/helpers_test.clj
Benjamin Sigonneau 449a4a7d75 Add unit and integration tests
I won't be lying, Claude Code was extremely helpful to write those
tests, although it had a lot of issues with properly using in-memory
SQLite (db and integration tests) and with parsing responses
(integration test).
2026-02-01 06:00:12 +01:00

36 lines
1.6 KiB
Clojure

(ns yohoho.helpers-test
(:require [clojure.test :refer :all]
[yohoho.helpers :as helpers]))
(deftest test-post-payload-content-type-json-middleware
(let [mock-handler (fn [_request] {:status 200 :body "Success"})
wrapped-handler (helpers/post-payload-content-type-json-middleware mock-handler)]
(testing "GET requests pass through without content-type check"
(let [request {:request-method :get}
response (wrapped-handler request)]
(is (= 200 (:status response)))
(is (= "Success" (:body response)))))
(testing "POST with application/json passes through"
(let [request {:request-method :post
:headers {"content-type" "application/json"}}
response (wrapped-handler request)]
(is (= 200 (:status response)))
(is (= "Success" (:body response)))))
(testing "POST without content-type returns 415"
(let [request {:request-method :post
:headers {}}
response (wrapped-handler request)]
(is (= 415 (:status response)))
(is (= "Unsupported Media Type" (get-in response [:body :error])))
(is (= "Content-Type must be application/json" (get-in response [:body :message])))))
(testing "POST with wrong content-type returns 415"
(let [request {:request-method :post
:headers {"content-type" "application/xml"}}
response (wrapped-handler request)]
(is (= 415 (:status response)))
(is (= "Unsupported Media Type" (get-in response [:body :error])))))))