forked from AkkomaGang/akkoma
[#1149] Fixed failing tests. Ensured Instance.set_unreachable/2 supports ISO 8601 datetime.
This commit is contained in:
parent
267262491e
commit
33a5fc4a70
6 changed files with 20 additions and 6 deletions
|
@ -1,8 +1,6 @@
|
||||||
defmodule Pleroma.DigestEmailWorker do
|
defmodule Pleroma.DigestEmailWorker do
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
@queue_name :digest_emails
|
|
||||||
|
|
||||||
def perform do
|
def perform do
|
||||||
config = Pleroma.Config.get([:email_notifications, :digest])
|
config = Pleroma.Config.get([:email_notifications, :digest])
|
||||||
negative_interval = -Map.fetch!(config, :interval)
|
negative_interval = -Map.fetch!(config, :interval)
|
||||||
|
@ -17,7 +15,7 @@ def perform do
|
||||||
select: u
|
select: u
|
||||||
)
|
)
|
||||||
|> Pleroma.Repo.all()
|
|> Pleroma.Repo.all()
|
||||||
|> Enum.each(&PleromaJobQueue.enqueue(@queue_name, __MODULE__, [&1]))
|
|> Enum.each(&PleromaJobQueue.enqueue(:digest_emails, __MODULE__, [&1]))
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
|
@ -90,7 +90,7 @@ def set_reachable(_), do: {:error, nil}
|
||||||
def set_unreachable(url_or_host, unreachable_since \\ nil)
|
def set_unreachable(url_or_host, unreachable_since \\ nil)
|
||||||
|
|
||||||
def set_unreachable(url_or_host, unreachable_since) when is_binary(url_or_host) do
|
def set_unreachable(url_or_host, unreachable_since) when is_binary(url_or_host) do
|
||||||
unreachable_since = unreachable_since || DateTime.utc_now()
|
unreachable_since = parse_datetime(unreachable_since) || NaiveDateTime.utc_now()
|
||||||
host = host(url_or_host)
|
host = host(url_or_host)
|
||||||
existing_record = Repo.get_by(Instance, %{host: host})
|
existing_record = Repo.get_by(Instance, %{host: host})
|
||||||
|
|
||||||
|
@ -114,4 +114,10 @@ def set_unreachable(url_or_host, unreachable_since) when is_binary(url_or_host)
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_unreachable(_, _), do: {:error, nil}
|
def set_unreachable(_, _), do: {:error, nil}
|
||||||
|
|
||||||
|
defp parse_datetime(datetime) when is_binary(datetime) do
|
||||||
|
NaiveDateTime.from_iso8601(datetime)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp parse_datetime(datetime), do: datetime
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,6 +28,8 @@ test "it goes through old direct conversations" do
|
||||||
{:ok, _activity} =
|
{:ok, _activity} =
|
||||||
CommonAPI.post(user, %{"visibility" => "direct", "status" => "hey @#{other_user.nickname}"})
|
CommonAPI.post(user, %{"visibility" => "direct", "status" => "hey @#{other_user.nickname}"})
|
||||||
|
|
||||||
|
Pleroma.ObanHelpers.perform_all()
|
||||||
|
|
||||||
Repo.delete_all(Conversation)
|
Repo.delete_all(Conversation)
|
||||||
Repo.delete_all(Conversation.Participation)
|
Repo.delete_all(Conversation.Participation)
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,12 @@ defmodule Pleroma.ObanHelpers do
|
||||||
|
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
|
|
||||||
|
def perform_all do
|
||||||
|
Oban.Job
|
||||||
|
|> Repo.all()
|
||||||
|
|> perform()
|
||||||
|
end
|
||||||
|
|
||||||
def perform(%Oban.Job{} = job) do
|
def perform(%Oban.Job{} = job) do
|
||||||
res = apply(String.to_existing_atom("Elixir." <> job.worker), :perform, [job])
|
res = apply(String.to_existing_atom("Elixir." <> job.worker), :perform, [job])
|
||||||
Repo.delete(job)
|
Repo.delete(job)
|
||||||
|
|
|
@ -249,7 +249,8 @@ test "it does not crash if MRF rejects the post" do
|
||||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||||
|> Poison.decode!()
|
|> Poison.decode!()
|
||||||
|
|
||||||
assert Federator.incoming_ap_doc(params) == :error
|
assert {:ok, job} = Federator.incoming_ap_doc(params)
|
||||||
|
assert :error = ObanHelpers.perform(job)
|
||||||
|
|
||||||
Pleroma.Config.put([:instance, :rewrite_policy], policies)
|
Pleroma.Config.put([:instance, :rewrite_policy], policies)
|
||||||
Pleroma.Config.put(:mrf_keyword, mrf_keyword_policy)
|
Pleroma.Config.put(:mrf_keyword, mrf_keyword_policy)
|
||||||
|
|
|
@ -22,7 +22,8 @@ defmodule Pleroma.Instances.InstanceTest do
|
||||||
|
|
||||||
describe "set_reachable/1" do
|
describe "set_reachable/1" do
|
||||||
test "clears `unreachable_since` of existing matching Instance record having non-nil `unreachable_since`" do
|
test "clears `unreachable_since` of existing matching Instance record having non-nil `unreachable_since`" do
|
||||||
instance = insert(:instance, unreachable_since: NaiveDateTime.utc_now())
|
unreachable_since = NaiveDateTime.to_iso8601(NaiveDateTime.utc_now())
|
||||||
|
instance = insert(:instance, unreachable_since: unreachable_since)
|
||||||
|
|
||||||
assert {:ok, instance} = Instance.set_reachable(instance.host)
|
assert {:ok, instance} = Instance.set_reachable(instance.host)
|
||||||
refute instance.unreachable_since
|
refute instance.unreachable_since
|
||||||
|
|
Loading…
Reference in a new issue