From 5839b57ea799e19c19bb6c4566779ed8405e029c Mon Sep 17 00:00:00 2001 From: eltrac Date: Sat, 9 May 2026 16:29:37 +0800 Subject: test(handler): test most of routes availability --- test/weepinbell/handler_test.clj | 65 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/test/weepinbell/handler_test.clj b/test/weepinbell/handler_test.clj index 2c5855c..8bfd17c 100644 --- a/test/weepinbell/handler_test.clj +++ b/test/weepinbell/handler_test.clj @@ -3,12 +3,69 @@ [ring.mock.request :as mock] [weepinbell.handler :refer [app]])) -(deftest test-app - (testing "main route" - (let [response (app (mock/request :get "/"))] +(defmacro test-mention-list-by-domain-route [mftype] + `(testing (str "/api/" ~mftype "/:domain route") + (let [~'response ((app {:get-by-domain (fn [~'_] + [{:webmention {:source "" + :target "" + :id "" + :modified 0}}])}) + (mock/request :get (str "/api/" ~mftype "/www.example")))] + (is (= (:status ~'response) 200))))) + +(defmacro test-mention-list-by-url-route [mftype] + `(testing (str "/api/" ~mftype "?url= route") + (let [~'response ((app {:get-by-domain (fn [~'_] + [{:webmention {:source "" + :target "http://localhost/" + :id "" + :modified 0}}])}) + (mock/request :get (str "/api/" ~mftype "?url=http://localhost")))] + (is (= (:status ~'response) 200))))) + +(deftest api-routes-test + (testing "homepage route" + (let [response ((app nil) (mock/request :get "/"))] + (is (= (:status response) 200)))) + + (test-mention-list-by-domain-route "mentions") + (test-mention-list-by-domain-route "likes") + (test-mention-list-by-domain-route "reposts") + (test-mention-list-by-domain-route "replies") + + (test-mention-list-by-url-route "mentions") + (test-mention-list-by-url-route "likes") + (test-mention-list-by-url-route "reposts") + (test-mention-list-by-url-route "replies") + + (testing "/api/mention/:id" + (let [response ((app {:get (fn [_] + {:webmention {:source "" + :target "" + :id "xxx" + :modified 0}})}) + (mock/request :get "/api/mention/xxx"))] + (is (= (:status response) 200)))) + + (testing "/api/mention/?source=&target=" + (let [response ((app {:get (fn [_ _] + {: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" + (let [response ((app nil) (mock/request :get "/feed/valid.com"))] (is (= (:status response) 200)))) + (testing "not found for disallowed domains" + (let [response ((app nil) (mock/request :get "/feed/invalid.com"))] + (is (= (:status response) 404))))) +(deftest not-found-route-test (testing "not-found route" - (let [response (app (mock/request :get "/invalid"))] + (let [response ((app nil) (mock/request :get "/invalid"))] (is (= (:status response) 404))))) -- cgit v1.2.3