X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fworkers%2Fcron%2Fdigest_emails_worker_test.exs;h=f9bc50db52cc825a87f9dd2a0d5cfdfaec1db9d8;hb=780ac9cedb9a5df96bce763f586779c4297b0f0a;hp=073615d9e5623b15219c44a6a711ca7410caa01b;hpb=2f1c61255ff95a1d21a751cb78da3c031ccdd692;p=akkoma
diff --git a/test/workers/cron/digest_emails_worker_test.exs b/test/workers/cron/digest_emails_worker_test.exs
index 073615d9e..f9bc50db5 100644
--- a/test/workers/cron/digest_emails_worker_test.exs
+++ b/test/workers/cron/digest_emails_worker_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Workers.Cron.DigestEmailsWorkerTest do
@@ -11,9 +11,9 @@ defmodule Pleroma.Workers.Cron.DigestEmailsWorkerTest do
alias Pleroma.User
alias Pleroma.Web.CommonAPI
- clear_config([:email_notifications, :digest])
+ setup do: clear_config([:email_notifications, :digest])
- test "it sends digest emails" do
+ setup do
Pleroma.Config.put([:email_notifications, :digest], %{
active: true,
inactivity_threshold: 7,
@@ -29,8 +29,12 @@ defmodule Pleroma.Workers.Cron.DigestEmailsWorkerTest do
user2 = insert(:user, last_digest_emailed_at: date)
{:ok, _} = User.switch_email_notifications(user2, "digest", true)
- CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}!"})
+ CommonAPI.post(user, %{status: "hey @#{user2.nickname}!"})
+ {:ok, user2: user2}
+ end
+
+ test "it sends digest emails", %{user2: user2} do
Pleroma.Workers.Cron.DigestEmailsWorker.perform(:opts, :pid)
# Performing job(s) enqueued at previous step
ObanHelpers.perform_all()
@@ -39,4 +43,12 @@ defmodule Pleroma.Workers.Cron.DigestEmailsWorkerTest do
assert email.to == [{user2.name, user2.email}]
assert email.subject == "Your digest from #{Pleroma.Config.get(:instance)[:name]}"
end
+
+ test "it doesn't fail when a user has no email", %{user2: user2} do
+ {:ok, _} = user2 |> Ecto.Changeset.change(%{email: nil}) |> Pleroma.Repo.update()
+
+ Pleroma.Workers.Cron.DigestEmailsWorker.perform(:opts, :pid)
+ # Performing job(s) enqueued at previous step
+ ObanHelpers.perform_all()
+ end
end