(ns net.deertopia.doerg.server-test (:require [net.deertopia.doerg.server :as sut] [reitit.ring] [clojure.test :as t] [net.deertopia.doerg.config :as cfg] [net.deertopia.doerg.roam :as roam] [babashka.fs :as fs] [clojure.java.io :as io] [net.deertopia.doerg.roam-test :refer [test-db-fixture]] [net.deertopia.doerg.config-test :refer [test-config-fixture]])) (t/use-fixtures :once (t/join-fixtures [test-config-fixture test-db-fixture])) (defn with-server [f] (let [was-already-running? (= :running (sut/status))] (when-not was-already-running? (sut/start!)) (f) (when-not was-already-running? (sut/stop!)))) (defn get-sut [uri] (sut/app {:request-method :get :uri uri})) (t/deftest server-is-running ;; 서버는 벌써 시작한 다음에 이 테스트 하면 잘못됩니다. ;; (assert (not= :running (sut/status))) (with-server (fn [] (t/is (= :running (sut/status))) (t/is (->> (format "http://localhost:%d" (::cfg/port cfg/*cfg*)) slurp string?))))) (t/deftest get-nonexistent-node (let [slug "3Lxvxnb0QrivoU3DX-l_5w"] (assert (nil? (roam/make-node slug))) (t/is (= 404 (-> (str "/n/" slug) get-sut :status))))) (t/deftest get-homepage (let [resp (-> (str "/n/" sut/homepage-slug) get-sut)] (t/is (= 200 (:status resp))) (t/is (= (-> "/" get-sut :body) (-> resp :body)))))