summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-05-08 15:46:01 +0800
committereltrac <hi@eltr.ac>2026-05-08 15:46:01 +0800
commitbd9ace8fd9f11a935c85bf690d419dc5ab08e33d (patch)
treea7c6f95d90040ed3ec6c23ab4119f9c85e6f35ea
parent224853ba82cdb49297a643de0aa931db7661eba5 (diff)
fix(test): tests fail due to non-exisiting target URL
In verifier_test, fake target links were used because weepinbell did not make actual requests to target links until recent changes to verifier/verify-mention. Now target links must be valid URL because we need to determine it's Content-Type during verification. So the previous test cases need modifying.
-rw-r--r--test/weepinbell/verifier_test.clj55
1 files changed, 31 insertions, 24 deletions
diff --git a/test/weepinbell/verifier_test.clj b/test/weepinbell/verifier_test.clj
index 663aea4..b502d1a 100644
--- a/test/weepinbell/verifier_test.clj
+++ b/test/weepinbell/verifier_test.clj
@@ -2,49 +2,56 @@
(:require [clojure.test :refer [deftest testing is]]
[compojure.core :refer [GET routes]]
[ring.adapter.jetty :refer [run-jetty]]
- [weepinbell.verifier :as v]))
+ [weepinbell.verifier :as v]
+ [weepinbell.test-utility :refer [with-webmention]]))
(deftest verification-happy-paths-test
(testing "Test if processor can correctly verifies a Webmention."
- (let [handler (routes
- (GET "/1" []
- {:status 200 :headers {}
- :body (str "Oh I love this post:"
- " https://alice.blog/article/abc\n"
- " this is very clever"
- " and I find it inspiring")})
- (GET "/2" []
- {:status 206 :headers {}
- :body (str "Oh I love this post:"
- " https://alice.blog/article/abc\n"
- " this is very clever and I fi")}))
- server (run-jetty handler {:port 28888 :join? false})]
- (is (= true (v/verify-mention "http://localhost:28888/1"
- "https://alice.blog/article/abc")))
- (is (= true (v/verify-mention "http://localhost:28888/2"
- "https://alice.blog/article/abc")))
- (.stop server))))
+ (with-webmention :new ["/source" {:status 200
+ :headers {"Content-Type" "text/plain"}
+ :body (str "Oh I love this post:"
+ " http://localhost:38888/target\n"
+ " this is very clever"
+ " and I find it inspiring")}
+ "/target" {:status 200
+ :headers {"Content-Type" "text/plain"}}]
+ (is (= true (v/verify-mention "http://localhost:38888/source"
+ "http://localhost:38888/target")))))
+ (testing "Test if processor can correctly verifies a Webmention."
+ (with-webmention :new ["/source" {:status 206
+ :headers {"Content-Type" "text/plain"}
+ :body (str "Oh I love this post:"
+ " http://localhost:38888/target\n"
+ " this is very clev")}
+ "/target" {:status 200
+ :headers {"Content-Type" "text/plain"}}]
+ (is (= true (v/verify-mention "http://localhost:38888/source"
+ "http://localhost:38888/target"))))))
(deftest verification-error-cases-test
(testing "Test if processor can correctly verifies a Webmention."
(let [handler (routes
;; Cases that source respond with an error
(GET "/a" []
- {:status 404 :headers {}
+ {:status 404
+ :headers {"Content-Type" "text/plain"}
:body "Not Found."})
(GET "/b" []
- {:status 502 :headers {}
+ {:status 502
+ :headers {"Content-Type" "text/plain"}
:body "Bad Gateway"})
;; Cases that source does not contain target URL
(GET "/c" []
- {:status 200 :headers {}
+ {:status 200
+ :headers {"Content-Type" "text/plain"}
:body "I didn't mention anyone"})
(GET "/d" []
- {:status 200 :headers {}
+ {:status 200
+ :headers {"Content-Type" "text/plain"}
:body (str "I mentioned christ but not alice\n"
"https://chris.blog/archive/xxx")})
(GET "/e" []
- {:status 200 :headers {}
+ {:status 200
:body (str "I mentioned alice's other post\n"
"https://alice.blog/article/efg")}))
server (run-jetty handler {:port 28888 :join? false})]