logo

pleroma

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

digest_test.exs (1290B)


  1. defmodule Mix.Tasks.Pleroma.DigestTest do
  2. use Pleroma.DataCase
  3. import Pleroma.Factory
  4. import Swoosh.TestAssertions
  5. alias Pleroma.Tests.ObanHelpers
  6. alias Pleroma.Web.CommonAPI
  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. describe "pleroma.digest test" do
  16. test "Sends digest to the given user" do
  17. user1 = insert(:user)
  18. user2 = insert(:user)
  19. Enum.each(0..10, fn i ->
  20. {:ok, _activity} =
  21. CommonAPI.post(user1, %{
  22. status: "hey ##{i} @#{user2.nickname}!"
  23. })
  24. end)
  25. yesterday =
  26. NaiveDateTime.add(
  27. NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
  28. -60 * 60 * 24,
  29. :second
  30. )
  31. {:ok, yesterday_date} = Timex.format(yesterday, "%F", :strftime)
  32. :ok = Mix.Tasks.Pleroma.Digest.run(["test", user2.nickname, yesterday_date])
  33. ObanHelpers.perform_all()
  34. assert_receive {:mix_shell, :info, [message]}
  35. assert message =~ "Digest email have been sent"
  36. assert_email_sent(
  37. to: {user2.name, user2.email},
  38. html_body: ~r/here is what you've missed!/i
  39. )
  40. end
  41. end
  42. end