Fix tests
authorRoman Chvanikov <chvanikoff@gmail.com>
Sun, 28 Apr 2019 20:44:04 +0000 (03:44 +0700)
committerlain <lain@soykaf.club>
Wed, 1 May 2019 17:03:55 +0000 (19:03 +0200)
lib/pleroma/conversation.ex
test/conversation/participation_test.exs
test/conversation_test.exs
test/web/activity_pub/activity_pub_test.exs

index d9c84cb1b62d4375770b9f45726457ce29f59f02..e6a4ccc85c4989fa22117e831dd5a6860118d2e3 100644 (file)
@@ -47,9 +47,10 @@ defmodule Pleroma.Conversation do
   """
   def create_or_bump_for(activity) do
     with true <- Pleroma.Web.ActivityPub.Visibility.is_direct?(activity),
+         object <- Pleroma.Object.normalize(activity),
          "Create" <- activity.data["type"],
-         "Note" <- activity.data["object"]["type"],
-         ap_id when is_binary(ap_id) <- activity.data["object"]["context"] do
+         "Note" <- object.data["type"],
+         ap_id when is_binary(ap_id) and byte_size(ap_id) > 0 <- object.data["context"] do
       {:ok, conversation} = create_for_ap_id(ap_id)
 
       users = User.get_users_from_set(activity.recipients, false)
index 5791fa0dbec86c3060ce4b8642c540b2c9821a05..568953b07268611ec0688f458a28e3b8b00804ca 100644 (file)
@@ -67,24 +67,22 @@ defmodule Pleroma.Conversation.ParticipationTest do
         "in_reply_to_status_id" => activity_one.id
       })
 
-    assert [participation_one, participation_two] =
-             Participation.for_user(user)
-             |> Repo.preload(:conversation)
+    assert [participation_one, participation_two] = Participation.for_user(user)
 
-    assert participation_one.conversation.ap_id == activity_three.data["object"]["context"]
-    assert participation_two.conversation.ap_id == activity_two.data["object"]["context"]
+    object2 = Pleroma.Object.normalize(activity_two)
+    object3 = Pleroma.Object.normalize(activity_three)
+
+    assert participation_one.conversation.ap_id == object3.data["context"]
+    assert participation_two.conversation.ap_id == object2.data["context"]
 
     # Pagination
-    assert [participation_one] =
-             Participation.for_user(user, %{limit: 1})
-             |> Repo.preload(:conversation)
+    assert [participation_one] = Participation.for_user(user, %{"limit" => 1})
 
-    assert participation_one.conversation.ap_id == activity_three.data["object"]["context"]
+    assert participation_one.conversation.ap_id == object3.data["context"]
 
     # With last_activity_id
     assert [participation_one] =
-             Participation.for_user_with_last_activity_id(user, %{limit: 1})
-             |> Repo.preload(:conversation)
+             Participation.for_user_with_last_activity_id(user, %{"limit" => 1})
 
     assert participation_one.last_activity_id == activity_three.id
   end
index 239dda04f0716adbf9512722058c886d1469e94e..763183d6b484806adb0f577e08183e6982482f6b 100644 (file)
@@ -22,7 +22,8 @@ defmodule Pleroma.ConversationTest do
     user = insert(:user)
     {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey"})
 
-    context = activity.data["object"]["context"]
+    object = Pleroma.Object.normalize(activity)
+    context = object.data["context"]
 
     conversation = Conversation.get_for_ap_id(context)
 
@@ -37,7 +38,8 @@ defmodule Pleroma.ConversationTest do
     {:ok, activity} =
       CommonAPI.post(har, %{"status" => "Hey @#{jafnhar.nickname}", "visibility" => "direct"})
 
-    context = activity.data["object"]["context"]
+    object = Pleroma.Object.normalize(activity)
+    context = object.data["context"]
 
     conversation =
       Conversation.get_for_ap_id(context)
@@ -58,7 +60,8 @@ defmodule Pleroma.ConversationTest do
         "in_reply_to_status_id" => activity.id
       })
 
-    context = activity.data["object"]["context"]
+    object = Pleroma.Object.normalize(activity)
+    context = object.data["context"]
 
     conversation_two =
       Conversation.get_for_ap_id(context)
@@ -81,7 +84,8 @@ defmodule Pleroma.ConversationTest do
         "in_reply_to_status_id" => activity.id
       })
 
-    context = activity.data["object"]["context"]
+    object = Pleroma.Object.normalize(activity)
+    context = object.data["context"]
 
     conversation_three =
       Conversation.get_for_ap_id(context)
index 15276ba7b193f0c02010b52f76c3842d06ba16e0..047270a2a5adca2d30ad6aa88b05c2ef8cb44260 100644 (file)
@@ -208,11 +208,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
       }
 
       {:ok, %Activity{} = activity} = ActivityPub.insert(data)
+      object = Pleroma.Object.normalize(activity)
 
       assert is_binary(activity.data["context"])
-      assert is_binary(activity.data["object"]["context"])
+      assert is_binary(object.data["context"])
       assert activity.data["context_id"]
-      assert activity.data["object"]["context_id"]
+      assert object.data["context_id"]
     end
 
     test "adds an id to a given object if it lacks one and is a note and inserts it to the object database" do