summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoreltrac <hi@eltr.ac>2026-05-07 18:01:03 +0800
committereltrac <hi@eltr.ac>2026-05-07 18:01:30 +0800
commitd4a759ddfbcea30293432cfca58856ef7a30712b (patch)
tree71caa907acdf83fefd935fffde4be3ab98e3fa6d /test
parent81c60cb17c45bfb3746eb82bed85f0e97e28bab8 (diff)
refactor(test/processor): DRYness with macro
Diffstat (limited to 'test')
-rw-r--r--test/weepinbell/processor_test.clj102
1 files changed, 39 insertions, 63 deletions
diff --git a/test/weepinbell/processor_test.clj b/test/weepinbell/processor_test.clj
index 27f48be..5298f99 100644
--- a/test/weepinbell/processor_test.clj
+++ b/test/weepinbell/processor_test.clj
@@ -14,74 +14,50 @@
:delete (fn [_ _])
:get (fn [_ _])})
+(defmacro with-new-webmention [[source-route source-resp target-route target-resp] & body]
+ (let [source-url (str "http://localhost:38888" source-route)
+ target-url (str "http://localhost:38888" target-route)]
+ `(let [handler# (routes
+ (GET ~source-route [] ~source-resp)
+ (GET ~target-route [] ~target-resp))
+ ~'created (promise)
+ ~'storage (assoc mock-storage :append (fn [~'_] (deliver ~'created true)))
+ ~'server (run-jetty handler# {:port 38888 :join? false})]
+ (p/process-webmention {:s ~source-url :t ~target-url}
+ mock-callbacks
+ ~'storage)
+ ~@body
+ (.stop ~'server))))
+
(deftest new-webmention-test
(testing "Creating a new webmention."
- (let [handler (routes
- (GET "/source" []
- {:status 200
- :headers {"Content-Type" "text/plain"}
- :body (str "Oh I love this post: "
- "http://localhost:38888/target")})
- (GET "/target" []
- {:status 200
- :headers {"Content-Type" "text/plain"}
- :body "Nothing here"}))
- created (promise)
- storage (assoc mock-storage
- :append
- (fn [_] (deliver created true)))
- server (run-jetty handler {:port 38888 :join? false})]
- (p/process-webmention {:s "http://localhost:38888/source"
- :t "http://localhost:38888/target"}
- mock-callbacks
- storage)
- (is (deref created 1000 nil))
- (.stop server))))
+ (with-new-webmention ["/source" {:status 200
+ :headers {"Content-Type" "text/plain"}
+ :body (str "Oh I love this post: "
+ "http://localhost:38888/target")}
+ "/target" {:status 200
+ :headers {"Content-Type" "text/plain"}
+ :body "Nothing here"}]
+ (is (deref created 1000 nil)))))
(deftest new-webmention-content-type-fail-test
(testing "One of source and target has unsupported Content-Type"
- (let [handler (routes
- (GET "/source" []
- {:status 200
- :headers {"Content-Type" "text/plain"}
- :body (str "Oh I love this post: "
- "http://localhost:38888/target")})
- (GET "/target" []
- {:status 200
- :headers {"Content-Type" "application/json"}
- :body "Nothing here"}))
- created (promise)
- storage (assoc mock-storage
- :append
- (fn [_] (deliver created true)))
- server (run-jetty handler {:port 38888 :join? false})]
- (p/process-webmention {:s "http://localhost:38888/source"
- :t "http://localhost:38888/target"}
- mock-callbacks
- storage)
- (is (not (deref created 1000 nil)))
- (.stop server))))
+ (with-new-webmention ["/source" {:status 200
+ :headers {"Content-Type" "text/plain"}
+ :body (str "Oh I love this post: "
+ "http://localhost:38888/target")}
+ "/target" {:status 200
+ :headers {"Content-Type" "application/json"}
+ :body "Nothing here"}]
+ (is (not (deref created 1000 nil))))))
(deftest new-webmention-no-target-url-fail-test
(testing "The source does not contain target URL"
- (let [handler (routes
- (GET "/source" []
- {:status 200
- :headers {"Content-Type" "text/plain"}
- :body (str "Oh I love this post "
- "but I don't mention it.")})
- (GET "/target" []
- {:status 200
- :headers {"Content-Type" "application/json"}
- :body "Nothing here"}))
- created (promise)
- storage (assoc mock-storage
- :append
- (fn [_] (deliver created true)))
- server (run-jetty handler {:port 38888 :join? false})]
- (p/process-webmention {:s "http://localhost:38888/source"
- :t "http://localhost:38888/target"}
- mock-callbacks
- storage)
- (is (not (deref created 1000 nil)))
- (.stop server))))
+ (with-new-webmention ["/source" {:status 200
+ :headers {"Content-Type" "text/plain"}
+ :body (str "Oh I love this post "
+ "but I don't mention it.")}
+ "/target" {:status 200
+ :headers {"Content-Type" "application/json"}
+ :body "Nothing here"}]
+ (is (not (deref created 1000 nil))))))