diff options
| author | eltrac <hi@eltr.ac> | 2026-10-13 21:27:29 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-10-13 21:27:29 +0800 |
| commit | 3989bf6fbbb242ad5bd6a1d1f91f70a6a222f8e2 (patch) | |
| tree | 435dfee792ec80de7b4cfc233efd53fab579529e /test | |
| parent | 29344c41cc11c2d5d34bdfdbcfb8d093fad1002a (diff) | |
style: cljfmt everything
Diffstat (limited to 'test')
| -rw-r--r-- | test/weepinbell/core_test.clj | 2 | ||||
| -rw-r--r-- | test/weepinbell/handler_test.clj | 106 | ||||
| -rw-r--r-- | test/weepinbell/microformats_test.clj | 22 | ||||
| -rw-r--r-- | test/weepinbell/storage_test.clj | 18 | ||||
| -rw-r--r-- | test/weepinbell/utils_url_test.clj | 18 | ||||
| -rw-r--r-- | test/weepinbell/webhook_test.clj | 2 |
6 files changed, 84 insertions, 84 deletions
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) |
