2020-10-12 11:00:50 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2022-02-25 23:11:42 -07:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-10-12 11:00:50 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-06-03 17:48:21 -06:00
|
|
|
defmodule Mix.Tasks.Pleroma.DigestTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
import Swoosh.TestAssertions
|
|
|
|
|
2019-08-14 12:42:21 -06:00
|
|
|
alias Pleroma.Tests.ObanHelpers
|
2019-06-03 17:48:21 -06:00
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
|
|
|
|
setup_all do
|
|
|
|
Mix.shell(Mix.Shell.Process)
|
|
|
|
|
|
|
|
on_exit(fn ->
|
|
|
|
Mix.shell(Mix.Shell.IO)
|
|
|
|
end)
|
|
|
|
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
2020-08-19 03:57:29 -06:00
|
|
|
setup do: clear_config([Pleroma.Emails.Mailer, :enabled], true)
|
|
|
|
|
2019-06-03 17:48:21 -06:00
|
|
|
describe "pleroma.digest test" do
|
|
|
|
test "Sends digest to the given user" do
|
|
|
|
user1 = insert(:user)
|
|
|
|
user2 = insert(:user)
|
|
|
|
|
|
|
|
Enum.each(0..10, fn i ->
|
|
|
|
{:ok, _activity} =
|
|
|
|
CommonAPI.post(user1, %{
|
2020-05-12 13:59:26 -06:00
|
|
|
status: "hey ##{i} @#{user2.nickname}!"
|
2019-06-03 17:48:21 -06:00
|
|
|
})
|
|
|
|
end)
|
|
|
|
|
2019-06-03 18:38:53 -06:00
|
|
|
yesterday =
|
|
|
|
NaiveDateTime.add(
|
|
|
|
NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
|
|
|
|
-60 * 60 * 24,
|
|
|
|
:second
|
|
|
|
)
|
2019-06-03 17:48:21 -06:00
|
|
|
|
2019-06-03 18:38:53 -06:00
|
|
|
{:ok, yesterday_date} = Timex.format(yesterday, "%F", :strftime)
|
|
|
|
|
|
|
|
:ok = Mix.Tasks.Pleroma.Digest.run(["test", user2.nickname, yesterday_date])
|
|
|
|
|
2019-08-14 12:42:21 -06:00
|
|
|
ObanHelpers.perform_all()
|
|
|
|
|
2019-06-03 18:38:53 -06:00
|
|
|
assert_receive {:mix_shell, :info, [message]}
|
2019-06-03 18:07:49 -06:00
|
|
|
assert message =~ "Digest email have been sent"
|
|
|
|
|
2019-06-03 17:48:21 -06:00
|
|
|
assert_email_sent(
|
|
|
|
to: {user2.name, user2.email},
|
2019-08-14 07:46:05 -06:00
|
|
|
html_body: ~r/here is what you've missed!/i
|
2019-06-03 17:48:21 -06:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|