logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

email_test.exs (2936B)


  1. defmodule Mix.Tasks.Pleroma.EmailTest do
  2. use Pleroma.DataCase
  3. import Swoosh.TestAssertions
  4. alias Pleroma.Config
  5. alias Pleroma.Tests.ObanHelpers
  6. import Pleroma.Factory
  7. setup_all do
  8. Mix.shell(Mix.Shell.Process)
  9. on_exit(fn ->
  10. Mix.shell(Mix.Shell.IO)
  11. end)
  12. :ok
  13. end
  14. setup do: clear_config([Pleroma.Emails.Mailer, :enabled], true)
  15. setup do: clear_config([:instance, :account_activation_required], true)
  16. describe "pleroma.email test" do
  17. test "Sends test email with no given address" do
  18. mail_to = Config.get([:instance, :email])
  19. :ok = Mix.Tasks.Pleroma.Email.run(["test"])
  20. ObanHelpers.perform_all()
  21. assert_receive {:mix_shell, :info, [message]}
  22. assert message =~ "Test email has been sent"
  23. assert_email_sent(
  24. to: mail_to,
  25. html_body: ~r/a test email was requested./i
  26. )
  27. end
  28. test "Sends test email with given address" do
  29. mail_to = "hewwo@example.com"
  30. :ok = Mix.Tasks.Pleroma.Email.run(["test", "--to", mail_to])
  31. ObanHelpers.perform_all()
  32. assert_receive {:mix_shell, :info, [message]}
  33. assert message =~ "Test email has been sent"
  34. assert_email_sent(
  35. to: mail_to,
  36. html_body: ~r/a test email was requested./i
  37. )
  38. end
  39. test "Sends confirmation emails" do
  40. local_user1 =
  41. insert(:user, %{
  42. confirmation_pending: true,
  43. confirmation_token: "mytoken",
  44. deactivated: false,
  45. email: "local1@pleroma.com",
  46. local: true
  47. })
  48. local_user2 =
  49. insert(:user, %{
  50. confirmation_pending: true,
  51. confirmation_token: "mytoken",
  52. deactivated: false,
  53. email: "local2@pleroma.com",
  54. local: true
  55. })
  56. :ok = Mix.Tasks.Pleroma.Email.run(["resend_confirmation_emails"])
  57. ObanHelpers.perform_all()
  58. assert_email_sent(to: {local_user1.name, local_user1.email})
  59. assert_email_sent(to: {local_user2.name, local_user2.email})
  60. end
  61. test "Does not send confirmation email to inappropriate users" do
  62. # confirmed user
  63. insert(:user, %{
  64. confirmation_pending: false,
  65. confirmation_token: "mytoken",
  66. deactivated: false,
  67. email: "confirmed@pleroma.com",
  68. local: true
  69. })
  70. # remote user
  71. insert(:user, %{
  72. deactivated: false,
  73. email: "remote@not-pleroma.com",
  74. local: false
  75. })
  76. # deactivated user =
  77. insert(:user, %{
  78. deactivated: true,
  79. email: "deactivated@pleroma.com",
  80. local: false
  81. })
  82. # invisible user
  83. insert(:user, %{
  84. deactivated: false,
  85. email: "invisible@pleroma.com",
  86. local: true,
  87. invisible: true
  88. })
  89. :ok = Mix.Tasks.Pleroma.Email.run(["resend_confirmation_emails"])
  90. ObanHelpers.perform_all()
  91. refute_email_sent()
  92. end
  93. end
  94. end