Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow envelope sender override per message #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions test/postal/test/smtp.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@
(:use [clojure.test])
(:require [postal.smtp :as smtp] :reload))

(defn props [attrs]
(let [msg {:from "foo@bar.dom"
:to "baz@bar.dom"
:subject "Test"
:body "Hello."}]
(binding [smtp/smtp-send* (fn [& args] args)]
(->>
(smtp/smtp-send attrs [msg])
first
.getProperties
(into {})))))
(defn props
([attrs]
(let [msg {:from "foo@bar.dom"
:to "baz@bar.dom"
:subject "Test"
:body "Hello."}]
(props attrs msg)))
([attrs msg]
(binding [smtp/smtp-send* (fn [& args] args)]
(->>
(smtp/smtp-send attrs [msg])
first
.getProperties
(into {})))))

(defmacro is-props [input want]
`(is (= (props ~input) ~want)))
Expand Down Expand Up @@ -66,3 +69,19 @@
{"mail.smtp.port" 25
"mail.smtp.auth" "false"
"mail.smtp.host" "smtp.bar.dom"}))

(defmacro is-sender [expected props]
`(is (= ~expected (get ~props "mail.smtp.from"))))

(deftest test-sender
(let [attrs-with {:sender "attrs-sender@bar.dom"}
msg-with {:sender "msg-sender@bar.dom"
:from "foo@bar.dom"
:to "baz@bar.dom"
:subject "Test"
:body "Hello."}
attrs-without (dissoc attrs-with :sender)
msg-without (dissoc msg-with :sender)]
(is-sender "attrs-sender@bar.dom" (props attrs-with msg-without))
(is-sender "msg-sender@bar.dom" (props attrs-with msg-with))
(is-sender "msg-sender@bar.dom" (props attrs-without msg-with))))