logo

pleroma

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

welcome_email_test.exs (1783B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.User.WelcomeEmailTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Config
  7. alias Pleroma.Tests.ObanHelpers
  8. alias Pleroma.User.WelcomeEmail
  9. import Pleroma.Factory
  10. import Swoosh.TestAssertions
  11. setup do: clear_config([:welcome])
  12. describe "send_email/1" do
  13. test "send a welcome email" do
  14. user = insert(:user, name: "Jimm")
  15. Config.put([:welcome, :email, :enabled], true)
  16. Config.put([:welcome, :email, :sender], "welcome@pleroma.app")
  17. Config.put(
  18. [:welcome, :email, :subject],
  19. "Hello, welcome to pleroma: <%= instance_name %>"
  20. )
  21. Config.put(
  22. [:welcome, :email, :html],
  23. "<h1>Hello <%= user.name %>.</h1> <p>Welcome to <%= instance_name %></p>"
  24. )
  25. instance_name = Config.get([:instance, :name])
  26. {:ok, _job} = WelcomeEmail.send_email(user)
  27. ObanHelpers.perform_all()
  28. assert_email_sent(
  29. from: {instance_name, "welcome@pleroma.app"},
  30. to: {user.name, user.email},
  31. subject: "Hello, welcome to pleroma: #{instance_name}",
  32. html_body: "<h1>Hello #{user.name}.</h1> <p>Welcome to #{instance_name}</p>"
  33. )
  34. Config.put([:welcome, :email, :sender], {"Pleroma App", "welcome@pleroma.app"})
  35. {:ok, _job} = WelcomeEmail.send_email(user)
  36. ObanHelpers.perform_all()
  37. assert_email_sent(
  38. from: {"Pleroma App", "welcome@pleroma.app"},
  39. to: {user.name, user.email},
  40. subject: "Hello, welcome to pleroma: #{instance_name}",
  41. html_body: "<h1>Hello #{user.name}.</h1> <p>Welcome to #{instance_name}</p>"
  42. )
  43. end
  44. end
  45. end