logo

pleroma

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

new_users_digest_worker_test.exs (1585B)


  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.Workers.Cron.NewUsersDigestWorkerTest do
  5. use Pleroma.DataCase
  6. import Pleroma.Factory
  7. alias Pleroma.Tests.ObanHelpers
  8. alias Pleroma.Web.CommonAPI
  9. alias Pleroma.Workers.Cron.NewUsersDigestWorker
  10. test "it sends new users digest emails" do
  11. yesterday = NaiveDateTime.utc_now() |> Timex.shift(days: -1)
  12. admin = insert(:user, %{is_admin: true})
  13. user = insert(:user, %{inserted_at: yesterday})
  14. user2 = insert(:user, %{inserted_at: yesterday})
  15. CommonAPI.post(user, %{status: "cofe"})
  16. NewUsersDigestWorker.perform(%Oban.Job{})
  17. ObanHelpers.perform_all()
  18. assert_received {:email, email}
  19. assert email.to == [{admin.name, admin.email}]
  20. assert email.subject == "#{Pleroma.Config.get([:instance, :name])} New Users"
  21. refute email.html_body =~ admin.nickname
  22. assert email.html_body =~ user.nickname
  23. assert email.html_body =~ user2.nickname
  24. assert email.html_body =~ "cofe"
  25. assert email.html_body =~ "#{Pleroma.Web.Endpoint.url()}/static/logo.png"
  26. end
  27. test "it doesn't fail when admin has no email" do
  28. yesterday = NaiveDateTime.utc_now() |> Timex.shift(days: -1)
  29. insert(:user, %{is_admin: true, email: nil})
  30. insert(:user, %{inserted_at: yesterday})
  31. user = insert(:user, %{inserted_at: yesterday})
  32. CommonAPI.post(user, %{status: "cofe"})
  33. NewUsersDigestWorker.perform(%Oban.Job{})
  34. ObanHelpers.perform_all()
  35. end
  36. end