2019-08-19 16:10:00 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-08-19 16:10:00 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-11-27 12:59:13 +00:00
|
|
|
defmodule Pleroma.Workers.Cron.DigestEmailsWorkerTest do
|
2019-08-19 16:10:00 +00:00
|
|
|
use Pleroma.DataCase
|
2019-11-27 12:59:13 +00:00
|
|
|
|
2019-08-19 16:10:00 +00:00
|
|
|
import Pleroma.Factory
|
|
|
|
|
2019-08-22 17:59:58 +00:00
|
|
|
alias Pleroma.Tests.ObanHelpers
|
2019-08-19 16:10:00 +00:00
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
|
2020-03-20 15:33:00 +00:00
|
|
|
setup do: clear_config([:email_notifications, :digest])
|
2019-11-27 12:59:13 +00:00
|
|
|
|
2020-02-27 13:27:49 +00:00
|
|
|
setup do
|
2021-01-26 17:58:43 +00:00
|
|
|
clear_config([:email_notifications, :digest], %{
|
2019-11-27 12:59:13 +00:00
|
|
|
active: true,
|
|
|
|
inactivity_threshold: 7,
|
|
|
|
interval: 7
|
|
|
|
})
|
|
|
|
|
2019-08-19 16:10:00 +00:00
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
date =
|
|
|
|
Timex.now()
|
|
|
|
|> Timex.shift(days: -10)
|
|
|
|
|> Timex.to_naive_datetime()
|
|
|
|
|
|
|
|
user2 = insert(:user, last_digest_emailed_at: date)
|
2019-10-16 18:59:21 +00:00
|
|
|
{:ok, _} = User.switch_email_notifications(user2, "digest", true)
|
2020-05-12 19:59:26 +00:00
|
|
|
CommonAPI.post(user, %{status: "hey @#{user2.nickname}!"})
|
2019-08-19 16:10:00 +00:00
|
|
|
|
2020-02-27 13:27:49 +00:00
|
|
|
{:ok, user2: user2}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it sends digest emails", %{user2: user2} do
|
2020-06-23 12:09:01 +00:00
|
|
|
Pleroma.Workers.Cron.DigestEmailsWorker.perform(%Oban.Job{})
|
2019-08-22 17:59:58 +00:00
|
|
|
# Performing job(s) enqueued at previous step
|
|
|
|
ObanHelpers.perform_all()
|
2019-08-19 16:10:00 +00:00
|
|
|
|
2023-08-01 10:43:50 +00:00
|
|
|
assert_receive {:email, email}
|
2019-08-19 16:10:00 +00:00
|
|
|
assert email.to == [{user2.name, user2.email}]
|
|
|
|
assert email.subject == "Your digest from #{Pleroma.Config.get(:instance)[:name]}"
|
|
|
|
end
|
2020-02-27 13:27:49 +00:00
|
|
|
|
|
|
|
test "it doesn't fail when a user has no email", %{user2: user2} do
|
|
|
|
{:ok, _} = user2 |> Ecto.Changeset.change(%{email: nil}) |> Pleroma.Repo.update()
|
|
|
|
|
2020-06-23 12:09:01 +00:00
|
|
|
Pleroma.Workers.Cron.DigestEmailsWorker.perform(%Oban.Job{})
|
2020-02-27 13:27:49 +00:00
|
|
|
# Performing job(s) enqueued at previous step
|
|
|
|
ObanHelpers.perform_all()
|
|
|
|
end
|
2019-08-19 16:10:00 +00:00
|
|
|
end
|