PageRenderTime 53ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/pelrapeire/test/pelrapeire/repository/mail/mail_test.clj

https://github.com/mderosa/nimcram
Clojure | 54 lines | 47 code | 7 blank | 0 comment | 3 complexity | 6b10ca1893d9d6ef4ae99d695805b8a1 MD5 | raw file
  1. (ns pelrapeire.repository.mail.mail-test
  2. (:use clojure.test
  3. clojure.contrib.trace
  4. pelrapeire.repository.mail.invitationmessage
  5. pelrapeire.app.exception
  6. pelrapeire.repository.mail.mail)
  7. (:import (javax.mail Address SendFailedException)
  8. pelrapeire.repository.mail.invitationmessage.InvitationData
  9. (javax.mail.internet InternetAddress)))
  10. (defn mk-exception-proxy []
  11. (let [arr (make-array InternetAddress 1)]
  12. (do
  13. (aset arr 0 (InternetAddress. "ms@email.com"))
  14. (proxy [SendFailedException] []
  15. (getInvalidAddresses [] arr)
  16. (getValidSentAddresses [] arr)
  17. (getValidUnsentAddresses [] arr)))))
  18. (deftest test-sent-emails
  19. (testing "we should be able to aggregate emails from errors"
  20. (let [actual (sent-emails ["one@email.com"] (mk-exception-proxy))
  21. actual-strings (filter #(= java.lang.String (type %)) actual)]
  22. (is (= 2 (count actual)))
  23. (is (= (count actual) (count actual-strings))))))
  24. (def invitation (InvitationData. "from@email.com" ["to@email.com"] "hello" "AProject" "localhost:8080"))
  25. (def test-config {:activate.mail true
  26. :mail.smtp.host "smtp.server.com"
  27. :mail.smtp.auth "true"
  28. :mail.smtp.startls.enable, "true"
  29. :port 587
  30. :username "na"
  31. :password "na"})
  32. (deftest test-send-mail
  33. (testing "we should get a workable error message if we can not send an email"
  34. (let [actual (with-exception-translation (send-mail invitation test-config))]
  35. (is (:errors actual))
  36. (is (= "error sending mail, reason: No provider for smpt" (first (:errors actual)))))))
  37. (def test-config-off {:activate.mail false
  38. :mail.smtp.host "smtp.server.com"
  39. :mail.smtp.auth "true"
  40. :mail.smtp.startls.enable, "true"
  41. :port 587
  42. :username "na"
  43. :password "na"})
  44. (deftest test-send-mail-turned-off
  45. (testing "we should be able to turn off mail via a configuration setting for both production and testing"
  46. (let [actual (send-mail invitation test-config-off)]
  47. (is (nil? (:errors actual))))))