logo

pleroma

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

digest_emails_worker_test.exs (1593B)


  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.DigestEmailsWorkerTest do
  5. use Pleroma.DataCase
  6. import Pleroma.Factory
  7. alias Pleroma.Tests.ObanHelpers
  8. alias Pleroma.User
  9. alias Pleroma.Web.CommonAPI
  10. setup do: clear_config([:email_notifications, :digest])
  11. setup do
  12. Pleroma.Config.put([:email_notifications, :digest], %{
  13. active: true,
  14. inactivity_threshold: 7,
  15. interval: 7
  16. })
  17. user = insert(:user)
  18. date =
  19. Timex.now()
  20. |> Timex.shift(days: -10)
  21. |> Timex.to_naive_datetime()
  22. user2 = insert(:user, last_digest_emailed_at: date)
  23. {:ok, _} = User.switch_email_notifications(user2, "digest", true)
  24. CommonAPI.post(user, %{status: "hey @#{user2.nickname}!"})
  25. {:ok, user2: user2}
  26. end
  27. test "it sends digest emails", %{user2: user2} do
  28. Pleroma.Workers.Cron.DigestEmailsWorker.perform(%Oban.Job{})
  29. # Performing job(s) enqueued at previous step
  30. ObanHelpers.perform_all()
  31. assert_received {:email, email}
  32. assert email.to == [{user2.name, user2.email}]
  33. assert email.subject == "Your digest from #{Pleroma.Config.get(:instance)[:name]}"
  34. end
  35. test "it doesn't fail when a user has no email", %{user2: user2} do
  36. {:ok, _} = user2 |> Ecto.Changeset.change(%{email: nil}) |> Pleroma.Repo.update()
  37. Pleroma.Workers.Cron.DigestEmailsWorker.perform(%Oban.Job{})
  38. # Performing job(s) enqueued at previous step
  39. ObanHelpers.perform_all()
  40. end
  41. end