diff options
| -rw-r--r-- | src/weepinbell/webhook.clj | 19 | ||||
| -rw-r--r-- | test/weepinbell/webhook_test.clj | 4 |
2 files changed, 12 insertions, 11 deletions
diff --git a/src/weepinbell/webhook.clj b/src/weepinbell/webhook.clj index c93b74a..e777e92 100644 --- a/src/weepinbell/webhook.clj +++ b/src/weepinbell/webhook.clj @@ -13,15 +13,14 @@ ;; utilities (defn- send-webhook [url opts] - (if (valid-http-url? url) - (client/post url opts - (fn async-callback [{:keys [status _ _ error]}] - (cond - error (timbre/error "error ocurred sending webhook to" url ":" error) - (>= status 500) (timbre/error "something's wrong with webhook server of" url) - (>= status 400) (timbre/error "webhook url is invalid:" url) - :else (timbre/info "request sent to" url)))) - (timbre/warn "webhook url not valid, skipped" url))) + {:pre [(valid-http-url? url) (map? opts)]} + (client/post url opts + (fn async-callback [{:keys [status _ _ error]}] + (cond + error (timbre/error "error ocurred sending webhook to" url ":" error) + (>= status 500) (timbre/error "something's wrong with webhook server of" url) + (>= status 400) (timbre/error "webhook url is invalid:" url) + :else (timbre/info "request sent to" url))))) (defn make-request [event-key data request-fn] (cond @@ -41,7 +40,7 @@ source (:source webmention) target (:target webmention)] (-> url - (string/replace "{event}" (or (name event-key) "")) + (string/replace "{event}" (name event-key)) (string/replace "{target}" (or target "")) (string/replace "{source}" (or source "")) (string/replace "{target-encoded}" (if target (url-encode target) "")) diff --git a/test/weepinbell/webhook_test.clj b/test/weepinbell/webhook_test.clj index 593e709..f7530cc 100644 --- a/test/weepinbell/webhook_test.clj +++ b/test/weepinbell/webhook_test.clj @@ -89,7 +89,9 @@ (testing "Webhook constructing request options with custom functions" (let [custom-map {:body "customized!"}] (is (= (webhook/make-request :on-receive test-wm-data (fn [& _] custom-map)) - custom-map))))) + custom-map)))) + (testing "Unknown request-fn type" + (is (nil? (webhook/make-request :on-delete test-wm-data "I am a function"))))) (deftest make-actions-test (testing "Constructing action map" |
