1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Workers.Cron.DigestEmailsWorkerTest do
10 alias Pleroma.Tests.ObanHelpers
12 alias Pleroma.Web.CommonAPI
14 setup do: clear_config([:email_notifications, :digest])
17 clear_config([:email_notifications, :digest], %{
19 inactivity_threshold: 7,
27 |> Timex.shift(days: -10)
28 |> Timex.to_naive_datetime()
30 user2 = insert(:user, last_digest_emailed_at: date)
31 {:ok, _} = User.switch_email_notifications(user2, "digest", true)
32 CommonAPI.post(user, %{status: "hey @#{user2.nickname}!"})
37 test "it sends digest emails", %{user2: user2} do
38 Pleroma.Workers.Cron.DigestEmailsWorker.perform(%Oban.Job{})
39 # Performing job(s) enqueued at previous step
40 ObanHelpers.perform_all()
42 assert_received {:email, email}
43 assert email.to == [{user2.name, user2.email}]
44 assert email.subject == "Your digest from #{Pleroma.Config.get(:instance)[:name]}"
47 test "it doesn't fail when a user has no email", %{user2: user2} do
48 {:ok, _} = user2 |> Ecto.Changeset.change(%{email: nil}) |> Pleroma.Repo.update()
50 Pleroma.Workers.Cron.DigestEmailsWorker.perform(%Oban.Job{})
51 # Performing job(s) enqueued at previous step
52 ObanHelpers.perform_all()