[#1149] Fixed failing tests. Ensured Instance.set_unreachable/2 supports ISO 8601...
authorIvan Tashkinov <ivantashkinov@gmail.com>
Sat, 10 Aug 2019 17:38:31 +0000 (20:38 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Sat, 10 Aug 2019 17:38:31 +0000 (20:38 +0300)
lib/pleroma/digest_email_worker.ex
lib/pleroma/instances/instance.ex
test/conversation_test.exs
test/support/oban_helpers.ex
test/web/federator_test.exs
test/web/instances/instance_test.exs

index 18e67d39b07cd5d7176f36c95cdd84b539f1299c..3b0e2bca695d3671653fa7ed50537c33e26d1799 100644 (file)
@@ -1,8 +1,6 @@
 defmodule Pleroma.DigestEmailWorker do
   import Ecto.Query
 
-  @queue_name :digest_emails
-
   def perform do
     config = Pleroma.Config.get([:email_notifications, :digest])
     negative_interval = -Map.fetch!(config, :interval)
@@ -17,7 +15,7 @@ defmodule Pleroma.DigestEmailWorker do
       select: u
     )
     |> Pleroma.Repo.all()
-    |> Enum.each(&PleromaJobQueue.enqueue(@queue_name, __MODULE__, [&1]))
+    |> Enum.each(&PleromaJobQueue.enqueue(:digest_emails, __MODULE__, [&1]))
   end
 
   @doc """
index 4d7ed4ca1076abe35b697f2e29002f739b2124c8..544c4b687c8d5e0a9c13a3247fa8e731609b0188 100644 (file)
@@ -90,7 +90,7 @@ defmodule Pleroma.Instances.Instance do
   def set_unreachable(url_or_host, unreachable_since \\ nil)
 
   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)
     existing_record = Repo.get_by(Instance, %{host: host})
 
@@ -114,4 +114,10 @@ defmodule Pleroma.Instances.Instance do
   end
 
   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
index aa193e0d40dadf907f974ef2cfa378ee7788844e..2ebbcab761aaf1a5c6d868a2978284dc805b0d75 100644 (file)
@@ -28,6 +28,8 @@ defmodule Pleroma.ConversationTest do
     {:ok, _activity} =
       CommonAPI.post(user, %{"visibility" => "direct", "status" => "hey @#{other_user.nickname}"})
 
+    Pleroma.ObanHelpers.perform_all()
+
     Repo.delete_all(Conversation)
     Repo.delete_all(Conversation.Participation)
 
index 54b5a95662314a943fa0eecf9e34551235e310f9..ecc03ba1ab87f23d64ae2b99c69367a9039bdbe1 100644 (file)
@@ -9,6 +9,12 @@ defmodule Pleroma.ObanHelpers do
 
   alias Pleroma.Repo
 
+  def perform_all do
+    Oban.Job
+    |> Repo.all()
+    |> perform()
+  end
+
   def perform(%Oban.Job{} = job) do
     res = apply(String.to_existing_atom("Elixir." <> job.worker), :perform, [job])
     Repo.delete(job)
index d3a28d50e72e129165b2d04d2b0d71f72947ba5e..e0be4342b90a8f0ef974c123b465f8d072382cd4 100644 (file)
@@ -249,7 +249,8 @@ defmodule Pleroma.Web.FederatorTest do
         File.read!("test/fixtures/mastodon-post-activity.json")
         |> 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(:mrf_keyword, mrf_keyword_policy)
index d28730994567b66bff6f812a137729fc257e46f8..a1bdd45d3d2b115387c656bc55bbe379b8d9ac97 100644 (file)
@@ -22,7 +22,8 @@ defmodule Pleroma.Instances.InstanceTest do
 
   describe "set_reachable/1" 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)
       refute instance.unreachable_since