From efd3568e8536e15f8f764d502154dca065939152 Mon Sep 17 00:00:00 2001 From: Felisp Date: Sat, 12 Oct 2024 11:22:42 +0200 Subject: [PATCH] Write tests for GUID generation functions --- src/rss_thread_watch/feed_generator.clj | 4 +++ test/rss_thread_watch/feed_generator_test.clj | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 test/rss_thread_watch/feed_generator_test.clj diff --git a/src/rss_thread_watch/feed_generator.clj b/src/rss_thread_watch/feed_generator.clj index ef81e1e..46c58dc 100644 --- a/src/rss_thread_watch/feed_generator.clj +++ b/src/rss_thread_watch/feed_generator.clj @@ -37,6 +37,10 @@ "-" 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 "Generate unique GUID on EVERY request to the feed. diff --git a/test/rss_thread_watch/feed_generator_test.clj b/test/rss_thread_watch/feed_generator_test.clj new file mode 100644 index 0000000..09dfa2d --- /dev/null +++ b/test/rss_thread_watch/feed_generator_test.clj @@ -0,0 +1,34 @@ +(ns rss-thread-watch.feed-generator-test + (:require [clojure.test :refer :all] + [rss-thread-watch.feed-generator :refer :all])) + +(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"))) + + + ) + )) + + +