summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-05-09 16:29:37 +0800
committereltrac <hi@eltr.ac>2026-05-09 16:29:37 +0800
commit5839b57ea799e19c19bb6c4566779ed8405e029c (patch)
tree7941ad7bff26286b2b2d4309b3cfccd001f68bfc /test
parent86fd9117e51884dc21cd7b839068f667b5a66051 (diff)
test(handler): test most of routes availability
Diffstat (limited to 'test')
-rw-r--r--test/weepinbell/handler_test.clj65
1 files 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)))))