Fix tests

This commit is contained in:
Roman Chvanikov 2019-04-29 03:44:04 +07:00 committed by lain
parent 45f790becc
commit 8af55728e4
4 changed files with 23 additions and 19 deletions

View File

@ -47,9 +47,10 @@ def get_for_ap_id(ap_id) 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)

View File

@ -67,24 +67,22 @@ test "gets all the participations for a user, ordered by updated at descending"
"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

View File

@ -22,7 +22,8 @@ test "public posts don't create conversations" 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 @@ test "it creates or updates a conversation and participations for a given DM" 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 @@ test "it creates or updates a conversation and participations for a given DM" 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 @@ test "it creates or updates a conversation and participations for a given DM" 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)

View File

@ -208,11 +208,12 @@ test "adds a context when none is there" 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