rss-thread-watcher/test/rss_thread_watch/feed_generator_test.clj

58 lines
2.4 KiB
Clojure
Raw Permalink Normal View History

(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)
2024-10-13 02:17:24 +02:00
(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"]})
2024-10-13 02:17:24 +02:00
(deftest filtering
(testing "Filter map making"
(is (= query-map1-result (make-filters query-map1 f/known-filters)))))
2024-10-25 02:32:14 +02:00
(deftest filter-chod-posts-test
)
2024-10-25 02:32:14 +02:00
(deftest thread-to-rss-item-test
(testing "Cached thread to RSS item conversion"
(is (= (thread-to-rss-item (first thread-list) "https://treebrary.org/")
{:title "94.00% - Some thread title"
:description "The thread: 'Some thread title' has 94.00% chance of dying"
:link (str "https://treebrary.org/" (:no (first thread-list)))
:guid nil}) "Thread NO appended when no proper host provided")
(is (= (thread-to-rss-item (first thread-list) "https://treebrary.org/thread/{threadnum}/fooSomething")
{:title "94.00% - Some thread title"
:description "The thread: 'Some thread title' has 94.00% chance of dying"
:link (str "https://treebrary.org/thread/" (:no (first thread-list)) "/fooSomething")
:guid nil}))))