Fix failing tests
authorMaxim Filippov <colixer@gmail.com>
Mon, 24 Dec 2018 21:29:13 +0000 (00:29 +0300)
committerMaxim Filippov <colixer@gmail.com>
Mon, 24 Dec 2018 21:29:13 +0000 (00:29 +0300)
lib/pleroma/activity.ex
lib/pleroma/notification.ex
lib/pleroma/web/activity_pub/transmogrifier.ex
test/activity_test.exs
test/web/ostatus/incoming_documents/delete_handling_test.exs

index 0845233ee7109b93ad1ccfdafeb18b7c37d97c40..be04363aab20b7c11db4534ed8844e083a599867 100644 (file)
@@ -108,17 +108,20 @@ defmodule Pleroma.Activity do
     %{
       id: data["id"],
       context: data["context"],
-      type: "tombstone",
+      type: "Tombstone",
       published: data["published"],
       deleted: deleted
     }
   end
 
   def swap_data_with_tombstone(activity) do
-    tombstone = get_tombstone(activity)
-
-    activity
-    |> change(%{data: tombstone})
-    |> Repo.update()
+    with tombstone = get_tombstone(activity),
+         Notification.clear(activity),
+         {:ok, changed_activity} =
+           activity
+           |> change(%{data: tombstone})
+           |> Repo.update() do
+      {:ok, changed_activity}
+    end
   end
 end
index 47f6b6ee73a5d9c5b9e5c9e43868e01d3c65f190..457cba9350244e748ffcb2454affbbc47631dab2 100644 (file)
@@ -75,10 +75,14 @@ defmodule Pleroma.Notification do
     end
   end
 
-  def clear(user) do
-    query = from(n in Notification, where: n.user_id == ^user.id)
+  def clear(%User{} = user) do
+    from(n in Notification, where: n.user_id == ^user.id)
+    |> Repo.delete_all()
+  end
 
-    Repo.delete_all(query)
+  def clear(%Activity{} = activity) do
+    from(n in Notification, where: n.activity_id == ^activity.id)
+    |> Repo.delete_all()
   end
 
   def dismiss(%{id: user_id} = _user, id) do
index e6af4b211a5cc81018b066110eb90ece0f5ec3e4..87514870de10ce59129712596d10c656200268f7 100644 (file)
@@ -586,7 +586,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
   end
 
   def set_reply_to_uri(%{"inReplyTo" => inReplyTo} = object) do
-    with false <- String.starts_with?(inReplyTo, "http"),
+    with false <- is_nil(inReplyTo),
+         false <- String.starts_with?(inReplyTo, "http"),
          {:ok, %{data: replied_to_object}} <- get_obj_helper(inReplyTo) do
       Map.put(object, "inReplyTo", replied_to_object["external_url"] || inReplyTo)
     else
index c47fe39dac9b2833f2e3f29e892a9bc024be9c32..dd11323b50c207537a839a57b2ae445c5bbf7734 100644 (file)
@@ -31,7 +31,7 @@ defmodule Pleroma.ActivityTest do
     deleted = DateTime.utc_now()
 
     assert Pleroma.Activity.get_tombstone(activity, deleted) == %{
-             id: activity.data["object"]["id"],
+             id: activity.data["id"],
              context: activity.data["context"],
              type: "Tombstone",
              published: activity.data["published"],
index 1e041e5b091b026260159e0a65193f21d1d54274..4e9c0f90fb68864e3f3fcee61e9b7f6767d88d7c 100644 (file)
@@ -23,9 +23,9 @@ defmodule Pleroma.Web.OStatus.DeleteHandlingTest do
 
       {:ok, [delete]} = OStatus.handle_incoming(incoming)
 
-      refute Repo.get(Activity, note.id)
-      refute Repo.get(Activity, like.id)
-      refute Object.get_by_ap_id(note.data["object"]["id"])
+      assert Repo.get(Activity, note.id).data["type"] == "Tombstone"
+      assert Repo.get(Activity, like.id).data["type"] == "Tombstone"
+      assert Object.get_by_ap_id(note.data["object"]["id"]).data["type"] == "Tombstone"
       assert Repo.get(Activity, second_note.id)
       assert Object.get_by_ap_id(second_note.data["object"]["id"])