From 8af55728e47f9f62d237704cd5a33fba5f946fa2 Mon Sep 17 00:00:00 2001 From: Roman Chvanikov Date: Mon, 29 Apr 2019 03:44:04 +0700 Subject: [PATCH] Fix tests --- lib/pleroma/conversation.ex | 5 +++-- test/conversation/participation_test.exs | 20 +++++++++----------- test/conversation_test.exs | 12 ++++++++---- test/web/activity_pub/activity_pub_test.exs | 5 +++-- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/lib/pleroma/conversation.ex b/lib/pleroma/conversation.ex index d9c84cb1b..e6a4ccc85 100644 --- a/lib/pleroma/conversation.ex +++ b/lib/pleroma/conversation.ex @@ -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) diff --git a/test/conversation/participation_test.exs b/test/conversation/participation_test.exs index 5791fa0db..568953b07 100644 --- a/test/conversation/participation_test.exs +++ b/test/conversation/participation_test.exs @@ -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 diff --git a/test/conversation_test.exs b/test/conversation_test.exs index 239dda04f..763183d6b 100644 --- a/test/conversation_test.exs +++ b/test/conversation_test.exs @@ -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) diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 15276ba7b..047270a2a 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -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 -- 2.45.2