2018-12-23 13:11:29 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-03-30 04:57:55 -06:00
|
|
|
defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
|
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
alias Pleroma.Web.CommonAPI.Utils
|
|
|
|
alias Pleroma.Web.TwitterAPI.ActivityView
|
|
|
|
alias Pleroma.Web.TwitterAPI.UserView
|
|
|
|
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
2018-03-30 06:46:36 -06:00
|
|
|
alias Pleroma.Repo
|
|
|
|
alias Pleroma.Activity
|
2018-03-30 07:17:13 -06:00
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
2018-04-02 06:46:56 -06:00
|
|
|
|
2018-03-30 04:57:55 -06:00
|
|
|
import Pleroma.Factory
|
2018-12-23 06:55:08 -07:00
|
|
|
import Tesla.Mock
|
|
|
|
|
|
|
|
setup do
|
|
|
|
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
2018-04-02 06:46:56 -06:00
|
|
|
import Mock
|
2018-03-30 04:57:55 -06:00
|
|
|
|
2018-12-17 12:41:36 -07:00
|
|
|
test "a create activity with a html status" do
|
|
|
|
text = """
|
|
|
|
#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg
|
|
|
|
"""
|
|
|
|
|
|
|
|
{:ok, activity} = CommonAPI.post(insert(:user), %{"status" => text})
|
|
|
|
|
|
|
|
result = ActivityView.render("activity.json", activity: activity)
|
|
|
|
|
|
|
|
assert result["statusnet_html"] ==
|
|
|
|
"<a data-tag=\"bike\" href=\"http://localhost:4001/tag/bike\">#Bike</a> log - Commute Tuesday<br /><a href=\"https://pla.bike/posts/20181211/\">https://pla.bike/posts/20181211/</a><br /><a data-tag=\"cycling\" href=\"http://localhost:4001/tag/cycling\">#cycling</a> <a data-tag=\"chscycling\" href=\"http://localhost:4001/tag/chscycling\">#CHScycling</a> <a data-tag=\"commute\" href=\"http://localhost:4001/tag/commute\">#commute</a><br />MVIMG_20181211_054020.jpg"
|
|
|
|
|
|
|
|
assert result["text"] ==
|
|
|
|
"#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg"
|
|
|
|
end
|
|
|
|
|
2018-03-30 04:57:55 -06:00
|
|
|
test "a create activity with a note" do
|
|
|
|
user = insert(:user)
|
|
|
|
other_user = insert(:user, %{nickname: "shp"})
|
|
|
|
|
2018-05-20 10:01:24 -06:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
|
2018-03-30 04:57:55 -06:00
|
|
|
|
|
|
|
result = ActivityView.render("activity.json", activity: activity)
|
|
|
|
|
|
|
|
convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
|
|
|
|
|
|
|
|
expected = %{
|
|
|
|
"activity_type" => "post",
|
|
|
|
"attachments" => [],
|
|
|
|
"attentions" => [
|
|
|
|
UserView.render("show.json", %{user: other_user})
|
|
|
|
],
|
2018-03-30 05:49:09 -06:00
|
|
|
"created_at" => activity.data["object"]["published"] |> Utils.date_to_asctime(),
|
2018-03-30 04:57:55 -06:00
|
|
|
"external_url" => activity.data["object"]["id"],
|
|
|
|
"fave_num" => 0,
|
|
|
|
"favorited" => false,
|
|
|
|
"id" => activity.id,
|
|
|
|
"in_reply_to_status_id" => nil,
|
2018-10-24 21:03:44 -06:00
|
|
|
"in_reply_to_screen_name" => nil,
|
2018-10-24 22:06:42 -06:00
|
|
|
"in_reply_to_user_id" => nil,
|
|
|
|
"in_reply_to_profileurl" => nil,
|
|
|
|
"in_reply_to_ostatus_uri" => nil,
|
2018-03-30 04:57:55 -06:00
|
|
|
"is_local" => true,
|
|
|
|
"is_post_verb" => true,
|
|
|
|
"possibly_sensitive" => false,
|
|
|
|
"repeat_num" => 0,
|
|
|
|
"repeated" => false,
|
|
|
|
"statusnet_conversation_id" => convo_id,
|
|
|
|
"statusnet_html" =>
|
2018-12-05 13:24:04 -07:00
|
|
|
"Hey <span><a data-user=\"#{other_user.id}\" href=\"#{other_user.ap_id}\">@<span>shp</span></a></span>!",
|
2018-03-30 04:57:55 -06:00
|
|
|
"tags" => [],
|
|
|
|
"text" => "Hey @shp!",
|
|
|
|
"uri" => activity.data["object"]["id"],
|
2018-05-20 10:01:24 -06:00
|
|
|
"user" => UserView.render("show.json", %{user: user}),
|
2018-06-24 00:23:19 -06:00
|
|
|
"visibility" => "direct",
|
|
|
|
"summary" => nil
|
2018-03-30 04:57:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
assert result == expected
|
|
|
|
end
|
2018-03-30 05:49:09 -06:00
|
|
|
|
2018-04-02 06:46:56 -06:00
|
|
|
test "a list of activities" do
|
|
|
|
user = insert(:user)
|
|
|
|
other_user = insert(:user, %{nickname: "shp"})
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
|
|
|
|
|
|
|
convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
|
|
|
|
|
|
|
|
mocks = [
|
|
|
|
{
|
|
|
|
TwitterAPI,
|
|
|
|
[],
|
2018-04-02 08:27:36 -06:00
|
|
|
[context_to_conversation_id: fn _ -> false end]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
User,
|
|
|
|
[:passthrough],
|
|
|
|
[get_cached_by_ap_id: fn _ -> nil end]
|
2018-04-02 06:46:56 -06:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
with_mocks mocks do
|
|
|
|
[result] = ActivityView.render("index.json", activities: [activity])
|
|
|
|
|
|
|
|
assert result["statusnet_conversation_id"] == convo_id
|
|
|
|
assert result["user"]
|
2018-04-02 08:27:36 -06:00
|
|
|
refute called(TwitterAPI.context_to_conversation_id(:_))
|
|
|
|
refute called(User.get_cached_by_ap_id(user.ap_id))
|
|
|
|
refute called(User.get_cached_by_ap_id(other_user.ap_id))
|
2018-04-02 06:46:56 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-30 05:49:09 -06:00
|
|
|
test "an activity that is a reply" do
|
|
|
|
user = insert(:user)
|
|
|
|
other_user = insert(:user, %{nickname: "shp"})
|
|
|
|
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
|
|
|
|
|
|
|
{:ok, answer} =
|
|
|
|
CommonAPI.post(other_user, %{"status" => "Hi!", "in_reply_to_status_id" => activity.id})
|
|
|
|
|
|
|
|
result = ActivityView.render("activity.json", %{activity: answer})
|
|
|
|
|
|
|
|
assert result["in_reply_to_status_id"] == activity.id
|
|
|
|
end
|
|
|
|
|
|
|
|
test "a like activity" do
|
|
|
|
user = insert(:user)
|
|
|
|
other_user = insert(:user, %{nickname: "shp"})
|
|
|
|
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
|
|
|
{:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
|
|
|
|
|
|
|
|
result = ActivityView.render("activity.json", activity: like)
|
2018-12-13 23:24:18 -07:00
|
|
|
activity = Pleroma.Activity.get_by_ap_id(activity.data["id"])
|
2018-03-30 05:49:09 -06:00
|
|
|
|
|
|
|
expected = %{
|
|
|
|
"activity_type" => "like",
|
|
|
|
"created_at" => like.data["published"] |> Utils.date_to_asctime(),
|
|
|
|
"external_url" => like.data["id"],
|
|
|
|
"id" => like.id,
|
|
|
|
"in_reply_to_status_id" => activity.id,
|
|
|
|
"is_local" => true,
|
2018-08-27 08:07:26 -06:00
|
|
|
"is_post_verb" => false,
|
2018-12-13 23:24:18 -07:00
|
|
|
"favorited_status" => ActivityView.render("activity.json", activity: activity),
|
2018-08-27 08:07:26 -06:00
|
|
|
"statusnet_html" => "shp favorited a status.",
|
|
|
|
"text" => "shp favorited a status.",
|
|
|
|
"uri" => "tag:#{like.data["id"]}:objectType=Favourite",
|
|
|
|
"user" => UserView.render("show.json", user: other_user)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert result == expected
|
|
|
|
end
|
|
|
|
|
|
|
|
test "a like activity for deleted post" do
|
|
|
|
user = insert(:user)
|
|
|
|
other_user = insert(:user, %{nickname: "shp"})
|
|
|
|
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
|
|
|
{:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
|
|
|
|
CommonAPI.delete(activity.id, user)
|
|
|
|
|
|
|
|
result = ActivityView.render("activity.json", activity: like)
|
|
|
|
|
|
|
|
expected = %{
|
|
|
|
"activity_type" => "like",
|
|
|
|
"created_at" => like.data["published"] |> Utils.date_to_asctime(),
|
|
|
|
"external_url" => like.data["id"],
|
|
|
|
"id" => like.id,
|
|
|
|
"in_reply_to_status_id" => nil,
|
|
|
|
"is_local" => true,
|
2018-03-30 05:49:09 -06:00
|
|
|
"is_post_verb" => false,
|
2018-12-13 23:24:18 -07:00
|
|
|
"favorited_status" => nil,
|
2018-03-30 05:49:09 -06:00
|
|
|
"statusnet_html" => "shp favorited a status.",
|
|
|
|
"text" => "shp favorited a status.",
|
|
|
|
"uri" => "tag:#{like.data["id"]}:objectType=Favourite",
|
|
|
|
"user" => UserView.render("show.json", user: other_user)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert result == expected
|
|
|
|
end
|
2018-03-30 06:46:36 -06:00
|
|
|
|
|
|
|
test "an announce activity" do
|
|
|
|
user = insert(:user)
|
|
|
|
other_user = insert(:user, %{nickname: "shp"})
|
|
|
|
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
|
|
|
{:ok, announce, _object} = CommonAPI.repeat(activity.id, other_user)
|
|
|
|
|
|
|
|
convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
|
|
|
|
|
|
|
|
activity = Repo.get(Activity, activity.id)
|
|
|
|
|
|
|
|
result = ActivityView.render("activity.json", activity: announce)
|
|
|
|
|
|
|
|
expected = %{
|
|
|
|
"activity_type" => "repeat",
|
|
|
|
"created_at" => announce.data["published"] |> Utils.date_to_asctime(),
|
|
|
|
"external_url" => announce.data["id"],
|
|
|
|
"id" => announce.id,
|
|
|
|
"is_local" => true,
|
|
|
|
"is_post_verb" => false,
|
|
|
|
"statusnet_html" => "shp retweeted a status.",
|
|
|
|
"text" => "shp retweeted a status.",
|
|
|
|
"uri" => "tag:#{announce.data["id"]}:objectType=note",
|
|
|
|
"user" => UserView.render("show.json", user: other_user),
|
|
|
|
"retweeted_status" => ActivityView.render("activity.json", activity: activity),
|
|
|
|
"statusnet_conversation_id" => convo_id
|
|
|
|
}
|
|
|
|
|
|
|
|
assert result == expected
|
|
|
|
end
|
2018-03-30 07:17:13 -06:00
|
|
|
|
|
|
|
test "A follow activity" do
|
|
|
|
user = insert(:user)
|
|
|
|
other_user = insert(:user, %{nickname: "shp"})
|
|
|
|
|
|
|
|
{:ok, follower} = User.follow(user, other_user)
|
|
|
|
{:ok, follow} = ActivityPub.follow(follower, other_user)
|
|
|
|
|
|
|
|
result = ActivityView.render("activity.json", activity: follow)
|
|
|
|
|
|
|
|
expected = %{
|
|
|
|
"activity_type" => "follow",
|
|
|
|
"attentions" => [],
|
|
|
|
"created_at" => follow.data["published"] |> Utils.date_to_asctime(),
|
|
|
|
"external_url" => follow.data["id"],
|
|
|
|
"id" => follow.id,
|
|
|
|
"in_reply_to_status_id" => nil,
|
|
|
|
"is_local" => true,
|
|
|
|
"is_post_verb" => false,
|
|
|
|
"statusnet_html" => "#{user.nickname} started following shp",
|
|
|
|
"text" => "#{user.nickname} started following shp",
|
|
|
|
"user" => UserView.render("show.json", user: user)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert result == expected
|
|
|
|
end
|
2018-03-30 07:32:43 -06:00
|
|
|
|
|
|
|
test "a delete activity" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
|
|
|
|
{:ok, delete} = CommonAPI.delete(activity.id, user)
|
|
|
|
|
|
|
|
result = ActivityView.render("activity.json", activity: delete)
|
|
|
|
|
|
|
|
expected = %{
|
|
|
|
"activity_type" => "delete",
|
|
|
|
"attentions" => [],
|
|
|
|
"created_at" => delete.data["published"] |> Utils.date_to_asctime(),
|
|
|
|
"external_url" => delete.data["id"],
|
|
|
|
"id" => delete.id,
|
|
|
|
"in_reply_to_status_id" => nil,
|
|
|
|
"is_local" => true,
|
|
|
|
"is_post_verb" => false,
|
|
|
|
"statusnet_html" => "deleted notice {{tag",
|
|
|
|
"text" => "deleted notice {{tag",
|
|
|
|
"uri" => delete.data["object"],
|
|
|
|
"user" => UserView.render("show.json", user: user)
|
|
|
|
}
|
|
|
|
|
|
|
|
assert result == expected
|
|
|
|
end
|
2018-12-23 06:59:06 -07:00
|
|
|
|
|
|
|
test "a peertube video" do
|
|
|
|
{:ok, object} =
|
|
|
|
ActivityPub.fetch_object_from_id(
|
|
|
|
"https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
|
|
|
|
)
|
|
|
|
|
|
|
|
%Activity{} = activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
|
|
|
|
|
|
|
|
result = ActivityView.render("activity.json", activity: activity)
|
|
|
|
|
|
|
|
assert length(result["attachments"]) == 1
|
|
|
|
assert result["summary"] == "Friday Night"
|
|
|
|
end
|
2018-03-30 04:57:55 -06:00
|
|
|
end
|