summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-10-13 21:27:29 +0800
committereltrac <hi@eltr.ac>2026-10-13 21:27:29 +0800
commit3989bf6fbbb242ad5bd6a1d1f91f70a6a222f8e2 (patch)
tree435dfee792ec80de7b4cfc233efd53fab579529e
parent29344c41cc11c2d5d34bdfdbcfb8d093fad1002a (diff)
style: cljfmt everything
-rw-r--r--bellsprout/dev/user.clj1
-rw-r--r--bellsprout/scripts/treeshake.clj14
-rw-r--r--bellsprout/src/core.cljs38
-rw-r--r--dev/user.clj2
-rw-r--r--project.clj4
-rw-r--r--scripts/ci/coverage_badge.clj36
-rw-r--r--scripts/recalculate-hashes.clj22
-rw-r--r--src/weepinbell/core.clj14
-rw-r--r--src/weepinbell/http/client.clj26
-rw-r--r--src/weepinbell/http/downloader.clj6
-rw-r--r--src/weepinbell/utils/url.clj26
-rw-r--r--src/weepinbell/webhook.clj4
-rw-r--r--src/weepinbell/webserver/facade.clj4
-rw-r--r--src/weepinbell/webserver/retriever.clj62
-rw-r--r--test/weepinbell/core_test.clj2
-rw-r--r--test/weepinbell/handler_test.clj106
-rw-r--r--test/weepinbell/microformats_test.clj22
-rw-r--r--test/weepinbell/storage_test.clj18
-rw-r--r--test/weepinbell/utils_url_test.clj18
-rw-r--r--test/weepinbell/webhook_test.clj2
20 files changed, 213 insertions, 214 deletions
diff --git a/bellsprout/dev/user.clj b/bellsprout/dev/user.clj
index 77dcc03..df2089c 100644
--- a/bellsprout/dev/user.clj
+++ b/bellsprout/dev/user.clj
@@ -18,7 +18,6 @@
;; tools.namespace https://github.com/clojure/tools.namespace
;; and Component https://github.com/stuartsierra/component
-
(defn fig-start
"This starts the figwheel server and watch based auto-compiler."
[]
diff --git a/bellsprout/scripts/treeshake.clj b/bellsprout/scripts/treeshake.clj
index 868a568..96c4009 100644
--- a/bellsprout/scripts/treeshake.clj
+++ b/bellsprout/scripts/treeshake.clj
@@ -7,12 +7,12 @@
(defn treeshake [content original target]
(let [shake (partial shell {:out :string}
- "npx" "purgecss"
- "--css" original
- "--content")
+ "npx" "purgecss"
+ "--css" original
+ "--content")
out (apply shake content)
- css (-> out :out json/parse-string first (get "css"))]
- (spit target css)))
+ css (-> out :out json/parse-string first (get "css"))]
+ (spit target css)))
(def original-css "resources/public/css/pico.min.css")
(def target-css "resources/public/css/pico.purged.css")
@@ -25,8 +25,8 @@
(let [size #(.length (java.io.File. %))
old-size (size original-css)
new-size (size target-css)]
- (println "Tree shaken. Purged CSS file size:" new-size "Bytes"
- (str "(" (- new-size old-size ) " Bytes)")))
+ (println "Tree shaken. Purged CSS file size:" new-size "Bytes"
+ (str "(" (- new-size old-size) " Bytes)")))
(println "Something went wrong.")))
(defn -main []
diff --git a/bellsprout/src/core.cljs b/bellsprout/src/core.cljs
index 2e1ffe4..9284f0b 100644
--- a/bellsprout/src/core.cljs
+++ b/bellsprout/src/core.cljs
@@ -1,5 +1,5 @@
(ns core
- (:require [hiccup :refer [hiccup->element]]))
+ (:require [hiccup :refer [hiccup->element]]))
;; global constants
(def API_BASE_URL "http://localhost:3000")
@@ -30,28 +30,28 @@
photo (or (get-in data ["extra" "proxied-photo"])
(get-in mf ["author" "photo"]))]
(hiccup->element
- [:div {:class "card" :style "font-family: monospace;"}
- [:p "From: " [:a {:href source :target "_blank"} source]]
- [:p "To: " [:a {:href target :target "_blank"} target]]
- (when mf
- [:footer {:class "card-footer"}
- [:img {:src photo :class "card-photo"}]
- [:small [:a {:href (or (get-in mf ["author" "url"]) "#")
- :target "_blank"}
- (get-in mf ["author" "name"])]]
- (when-let [datetime (get wm "modified")]
- (when-not (= "null" datetime)
- [:small [:time {:datetime (date->iso datetime)}
- (date->local datetime)]]))])])))
+ [:div {:class "card" :style "font-family: monospace;"}
+ [:p "From: " [:a {:href source :target "_blank"} source]]
+ [:p "To: " [:a {:href target :target "_blank"} target]]
+ (when mf
+ [:footer {:class "card-footer"}
+ [:img {:src photo :class "card-photo"}]
+ [:small [:a {:href (or (get-in mf ["author" "url"]) "#")
+ :target "_blank"}
+ (get-in mf ["author" "name"])]]
+ (when-let [datetime (get wm "modified")]
+ (when-not (= "null" datetime)
+ [:small [:time {:datetime (date->iso datetime)}
+ (date->local datetime)]]))])])))
(defn show-cards [data]
(set! (. cards-area -innerHTML) "")
(doseq [card-data data]
- (.appendChild cards-area
- (create-card card-data))))
+ (.appendChild cards-area
+ (create-card card-data))))
(defn get-webmention-list [by term]
- (-> (case by
+ (-> (case by
:domain (js/fetch (str API_BASE_URL "/api/mentions/" term))
:url (js/fetch (str API_BASE_URL "/api/mentions?url=" term)))
(.then (fn [resp] (.json resp)))))
@@ -70,12 +70,12 @@
(defn- nil-or-empty? [value]
(or (nil? value) (= "" value) (empty? value)))
(defn find-webmention [source target]
- (cond
+ (cond
(nil-or-empty? target) (js/alert "Cannot find webmention with no target URL")
(nil-or-empty? source) (show-webmention-list :url target)
:else (show-webmention source target)))
-(set! (. button-find -onclick)
+(set! (. button-find -onclick)
(fn [] (find-webmention (. input-wm-source -value)
(. input-wm-target -value))))
diff --git a/dev/user.clj b/dev/user.clj
index 2ebcdb0..04e0526 100644
--- a/dev/user.clj
+++ b/dev/user.clj
@@ -4,7 +4,7 @@
[weepinbell.core]))
(reload/init
- {:dirs ["src" "dev" "test"]})
+ {:dirs ["src" "dev" "test"]})
(defonce stop-fn (atom nil))
diff --git a/project.clj b/project.clj
index e599db2..5434980 100644
--- a/project.clj
+++ b/project.clj
@@ -22,7 +22,7 @@
[org.nibor.autolink/autolink "0.12.0"]
[io.github.tonsky/fast-edn "1.2.0"]]
:managed-dependencies [[org.clojure/tools.reader "1.6.0"]
- [org.ow2.asm/asm "9.11"]]
+ [org.ow2.asm/asm "9.11"]]
:profiles {:uberjar {:aot :all}
:test {:dependencies [[ring/ring-mock "0.6.2"]]}
:dev {:source-paths ["dev"]
@@ -36,6 +36,6 @@
:plugins [[lein-ancient "0.6.15"]
;; latest commits of cloverage were "co-authored" by Claude
;; we'll keep it on this version for now
- [lein-cloverage "1.2.2"]
+ [lein-cloverage "1.2.2"]
[dev.weavejester/lein-cljfmt "0.16.5"]])
diff --git a/scripts/ci/coverage_badge.clj b/scripts/ci/coverage_badge.clj
index a8a0948..4cb5947 100644
--- a/scripts/ci/coverage_badge.clj
+++ b/scripts/ci/coverage_badge.clj
@@ -7,25 +7,25 @@
(def cloverage-output "target/coverage/index.html")
(def coverage (let [rows (-> cloverage-output
- slurp
- h/parse
- h/as-hickory
- :content first ;; get <html>
- :content (nth 3) ;; get <body>
- :content second ;; get <table>
- :content last ;; get <tbody>
- :content)
- total-row (->> rows
- (map :content)
- (filter sequential?)
- (filter #(= "Totals:" (get-in % [0 :content 0])))
- first
- (filter map?))]
+ slurp
+ h/parse
+ h/as-hickory
+ :content first ;; get <html>
+ :content (nth 3) ;; get <body>
+ :content second ;; get <table>
+ :content last ;; get <tbody>
+ :content)
+ total-row (->> rows
+ (map :content)
+ (filter sequential?)
+ (filter #(= "Totals:" (get-in % [0 :content 0])))
+ first
+ (filter map?))]
(-> total-row
- (nth 2)
- :content
- first
- (string/replace " " ""))))
+ (nth 2)
+ :content
+ first
+ (string/replace " " ""))))
;; "25" will make "%25" which decoded to "%", removing it will result in a Bad Request
(def badge-url (str "https://img.shields.io/badge/coverage-" coverage "25-green"))
(def badge-html
diff --git a/scripts/recalculate-hashes.clj b/scripts/recalculate-hashes.clj
index b42a0d1..67c0251 100644
--- a/scripts/recalculate-hashes.clj
+++ b/scripts/recalculate-hashes.clj
@@ -24,11 +24,11 @@
(->> (line-seq r)
(map edn/read-string)
f)))
-(defn- java-digest [^String s algo]
- (let [algorithm (MessageDigest/getInstance algo)
- raw-bytes (.digest algorithm (.getBytes s "UTF-8"))]
+(defn- java-digest [^String s algo]
+ (let [algorithm (MessageDigest/getInstance algo)
+ raw-bytes (.digest algorithm (.getBytes s "UTF-8"))]
(apply str (map #(format "%02x" %) raw-bytes))))
-(defn digest
+(defn digest
([s]
(digest s :sha-256 32))
([s algo]
@@ -45,16 +45,16 @@
;; end
(let [[datafile] *command-line-args*]
- (with-webmentions datafile
+ (with-webmentions datafile
(fn [wms]
(println "starting reading, total count:" (count wms))
(->> wms
(map (fn [wm]
- (let [webmention (:webmention wm)
- source (:source webmention)
- target (:target webmention)
- new-id (digest (str source target))]
- (println new-id)
- (assoc wm :webmention (assoc webmention :id new-id)))))
+ (let [webmention (:webmention wm)
+ source (:source webmention)
+ target (:target webmention)
+ new-id (digest (str source target))]
+ (println new-id)
+ (assoc wm :webmention (assoc webmention :id new-id)))))
(unload-data datafile))
(println "complete!"))))
diff --git a/src/weepinbell/core.clj b/src/weepinbell/core.clj
index edc3918..20c0aef 100644
--- a/src/weepinbell/core.clj
+++ b/src/weepinbell/core.clj
@@ -52,13 +52,13 @@
stop-system (start-system)]
;; Register signal handlers for SIGINT and SIGTERM
(doseq [signal ["INT" "TERM"]]
- (Signal/handle (Signal. signal)
- (reify SignalHandler
- (handle [_ sig]
- (stop-system)
- (timbre/info "signal" (.getName sig) "received."
- "gracefully shut down weepinbell.")
- (>!! done-chan true)))))
+ (Signal/handle (Signal. signal)
+ (reify SignalHandler
+ (handle [_ sig]
+ (stop-system)
+ (timbre/info "signal" (.getName sig) "received."
+ "gracefully shut down weepinbell.")
+ (>!! done-chan true)))))
;; block til signal received
(<!! done-chan)))
diff --git a/src/weepinbell/http/client.clj b/src/weepinbell/http/client.clj
index 99514f4..f051d15 100644
--- a/src/weepinbell/http/client.clj
+++ b/src/weepinbell/http/client.clj
@@ -74,20 +74,20 @@
(let [retryables #{TimeoutException}]
(some #(instance? % error) retryables)))
-(defmacro with-retry
+(defmacro with-retry
"Retry request after failure with backoff, asynchronously."
[times backoff & body]
`(future (loop [~'current-try 0
- ~'backoff ~backoff]
- (let [~'result (try
- (deref ~@body)
- (catch Throwable ~'e {:error ~'e}))]
- (if (and (:error ~'result)
- (retryable? (:error ~'result))
- (< ~'current-try ~times))
- (do
- (timbre/warn "request failed. retry after" ~'backoff "seconds")
- (Thread/sleep (* ~'backoff 1000))
- (recur (inc ~'current-try) (* 2 ~'backoff)))
- ~'result)))))
+ ~'backoff ~backoff]
+ (let [~'result (try
+ (deref ~@body)
+ (catch Throwable ~'e {:error ~'e}))]
+ (if (and (:error ~'result)
+ (retryable? (:error ~'result))
+ (< ~'current-try ~times))
+ (do
+ (timbre/warn "request failed. retry after" ~'backoff "seconds")
+ (Thread/sleep (* ~'backoff 1000))
+ (recur (inc ~'current-try) (* 2 ~'backoff)))
+ ~'result)))))
diff --git a/src/weepinbell/http/downloader.clj b/src/weepinbell/http/downloader.clj
index d58501b..3b5bdfb 100644
--- a/src/weepinbell/http/downloader.clj
+++ b/src/weepinbell/http/downloader.clj
@@ -1,4 +1,4 @@
-(ns weepinbell.http.downloader
+(ns weepinbell.http.downloader
(:require [taoensso.timbre :as timbre]
[clojure.java.io :as io]
[weepinbell.http.client :as client]))
@@ -14,7 +14,7 @@
(let [response (client/get! url {:as :stream})
status (:status response)]
(if (and status (> status 199) (< status 300))
- (do
+ (do
(timbre/info "Downloading [" url "] -> [" dest-path "]")
;; write to output stream
(with-open [in (:body response)
@@ -22,7 +22,7 @@
(io/copy in out))
(timbre/info "Download success. File size:" (.length file) "bytes")
true)
- (do
+ (do
(timbre/warn "Download fail. Status: " status)
(when-let [error (:error response)]
(timbre/error error))))))
diff --git a/src/weepinbell/utils/url.clj b/src/weepinbell/utils/url.clj
index 265509c..9b25cd2 100644
--- a/src/weepinbell/utils/url.clj
+++ b/src/weepinbell/utils/url.clj
@@ -38,26 +38,26 @@
(defn- normlaize-path [^String path*]
(let [path (or path* "")
deslashed (if (and (pos? (count path)) (.endsWith path "/"))
- (subs path 0 (dec (count path)))
+ (subs path 0 (dec (count path)))
path)]
- (str (.normalize (URI. deslashed)))))
+ (str (.normalize (URI. deslashed)))))
(defn- normalize-query [^String query]
(some-> query
- (string/split #"&")
- sort
- (->> (string/join "&"))))
+ (string/split #"&")
+ sort
+ (->> (string/join "&"))))
(defn normalize
"Normalize URL by removing trailing slashes; removing anchor;
replacing . and ..; ordering query params."
[^String url]
- (try
+ (try
(let [base (URI. url)
- scheme (.getScheme base)
- auth (.getAuthority base)
- path (normlaize-path (.getPath base))
- query (normalize-query (.getQuery base))]
+ scheme (.getScheme base)
+ auth (.getAuthority base)
+ path (normlaize-path (.getPath base))
+ query (normalize-query (.getQuery base))]
(str scheme "://" auth path
- (when (seq query) (str "?" query))))
+ (when (seq query) (str "?" query))))
;; fallback to empty string is url is nil
(catch NullPointerException _ "")
;; fallback to original string if syntax is invalid
@@ -66,7 +66,7 @@
(defn url= [& urls]
(apply = (map normalize urls)))
-(defn extract
+(defn extract
"Given plain text. Returns a vector of URLs that appears in it."
[^String text]
{:pre [(string? text)]
@@ -75,7 +75,7 @@
(.linkTypes (EnumSet/of LinkType/URL))
.build)
indexes (->> (.extractLinks extractor text)
- (map (fn [link]
+ (map (fn [link]
[(.getBeginIndex link)
(.getEndIndex link)])))
urls (map #(subs text (first %) (last %)) indexes)]
diff --git a/src/weepinbell/webhook.clj b/src/weepinbell/webhook.clj
index ae0d12b..c93b74a 100644
--- a/src/weepinbell/webhook.clj
+++ b/src/weepinbell/webhook.clj
@@ -8,7 +8,7 @@
[weepinbell.http.client :as client]
[weepinbell.webhook-presets :refer [request-presets]]))
-(s/def ::hooks-map
+(s/def ::hooks-map
(s/keys :req-un [::on-create ::on-update ::on-delete ::on-receive]))
;; utilities
@@ -73,7 +73,7 @@
(make-request event-key data (:request-fn %))))
doall))
-(def empty-hooks
+(def empty-hooks
(zipmap [:on-receive :on-create :on-delete :on-update]
(repeat 4 (fn [& _]))))
(defn make-hooks
diff --git a/src/weepinbell/webserver/facade.clj b/src/weepinbell/webserver/facade.clj
index 4a7bead..1e93126 100644
--- a/src/weepinbell/webserver/facade.clj
+++ b/src/weepinbell/webserver/facade.clj
@@ -15,10 +15,10 @@
(defn make-services []
{:post [#(s/valid? :weepinbell.webserver.handler/services %)]}
{:gen-feed feed/rss
- :receive receiver/receive
+ :receive receiver/receive
:retrieve-by-domain retriever/by-domain
:retrieve-by-url retriever/by-url
- :retrieve-by-id retriever/by-id
+ :retrieve-by-id retriever/by-id
:retrieve-by-pair retriever/by-st-pair
:count-by-domain counter/by-domain
:count-by-url counter/by-url})
diff --git a/src/weepinbell/webserver/retriever.clj b/src/weepinbell/webserver/retriever.clj
index eac4053..e335bc9 100644
--- a/src/weepinbell/webserver/retriever.clj
+++ b/src/weepinbell/webserver/retriever.clj
@@ -23,20 +23,20 @@
;; query list of webmentions
-(defn filter-by-mftype
+(defn filter-by-mftype
[mftype data]
- (if (nil? mftype) data
- (->> data
- (map (fn [item]
- [(get-in item [:webmention :target])
- (get item :microformats)]))
- (filter (fn [[target mf]]
- (->> mf mfsr/use-items
- mfsr/find-h-entry
- (mfsr/search-mftype target)
- (= mftype)))))))
+ (if (nil? mftype) data
+ (->> data
+ (map (fn [item]
+ [(get-in item [:webmention :target])
+ (get item :microformats)]))
+ (filter (fn [[target mf]]
+ (->> mf mfsr/use-items
+ mfsr/find-h-entry
+ (mfsr/search-mftype target)
+ (= mftype)))))))
-(defn query-list
+(defn query-list
"Get a list of webmentions by certain filters."
{:pre [(s/keys :req-un [::domain ::path ::page ::page-size ::storage ::mftype])]}
[opts]
@@ -46,14 +46,14 @@
data ((:get-by-domain storage path) domain)
data (filter-by-mftype mftype data)
pages (vec (partition-all page-size data))
- page-number (if (number? page) page
- (- (count pages) 1))
+ page-number (if (number? page) page
+ (- (count pages) 1))
page-selected (get pages page-number)
- result (if reduce-mf? (map #(assoc % :microformats
- (reduce-mf (get-in % [:webmention :target])
- (:microformats %)))
- page-selected)
- page-selected)]
+ result (if reduce-mf? (map #(assoc % :microformats
+ (reduce-mf (get-in % [:webmention :target])
+ (:microformats %)))
+ page-selected)
+ page-selected)]
(respond-webmention-list-json result)))
(defn by-domain
@@ -61,9 +61,9 @@
[domain page storage opts]
(query-list {:domain domain
:path nil
- :page page
+ :page page
:page-size default-page-size
- :storage storage
+ :storage storage
:mftype (:type opts)
:microformats (:microformats opts)}))
@@ -73,17 +73,17 @@
(if url
(query-list {:domain (get-domain url)
:path (get-path url)
- :page page
+ :page page
:page-size default-page-size
- :storage storage
+ :storage storage
:mftype (:type opts)
:microformats (:microformats opts)})
- {:status 400
+ {:status 400
:body {:message "Missing URL. Specify target URL whose webmentions you are querying."}}))
;; query one webmention
-(defn query-one
+(defn query-one
"Get one specific webmention by id or by its source and target."
[opts]
{:post [(s/keys :req-un [::identifiers ::storage ::microformats])]}
@@ -91,23 +91,23 @@
reduce-mf? (not= "raw" microformats)
data (apply (:get storage) identifiers)
result (if (and (:microformats data) reduce-mf?)
- (assoc data :microformats
- (reduce-mf (get-in (:microformats data) [:webmention :target])
- (:microformats data)))
- data)]
+ (assoc data :microformats
+ (reduce-mf (get-in (:microformats data) [:webmention :target])
+ (:microformats data)))
+ data)]
(respond-webmention-json result)))
(defn by-id
"Get one specific webmention by ID."
[id storage opts]
(query-one {:identifiers [id]
- :storage storage
+ :storage storage
:microformats (:microformats opts)}))
(defn by-st-pair
"Get one specific webmention by source and target."
[source target storage opts]
(query-one {:identifiers [source target]
- :storage storage
+ :storage storage
:microformats (:microformats opts)}))
diff --git a/test/weepinbell/core_test.clj b/test/weepinbell/core_test.clj
index 4e7ebd8..9a223c9 100644
--- a/test/weepinbell/core_test.clj
+++ b/test/weepinbell/core_test.clj
@@ -2,7 +2,7 @@
(:require [clojure.test :refer [deftest testing is]]
[weepinbell.core :refer [start-system]]))
-(deftest start-system-test
+(deftest start-system-test
(testing "system starts and shuts down normally"
(let [shutdown (start-system)]
(is (fn? shutdown))
diff --git a/test/weepinbell/handler_test.clj b/test/weepinbell/handler_test.clj
index 754444c..457385a 100644
--- a/test/weepinbell/handler_test.clj
+++ b/test/weepinbell/handler_test.clj
@@ -7,82 +7,82 @@
[cheshire.core :refer [parse-string]]))
(defn test-app [wmc store config]
- (app {:wmc wmc :store store :config config
+ (app {:wmc wmc :store store :config config
:services (make-services)}))
(deftest api-routes-test
(testing "/api/mentions/:domain route"
- (let [response ((test-app nil {:get-by-domain (fn [_]
- [{:webmention {:source ""
- :target ""
- :id ""
- :modified 0}}])}
- {})
- (mock/request :get "/api/mentions/www.example"))]
- (is (= (:status response) 200))
- (is (some? (:body response)))))
+ (let [response ((test-app nil {:get-by-domain (fn [_]
+ [{:webmention {:source ""
+ :target ""
+ :id ""
+ :modified 0}}])}
+ {})
+ (mock/request :get "/api/mentions/www.example"))]
+ (is (= (:status response) 200))
+ (is (some? (:body response)))))
(testing "/api/mentions?url= route"
- (let [response ((test-app nil
- {:get-by-domain
- (fn [_]
- [{:webmention {:source "https://source.net"
- :target "http://localhost"
- :id "123456789123456789"
- :modified 0}
- :microformats {:type :like-of}}])}
- {})
- (mock/request :get "/api/mentions?url=http://localhost"))]
- (is (= (:status response) 200))
- (is (some? (:body response)))
- (when-not (-> response :body parse-string empty?)
- (is (-> response :body parse-string first (get "webmention") some?)))))
+ (let [response ((test-app nil
+ {:get-by-domain
+ (fn [_]
+ [{:webmention {:source "https://source.net"
+ :target "http://localhost"
+ :id "123456789123456789"
+ :modified 0}
+ :microformats {:type :like-of}}])}
+ {})
+ (mock/request :get "/api/mentions?url=http://localhost"))]
+ (is (= (:status response) 200))
+ (is (some? (:body response)))
+ (when-not (-> response :body parse-string empty?)
+ (is (-> response :body parse-string first (get "webmention") some?)))))
(testing "/api/count/:domain route"
- (let [response ((test-app nil {:get-by-domain (fn [_]
- [{:webmention {:source ""
- :target ""
- :id ""
- :modified 0}}])}
- {})
- (mock/request :get "/api/count/www.example.com"))]
- (is (= (:status response) 200))
- (is (= 1 (-> response :body parse-string (get "count") Long.)))))
+ (let [response ((test-app nil {:get-by-domain (fn [_]
+ [{:webmention {:source ""
+ :target ""
+ :id ""
+ :modified 0}}])}
+ {})
+ (mock/request :get "/api/count/www.example.com"))]
+ (is (= (:status response) 200))
+ (is (= 1 (-> response :body parse-string (get "count") Long.)))))
(testing "/api/count?url= route"
- (let [response ((test-app nil
- {:get-by-domain
- (fn [_] [{:webmention {:source "1"
- :target "http://localhost"}}])}
- {})
- (mock/request :get "/api/count?url=http://localhost"))]
- (is (= (:status response) 200))
- (is (= 1 (-> response :body parse-string (get "count") Long.)))))
+ (let [response ((test-app nil
+ {:get-by-domain
+ (fn [_] [{:webmention {:source "1"
+ :target "http://localhost"}}])}
+ {})
+ (mock/request :get "/api/count?url=http://localhost"))]
+ (is (= (:status response) 200))
+ (is (= 1 (-> response :body parse-string (get "count") Long.)))))
(testing "/api/mention/:id"
(let [response ((test-app nil {:get (fn [_]
- {:webmention {:source ""
- :target ""
- :id "xxx"
- :modified 0}})}
- {})
+ {:webmention {:source ""
+ :target ""
+ :id "xxx"
+ :modified 0}})}
+ {})
(mock/request :get "/api/mention/xxx"))]
(is (= (:status response) 200))))
(testing "/api/mention/?source=&target="
(let [response ((test-app nil {:get (fn [_ _]
- {:webmention {:source "1"
- :target "2"
- :id "xxx"
- :modified 0}})}
- {})
+ {:webmention {:source "1"
+ :target "2"
+ :id "xxx"
+ :modified 0}})}
+ {})
(mock/request :get "/api/mention/?source=1&?target=2"))]
(is (= (:status response) 200)))))
(deftest feed-route-test
(testing "RSS feed for allowed domains and has items"
(let [response ((test-app nil {:get-by-domain (fn [_] [{:webmention nil}])}
- {:allowed-target-domains "valid.com"})
+ {:allowed-target-domains "valid.com"})
(mock/request :get "/feed/valid.com"))]
(is (= (:status response) 404))))
(testing "RSS feed for allowed domains, but with no webmentions"
@@ -98,7 +98,7 @@
(let [response ((test-app nil nil {}) (mock/request :get "/invalid"))]
(is (= (:status response) 404)))))
-(deftest receiver-endpoint-test
+(deftest receiver-endpoint-test
(testing "/endpoint and /api/send should receive valid webmention and return 201"
(let [test-chan (chan)
app (test-app test-chan nil {:endpoint "/endpoint"
diff --git a/test/weepinbell/microformats_test.clj b/test/weepinbell/microformats_test.clj
index c7b41de..16b09d8 100644
--- a/test/weepinbell/microformats_test.clj
+++ b/test/weepinbell/microformats_test.clj
@@ -89,17 +89,17 @@
:published [52341243232]}}]}]}]
(is (= ["h-entry"]
(->> testdata-a sr/use-items sr/find-h-entry :type))))
- (testing "find-type should find all matched items on different layers"
- (let [testdata-a {:items [{:type ["h-feed"]
- :children [{:type ["h-entry"]
- :children [{:type ["h-card"]}]}
- {:type ["h-card"]}]}
- {:type ["h-card"]}]}]
- (is (= 3 (->> testdata-a sr/use-items sr/find-h-cards count)))))
- (testing "find-type should not return empty seq if nothing's matched"
- (let [testdata-a {:items [{:type ["h-feed"]
- :children []}]}]
- (is (->> testdata-a sr/use-items sr/find-h-entry empty?)))))
+ (testing "find-type should find all matched items on different layers"
+ (let [testdata-a {:items [{:type ["h-feed"]
+ :children [{:type ["h-entry"]
+ :children [{:type ["h-card"]}]}
+ {:type ["h-card"]}]}
+ {:type ["h-card"]}]}]
+ (is (= 3 (->> testdata-a sr/use-items sr/find-h-cards count)))))
+ (testing "find-type should not return empty seq if nothing's matched"
+ (let [testdata-a {:items [{:type ["h-feed"]
+ :children []}]}]
+ (is (->> testdata-a sr/use-items sr/find-h-entry empty?)))))
(testing "search photos in h-card"
(let [photo-url "https://test.com/photo.png"
testdata-a {:type ["h-card"]
diff --git a/test/weepinbell/storage_test.clj b/test/weepinbell/storage_test.clj
index 0555eac..53abbb6 100644
--- a/test/weepinbell/storage_test.clj
+++ b/test/weepinbell/storage_test.clj
@@ -12,9 +12,9 @@
(is (spec-check (edns/use-store "source.edn")))))
(testing "spec-check invalid storage vtables"
(doseq [check [{:get-by-domain (fn [_])}
- {:append (fn [_]) :get (fn [_])}
- "I am storage. Trust me"
- nil 1 [] {}]]
+ {:append (fn [_]) :get (fn [_])}
+ "I am storage. Trust me"
+ nil 1 [] {}]]
(is (not (spec-check check))))))
(def test-edn-file "tmp/testfile")
@@ -64,16 +64,16 @@
(let [id "987654321"
source "https://source.com"
target "https://target.com"
- data {:webmention {:id id
+ data {:webmention {:id id
:source source
:target target
:modified (System/currentTimeMillis)}}
data-wm (:webmention data)
- data-new (assoc data :webmention
- (assoc data-wm :modified
+ data-new (assoc data :webmention
+ (assoc data-wm :modified
(+ (System/currentTimeMillis) 1)))
- data-neo (assoc data-new :webmention
- (assoc data-wm :modified
+ data-neo (assoc data-new :webmention
+ (assoc data-wm :modified
(+ (System/currentTimeMillis) 1)))]
((:append storage) data)
((:update storage) id data-new)
@@ -87,7 +87,7 @@
(is (nil? ((:get storage) "source" nil)))
(is (nil? ((:get storage) nil nil))))
-(deftest general-storage-test
+(deftest general-storage-test
(doseq [storage storages]
(doseq [testcase [[test-append-and-get "appending webmention"]
[test-append-and-get-list "appending and getting by domain"]
diff --git a/test/weepinbell/utils_url_test.clj b/test/weepinbell/utils_url_test.clj
index d2f7c34..df73e2a 100644
--- a/test/weepinbell/utils_url_test.clj
+++ b/test/weepinbell/utils_url_test.clj
@@ -31,9 +31,9 @@
(is (= "/index.php" (url/get-path "https://www.example.com/index.php?page=abc")))
(is (= "/page/abc" (url/get-path "https://example.com/page/abc#anchor"))))
(testing "getting target"
- (is (= "https://www.example.com" (url/get-target {:webmention {:target "https://www.example.com"}})))))
+ (is (= "https://www.example.com" (url/get-target {:webmention {:target "https://www.example.com"}})))))
-(deftest url-equal-test
+(deftest url-equal-test
(testing "URL equality"
(is (url/url= "https://example.com/./abc" "https://example.com/abc"))
(is (url/url= "https://example.com/page/../abc" "https://example.com/abc"))
@@ -44,14 +44,14 @@
(defn- has-same-elements? [& colls]
(apply = (map set colls)))
-(deftest url-extract-test
+(deftest url-extract-test
(testing "Extracting URLs from string"
- (is (has-same-elements?
- ["https://test.com" "https://example.com"]
- (url/extract "two links: https://test.com and https://example.com")))
- (is (has-same-elements?
- ["http://www.example.com/index.php?page=123#anchor"]
- (url/extract "complicated one (http://www.example.com/index.php?page=123#anchor)")))))
+ (is (has-same-elements?
+ ["https://test.com" "https://example.com"]
+ (url/extract "two links: https://test.com and https://example.com")))
+ (is (has-same-elements?
+ ["http://www.example.com/index.php?page=123#anchor"]
+ (url/extract "complicated one (http://www.example.com/index.php?page=123#anchor)")))))
(deftest relative-predicate-test
(testing "Check if a URL is relative"
diff --git a/test/weepinbell/webhook_test.clj b/test/weepinbell/webhook_test.clj
index 6183060..593e709 100644
--- a/test/weepinbell/webhook_test.clj
+++ b/test/weepinbell/webhook_test.clj
@@ -101,7 +101,7 @@
(is (= (webhook/make-actions nil nil) []))
(is (= (webhook/make-actions :default []) []))))
-(deftest make-hooks-test
+(deftest make-hooks-test
(testing "Still need all four event keys even if config has less than four. (:on-create, :on-delete, :on-receive, :on-update)"
(let [config {:webhook {:on-create ["https://test.url/"]}}
hooks (webhook/make-hooks config)