2019-08-19 10:10:00 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.DigestEmailWorkerTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
alias Pleroma.DigestEmailWorker
|
2019-08-22 11:59:58 -06:00
|
|
|
alias Pleroma.Tests.ObanHelpers
|
2019-08-19 10:10:00 -06:00
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
|
|
|
|
test "it sends digest emails" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
date =
|
|
|
|
Timex.now()
|
|
|
|
|> Timex.shift(days: -10)
|
|
|
|
|> Timex.to_naive_datetime()
|
|
|
|
|
|
|
|
user2 = insert(:user, last_digest_emailed_at: date)
|
|
|
|
User.switch_email_notifications(user2, "digest", true)
|
|
|
|
CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}!"})
|
|
|
|
|
|
|
|
DigestEmailWorker.perform()
|
2019-08-22 11:59:58 -06:00
|
|
|
ObanHelpers.perform_all()
|
|
|
|
# Performing job(s) enqueued at previous step
|
|
|
|
ObanHelpers.perform_all()
|
2019-08-19 10:10:00 -06: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
|