(ns pmagnus.btcdata.web.controllers.health-test (:require [clojure.test :refer [deftest is testing]] [pmagnus.btcdata.web.controllers.health :as health])) (deftest healthcheck-is-process-only (let [response (health/healthcheck! {})] (is (= 200 (:status response))) (is (= "up" (get-in response [:body :app :status]))))) (deftest readiness-check-tests-database (testing "ready when the database query succeeds" (let [called (atom nil) query-fn (fn [query params] (reset! called [query params]) {:healthy 1}) response (health/readiness-check! query-fn {})] (is (= 200 (:status response))) (is (= {:status "ready"} (:body response))) (is (= [:check-database {}] @called)))) (testing "not ready when the database query fails" (let [query-fn (fn [_ _] (throw (ex-info "database unavailable" {}))) response (health/readiness-check! query-fn {})] (is (= 503 (:status response))) (is (= {:status "not ready"} (:body response))))))