Introduce new ingestion pipeline structure, implement internal Likes with it.
This commit is contained in:
parent
e3b4a3e96b
commit
6e4f52f8a2
22 changed files with 284 additions and 47 deletions
21
test/web/activity_pub/activity_validator_test.exs
Normal file
21
test/web/activity_pub/activity_validator_test.exs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "likes" do
|
||||
test "it is well formed" do
|
||||
_required_fields = [
|
||||
"id",
|
||||
"actor",
|
||||
"object"
|
||||
]
|
||||
|
||||
_user = insert(:user)
|
||||
end
|
||||
end
|
||||
end
|
||||
32
test/web/activity_pub/side_effects_test.exs
Normal file
32
test/web/activity_pub/side_effects_test.exs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.ActivityPub.Builder
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.SideEffects
|
||||
|
||||
import Pleroma.Factory
|
||||
describe "like objects" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
{:ok, post} = CommonAPI.post(user, %{"status" => "hey"})
|
||||
|
||||
{:ok, like_data, _meta} = Builder.like(user, post.object)
|
||||
{:ok, like, _meta} = ActivityPub.persist(like_data, [])
|
||||
|
||||
%{like: like, user: user}
|
||||
end
|
||||
|
||||
test "add the like to the original object", %{like: like, user: user} do
|
||||
{:ok, like, _} = SideEffects.handle(like)
|
||||
object = Object.get_by_ap_id(like.data["object"])
|
||||
assert object.data["like_count"] == 1
|
||||
assert user.ap_id in object.data["likes"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1187,7 +1187,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity, _} = CommonAPI.favorite(referent_activity.id, user)
|
||||
{:ok, activity} = CommonAPI.favorite(user, referent_activity.id)
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
assert modified["object"] == "http://gs.example.org:4040/index.php/notice/29"
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do
|
|||
object = Object.normalize(note)
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, like_activity, _} = CommonAPI.favorite(note.id, user)
|
||||
{:ok, like_activity} = CommonAPI.favorite(user, note.id)
|
||||
|
||||
result = ObjectView.render("object.json", %{object: like_activity})
|
||||
|
||||
|
|
|
|||
|
|
@ -251,9 +251,12 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
|
||||
{:ok, post_activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
|
||||
|
||||
{:ok, %Activity{}, _} = CommonAPI.favorite(activity.id, user)
|
||||
{:ok, %Activity{data: data}} = CommonAPI.favorite(user, post_activity.id)
|
||||
assert data["type"] == "Like"
|
||||
assert data["actor"] == user.ap_id
|
||||
assert data["object"] == post_activity.data["object"]
|
||||
end
|
||||
|
||||
test "retweeting a status twice returns an error" do
|
||||
|
|
@ -270,8 +273,8 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
|
||||
{:ok, %Activity{}, _object} = CommonAPI.favorite(activity.id, user)
|
||||
{:error, _} = CommonAPI.favorite(activity.id, user)
|
||||
{:ok, %Activity{}} = CommonAPI.favorite(user, activity.id)
|
||||
{:error, _} = CommonAPI.favorite(user, activity.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
{:ok, mention_activity} = CommonAPI.post(other_user, %{"status" => "hey @#{user.nickname}"})
|
||||
{:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"})
|
||||
{:ok, favorite_activity, _} = CommonAPI.favorite(create_activity.id, other_user)
|
||||
{:ok, favorite_activity} = CommonAPI.favorite(other_user, create_activity.id)
|
||||
{:ok, reblog_activity, _} = CommonAPI.repeat(create_activity.id, other_user)
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user)
|
||||
|
||||
|
|
|
|||
|
|
@ -589,7 +589,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
user1 = insert(:user)
|
||||
user2 = insert(:user)
|
||||
user3 = insert(:user)
|
||||
CommonAPI.favorite(activity.id, user2)
|
||||
{:ok, _} = CommonAPI.favorite(user2, activity.id)
|
||||
{:ok, _bookmark} = Pleroma.Bookmark.create(user2.id, activity.id)
|
||||
{:ok, reblog_activity1, _object} = CommonAPI.repeat(activity.id, user1)
|
||||
{:ok, _, _object} = CommonAPI.repeat(activity.id, user2)
|
||||
|
|
@ -695,7 +695,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
activity = insert(:note_activity)
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, _, _} = CommonAPI.favorite(activity.id, user)
|
||||
{:ok, _} = CommonAPI.favorite(user, activity.id)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -1047,7 +1047,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
test "returns users who have favorited the status", %{conn: conn, activity: activity} do
|
||||
other_user = insert(:user)
|
||||
{:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
|
||||
{:ok, _} = CommonAPI.favorite(other_user, activity.id)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -1078,7 +1078,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
other_user = insert(:user)
|
||||
{:ok, user} = User.block(user, other_user)
|
||||
|
||||
{:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
|
||||
{:ok, _} = CommonAPI.favorite(other_user, activity.id)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -1091,7 +1091,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
test "does not fail on an unauthenticated request", %{conn: conn, activity: activity} do
|
||||
other_user = insert(:user)
|
||||
{:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
|
||||
{:ok, _} = CommonAPI.favorite(other_user, activity.id)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -1112,7 +1112,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
{:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
|
||||
{:ok, _} = CommonAPI.favorite(other_user, activity.id)
|
||||
|
||||
conn
|
||||
|> assign(:user, nil)
|
||||
|
|
@ -1269,7 +1269,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
{:ok, _} = CommonAPI.post(other_user, %{"status" => "bla"})
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "traps are happy"})
|
||||
|
||||
{:ok, _, _} = CommonAPI.favorite(activity.id, user)
|
||||
{:ok, _} = CommonAPI.favorite(user, activity.id)
|
||||
|
||||
first_conn =
|
||||
conn
|
||||
|
|
@ -1289,7 +1289,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
"Trees Are Never Sad Look At Them Every Once In Awhile They're Quite Beautiful."
|
||||
})
|
||||
|
||||
{:ok, _, _} = CommonAPI.favorite(second_activity.id, user)
|
||||
{:ok, _} = CommonAPI.favorite(user, second_activity.id)
|
||||
|
||||
last_like = status["id"]
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
user = insert(:user)
|
||||
another_user = insert(:user)
|
||||
{:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"})
|
||||
{:ok, favorite_activity, _object} = CommonAPI.favorite(create_activity.id, another_user)
|
||||
{:ok, favorite_activity} = CommonAPI.favorite(another_user, create_activity.id)
|
||||
{:ok, [notification]} = Notification.create_notifications(favorite_activity)
|
||||
create_activity = Activity.get_by_id(create_activity.id)
|
||||
|
||||
|
|
|
|||
|
|
@ -271,7 +271,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, like_activity, _} = CommonAPI.favorite(note_activity.id, user)
|
||||
{:ok, like_activity} = CommonAPI.favorite(user, note_activity.id)
|
||||
url = "/notice/#{like_activity.id}"
|
||||
|
||||
assert like_activity.data["type"] == "Like"
|
||||
|
|
@ -298,7 +298,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, like_activity, _} = CommonAPI.favorite(note_activity.id, user)
|
||||
{:ok, like_activity} = CommonAPI.favorite(user, note_activity.id)
|
||||
|
||||
assert like_activity.data["type"] == "Like"
|
||||
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
user: user
|
||||
} do
|
||||
[activity | _] = insert_pair(:note_activity)
|
||||
CommonAPI.favorite(activity.id, user)
|
||||
CommonAPI.favorite(user, activity.id)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -184,7 +184,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
user: user
|
||||
} do
|
||||
activity = insert(:note_activity)
|
||||
CommonAPI.favorite(activity.id, user)
|
||||
CommonAPI.favorite(user, activity.id)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -205,7 +205,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
CommonAPI.favorite(direct.id, user)
|
||||
CommonAPI.favorite(user, direct.id)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -236,7 +236,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
CommonAPI.favorite(direct.id, user)
|
||||
CommonAPI.favorite(user, direct.id)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -255,7 +255,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
activities = insert_list(10, :note_activity)
|
||||
|
||||
Enum.each(activities, fn activity ->
|
||||
CommonAPI.favorite(activity.id, user)
|
||||
CommonAPI.favorite(user, activity.id)
|
||||
end)
|
||||
|
||||
third_activity = Enum.at(activities, 2)
|
||||
|
|
@ -283,7 +283,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
7
|
||||
|> insert_list(:note_activity)
|
||||
|> Enum.each(fn activity ->
|
||||
CommonAPI.favorite(activity.id, user)
|
||||
CommonAPI.favorite(user, activity.id)
|
||||
end)
|
||||
|
||||
response =
|
||||
|
|
@ -321,7 +321,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
} do
|
||||
user = insert(:user, %{info: %{hide_favorites: true}})
|
||||
activity = insert(:note_activity)
|
||||
CommonAPI.favorite(activity.id, user)
|
||||
CommonAPI.favorite(user, activity.id)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -334,7 +334,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
test "hides favorites for new users by default", %{conn: conn, current_user: current_user} do
|
||||
user = insert(:user)
|
||||
activity = insert(:note_activity)
|
||||
CommonAPI.favorite(activity.id, user)
|
||||
CommonAPI.favorite(user, activity.id)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ defmodule Pleroma.Web.Push.ImplTest do
|
|||
"<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
|
||||
})
|
||||
|
||||
{:ok, activity, _} = CommonAPI.favorite(activity.id, user)
|
||||
{:ok, activity} = CommonAPI.favorite(user, activity.id)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert Impl.format_body(%{activity: activity}, user, object) == "@Bob has favorited your post"
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => ":("})
|
||||
{:ok, notif, _} = CommonAPI.favorite(activity.id, blocked)
|
||||
{:ok, notif} = CommonAPI.favorite(blocked, activity.id)
|
||||
|
||||
Streamer.stream("user:notification", notif)
|
||||
Task.await(task)
|
||||
|
|
@ -87,7 +87,7 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
|
||||
{:ok, activity} = CommonAPI.add_mute(user, activity)
|
||||
{:ok, notif, _} = CommonAPI.favorite(activity.id, user2)
|
||||
{:ok, notif} = CommonAPI.favorite(user2, activity.id)
|
||||
Streamer.stream("user:notification", notif)
|
||||
Task.await(task)
|
||||
end
|
||||
|
|
@ -105,7 +105,7 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
|
||||
{:ok, user} = User.block_domain(user, "hecking-lewd-place.com")
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
|
||||
{:ok, notif, _} = CommonAPI.favorite(activity.id, user2)
|
||||
{:ok, notif} = CommonAPI.favorite(user2, activity.id)
|
||||
|
||||
Streamer.stream("user:notification", notif)
|
||||
Task.await(task)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue