<commit_before>(ns comic-reader.web-app-test
  (:require [clojure.test :as t]
            [comic-reader.site-scraper :as site-scraper]
            [comic-reader.web-app :refer :all]
            [comic-reader.comic-repository.scraper :refer [new-scraper-repo]]
            [comic-reader.mock-site-scraper :refer [mock-scraper]]
            [com.stuartsierra.component :as component]
            [ring.mock.request :as mock]))

(defn server-test-system [scraper]
  (component/system-map
   :site-scraper scraper
   :comic-repository (component/using
                      (new-scraper-repo)
                      {:scraper :site-scraper})
   :web-app (component/using
             (new-web-app)
             {:repository :comic-repository})))

(defn test-system [scraper]
  (-> (server-test-system scraper)
      (component/start)))

(defn app-routes [system]
  (get-routes (:web-app system)))

(t/deftest test-home-page
  (t/is (= (:status
            ((app-routes (test-system {})) (mock/request :get "/")))
           200)))

(def edn-content-type {"Content-Type" "application/edn; charset=utf-8"})

(t/deftest test-api
  (t/testing "/api/v1"

    (t/testing "/sites"
      (let [handle (app-routes
                    (test-system (mock-scraper
                                  :sites '("site-one"
                                           "site-two"
                                           "site-three"))))]

        (t/is (= (handle (mock/request :get "/api/v1/sites"))<commit_msg>Get rid of refer-all in web-app-test<commit_after>(ns comic-reader.web-app-test
  (:require [clojure.test :as t]
            [comic-reader.site-scraper :as site-scraper]
            [comic-reader.web-app :as sut]
            [comic-reader.comic-repository.scraper :refer [new-scraper-repo]]
            [comic-reader.mock-site-scraper :refer [mock-scraper]]
            [com.stuartsierra.component :as component]
            [ring.mock.request :as mock]))

(defn server-test-system [scraper]
  (component/system-map
   :site-scraper scraper
   :comic-repository (component/using
                      (new-scraper-repo)
                      {:scraper :site-scraper})
   :web-app (component/using
             (sut/new-web-app)
             {:repository :comic-repository})))

(defn test-system [scraper]
  (-> (server-test-system scraper)
      (component/start)))

(defn app-routes [system]
  (sut/get-routes (:web-app system)))

(t/deftest test-home-page
  (t/is (= (:status
            ((app-routes (test-system {})) (mock/request :get "/")))
           200)))

(def edn-content-type {"Content-Type" "application/edn; charset=utf-8"})

(t/deftest test-api
  (t/testing "/api/v1"

    (t/testing "/sites"
      (let [handle (app-routes
                    (test-system (mock-scraper
                                  :sites '("site-one"
                                           "site-two"
                                           "site-three"))))]

        (t/is (= (handle (mock/request :get "/api/v1/sites"))
{'fraction_non_alphanumeric': 0.15364150315929498, 'fraction_numerical': 0.0039906883937479215, 'mean_word_length': 1.813844714686623, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4137894', 'n_tokens_mistral': 1012, 'n_tokens_neox': 987, 'n_words': 176}