2019-08-19 12:10:00 -04:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-02 00:08:45 -05:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-08-19 12:10:00 -04:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-11-27 07:59:13 -05:00
|
|
|
defmodule Pleroma.Workers.Cron.DigestEmailsWorkerTest do
|
2019-08-19 12:10:00 -04:00
|
|
|
use Pleroma.DataCase
|
2019-11-27 07:59:13 -05:00
|
|
|
|
2019-08-19 12:10:00 -04:00
|
|
|
import Pleroma.Factory
|
|
|
|
|
2019-08-22 13:59:58 -04:00
|
|
|
alias Pleroma.Tests.ObanHelpers
|
2019-08-19 12:10:00 -04:00
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
|
2019-11-27 07:59:13 -05:00
|
|
|
clear_config([:email_notifications, :digest])
|
|
|
|
|
2019-08-19 12:10:00 -04:00
|
|
|
test "it sends digest emails" do
|
2019-11-27 07:59:13 -05:00
|
|
|
Pleroma.Config.put([:email_notifications, :digest], %{
|
|
|
|
active: true,
|
|
|
|
inactivity_threshold: 7,
|
|
|
|
interval: 7
|
|
|
|
})
|
|
|
|
|
2019-08-19 12:10:00 -04: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 14:59:21 -04:00
|
|
|
{:ok, _} = User.switch_email_notifications(user2, "digest", true)
|
2019-08-19 12:10:00 -04:00
|
|
|
CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}!"})
|
|
|
|
|
2019-11-27 07:59:13 -05:00
|
|
|
Pleroma.Workers.Cron.DigestEmailsWorker.perform(:opts, :pid)
|
2019-08-22 13:59:58 -04:00
|
|
|
# Performing job(s) enqueued at previous step
|
|
|
|
ObanHelpers.perform_all()
|
2019-08-19 12:10:00 -04:00
|
|
|
|
|
|
|
assert_received {:email, email}
|
|
|
|
assert email.to == [{user2.name, user2.email}]
|
|
|
|
assert email.subject == "Your digest from #{Pleroma.Config.get(:instance)[:name]}"
|
|
|
|
end
|
|
|
|
end
|