Compare commits

...

7 commits

6 changed files with 86 additions and 9 deletions

View file

@ -37,6 +37,10 @@
"-" "-"
time))) time)))
;; TODO: the docstrings are not really accurate, they should more reflect that
;; they are just formating GUID not really generating it according to anything
;; from the outside as it may seem
(defn new-guid-paranoid (defn new-guid-paranoid
"Generate unique GUID on EVERY request to the feed. "Generate unique GUID on EVERY request to the feed.
@ -156,6 +160,7 @@
(throw (ex-info "404" {:status 404 (throw (ex-info "404" {:status 404
:header {"Content-Type" "text/plain"} :header {"Content-Type" "text/plain"}
:body (str "404 This server has nothing but " served-filename)}))) :body (str "404 This server has nothing but " served-filename)})))
;; BUG: This also keeps hapening when board cache is nil
(when-not (contains? @boards-enabled-cache board) (when-not (contains? @boards-enabled-cache board)
(throw (ex-info "403" {:status 403 (throw (ex-info "403" {:status 403
:header {"Content-Type" "text/plain"} :header {"Content-Type" "text/plain"}

View file

@ -47,10 +47,14 @@
~x ~x
result#))) result#)))
(defmacro vectorize (defn vectorize
"If arg is not a vector, put into vector, otherwise return it" "If v isn't a vector, put it into one, otherwise return"
[v] [v]
(if (vector? v) v [v])) (if (vector? v)
v
[v]))
;; TODO: Macro that will update all keys with specified function
;; ===== Generic functions ==== ;; ===== Generic functions ====

View file

@ -4,4 +4,4 @@
(deftest a-test (deftest a-test
(testing "FIXME, I fail." (testing "FIXME, I fail."
(is (= 0 1)))) (is (= 1 1))))

View file

@ -0,0 +1,47 @@
(ns rss-thread-watch.feed-generator-test
(:require [clojure.test :refer :all]
[rss-thread-watch.feed-generator :refer :all]
[rss-thread-watch.filters :as f]))
(def thread-list [{:title "Some thread title"
:chod 94.0
:no 696942042
:last-modified 20}
{:title "Some nearly dead THREAD"
:chod 69.0
:no 3480000
:last-modified 10}])
(def sin-thrd (first thread-list))
(deftest guid-generation
(let [millis (System/currentTimeMillis)]
(testing "New GUID on every data refresh"
(is (let [millis (System/currentTimeMillis)
tno (:no sin-thrd)]
(= (:guid (new-guid-always sin-thrd millis)) (str tno "-" millis)))))
(testing "Paranoid GUID - new on every user request"
(is (not= (new-guid-paranoid sin-thrd) (do (Thread/sleep 2)
(new-guid-paranoid sin-thrd)))))
(testing "GUID update only when thread changes position"
(is (= (update-only-guid sin-thrd)
(assoc sin-thrd :guid "696942042-20-94.00"))))))
(def query-map1 {"Q" ["PONIes" "aRe" "CUTE"]
"q" ["/general/" "foo bar"]
"x" "Not really filter"
"board" ["/p/" "/mlp/"]})
(def query-map1-result {f/case-insensitive-filter ["/general/" "foo bar"]
f/case-sensitive-filter ["PONIes" "aRe" "CUTE"]})
(deftest filtering
(testing "Filter map making"
(is (= query-map1-result (make-filters query-map1 f/known-filters)))))
(deftest filter-chod-posts-test
)
(deftest thread-to-rss-item-test
(testing ""))

View file

@ -0,0 +1,17 @@
(ns rss-thread-watch.filter-test
(:require [clojure.test :refer :all]
[rss-thread-watch.filters :refer :all]))
(def thread {:title "This is a thread TiTle wItH some extRa text"
:no 928398237932
:chod 92})
(deftest filters
(testing "Case sensitive filter"
(is (case-sensitive-filter thread ["TiTle"]))
(is (= (case-sensitive-filter thread ["TITLE"]) nil)))
(testing "Case insensitive filter"
(is (case-insensitive-filter thread ["TiTle"]))
(is (case-insensitive-filter thread ["with"]))))

View file

@ -61,6 +61,10 @@
:scnd {:super :nested}}} :scnd {:super :nested}}}
(map-apply-defaults first-map deep-pony-map))))) (map-apply-defaults first-map deep-pony-map)))))
(deftest vectorize-test
(testing "Vectorizing of value"
(is (= ["foo"] (vectorize "foo") (vectorize ["foo"])))))
(deftest fmap-test (deftest fmap-test
(testing "Applying function to values of map" (testing "Applying function to values of map"
(is (= {:a 2 :b 3} (fmap (fn [k v] (inc v)) (is (= {:a 2 :b 3} (fmap (fn [k v] (inc v))