diff options
| author | eltrac <hi@eltr.ac> | 2026-10-30 11:46:40 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-10-30 11:46:40 +0800 |
| commit | a5f0d0dc9e73ba46a4ff974a256de770d70ac788 (patch) | |
| tree | 814f8d59a3dd1c76716fe181ad07f8e8ec4cb03f /src | |
| parent | dd4c7ca7850f166af4997912a3ded5639bd14a56 (diff) | |
test, webhook: tidy up webhook; add tests
- (send-webhook) does not need to validate URLs; (trigger) already does
that; replace validation logic with :pre conditional
- (make-request) does not need to fallback to empty string when
event-key is nil. it should never be nil.
Diffstat (limited to 'src')
| -rw-r--r-- | src/weepinbell/webhook.clj | 19 |
1 files changed, 9 insertions, 10 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) "")) |
