<commit_before>(ns silly-image-store.handler-test
  (:require [clojure.test :refer :all]
            [clojure.data.json :as json]
            [silly-image-store.handler :refer :all]
            [ring.mock.request :as mock]))

(deftest test-app
  (testing "view image route"
    (testing "serve image"
      (let [response (app (mock/request :get "/images/test-all-the-things.jpg"))
            body (:body response)]
        (is (= (:status response) 200))  
        (is (= (class body) java.io.File))  
        (is (= (.getPath body) "test/fixtures/test-all-the-things.jpg"))))

    (testing "image not-found"
      (let [response (app (mock/request :get "/images/not-such-image.png"))]
        (is (= (:status response) 404))   
        (is (= (:body response) "No thing 'not-such-image.png' found")))))

  (testing "serve random image"
    (let [response (app (mock/request :get "/random"))
          body (:body response)]
      (is (= (:status response) 200))  
      (is (= (class body) java.io.File))))
    
  (testing "listing images"
    (testing "images from base dir as json"
      (let [response (app (mock/request :get "/images"))
            json-body (json/read-str (:body response))]
        (is (= (:status response) 200))  
        (is (= json-body 
               [{"name" "another-test.jpg",
                 "url" "http://localhost/images/another-test.jpg"}
                {"name" "test-all-the-things.jpg",
                 "url" "http://localhost/images/test-all-the-things.jpg"}]))))
    
    (testing "images from bucket as json"
      (let [response (app (mock/request :get "/buckets/some-bucket/images"))
            json-body (json/read-str (:body response))]
        (is (= (:status response) 200))  
        (is (= json-body 
               [{"name" "all-the-stuff.jpg",
                 "url" "http://localhost/buckets/some-bucket/images/all-the-stuff.jpg"}
                {"name" "stuff.jpg",
                 "url" "http://localhost/buckets/some-bucket/images/stuff.jpg"}
                ]))))
    
    (testing "bucket not found"
      (let [response (app (mock/request :get "/buckets/no-such-bucket/images"))]
        (is (= (:status response) 404))   
        (is (= (:body response) "No thing 'no-such-bucket' found")))))


  (testing "generic not-found route"
    (let [response (app (mock/request :get "/invalid"))]
      (is (= (:status response) 404)))))<commit_msg>Commented out test for listing buckets<commit_after>(ns silly-image-store.handler-test
  (:require [clojure.test :refer :all]
            [clojure.data.json :as json]
            [silly-image-store.handler :refer :all]
            [ring.mock.request :as mock]))

(deftest test-app
  (testing "view image route"
    (testing "serve image"
      (let [response (app (mock/request :get "/images/test-all-the-things.jpg"))
            body (:body response)]
        (is (= (:status response) 200))  
        (is (= (class body) java.io.File))  
        (is (= (.getPath body) "test/fixtures/test-all-the-things.jpg"))))

    (testing "image not-found"
      (let [response (app (mock/request :get "/images/not-such-image.png"))]
        (is (= (:status response) 404))   
        (is (= (:body response) "No thing 'not-such-image.png' found")))))

  (testing "serve random image"
    (let [response (app (mock/request :get "/random"))
          body (:body response)]
      (is (= (:status response) 200))  
      (is (= (class body) java.io.File))))
    
  (testing "listing images"
    (testing "images from base dir as json"
      (let [response (app (mock/request :get "/images"))
            json-body (json/read-str (:body response))]
        (is (= (:status response) 200))  
        (is (= json-body 
               [{"name" "another-test.jpg",
                 "url" "http://localhost/images/another-test.jpg"}
                {"name" "test-all-the-things.jpg",
                 "url" "http://localhost/images/test-all-the-things.jpg"}]))))
    
    (testing "images from bucket as json"
      (let [response (app (mock/request :get "/buckets/some-bucket/images"))
            json-body (json/read-str (:body response))]
        (is (= (:status response) 200))  
        (is (= json-body 
               [{"name" "all-the-stuff.jpg",
                 "url" "http://localhost/buckets/some-bucket/images/all-the-stuff.jpg"}
                {"name" "stuff.jpg",
                 "url" "http://localhost/buckets/some-bucket/images/stuff.jpg"}
                ]))))
    
    (testing "bucket not found"
      (let [response (app (mock/request :get "/buckets/no-such-bucket/images"))]
        (is (= (:status response) 404))   
        (is (= (:body response) "No thing 'no-such-bucket' found")))))

;  (testing "listing buckets"
;    (let [response (app (mock/request :get "/buckets"))
;          json-body (json/read-str (:body response))]
;      (is (= (:status response) 200))
;      (is (= json-body [{"name" "some-bucket",
;                         "url" "http://localhost/buckets/some-bucket"}]))
;      ))


  (testing "generic not-found route"
    (let [response (app (mock/request :get "/invalid"))]
      (is (= (:status response) 404)))))
{'fraction_non_alphanumeric': 0.179139201240791, 'fraction_numerical': 0.008724311748739822, 'mean_word_length': 2.216334164588529, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1069498', 'n_tokens_mistral': 1734, 'n_tokens_neox': 1575, 'n_words': 397}