1 defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
3 alias Pleroma.{User, Activity, Object}
4 alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ActivityRepresenter, ObjectRepresenter}
5 alias Pleroma.Web.ActivityPub.ActivityPub
6 alias Pleroma.Builders.UserBuilder
9 test "an announce activity" do
11 note_activity = insert(:note_activity)
12 activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"])
13 object = Object.get_by_ap_id(note_activity.data["object"]["id"])
15 {:ok, announce_activity, _object} = ActivityPub.announce(user, object)
16 note_activity = Activity.get_by_ap_id(note_activity.data["id"])
18 status = ActivityRepresenter.to_map(announce_activity, %{users: [user, activity_actor], announced_activity: note_activity, for: user})
20 assert status["id"] == announce_activity.id
21 assert status["user"] == UserRepresenter.to_map(user, %{for: user})
23 retweeted_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
24 assert retweeted_status["repeated"] == true
25 assert retweeted_status["id"] == note_activity.id
26 assert status["statusnet_conversation_id"] == retweeted_status["statusnet_conversation_id"]
28 assert status["retweeted_status"] == retweeted_status
31 test "a like activity" do
33 note_activity = insert(:note_activity)
34 object = Object.get_by_ap_id(note_activity.data["object"]["id"])
36 {:ok, like_activity, _object} = ActivityPub.like(user, object)
37 status = ActivityRepresenter.to_map(like_activity, %{user: user, liked_activity: note_activity})
39 assert status["id"] == like_activity.id
40 assert status["in_reply_to_status_id"] == note_activity.id
42 note_activity = Activity.get_by_ap_id(note_activity.data["id"])
43 activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"])
44 liked_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
45 assert liked_status["favorited"] == true
49 {:ok, user} = UserBuilder.insert
50 # {:ok, mentioned_user } = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
51 mentioned_user = insert(:user, %{nickname: "shp"})
53 # {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
54 follower = insert(:user, %{following: [User.ap_followers(user)]})
62 "mediaType" => "image/jpg",
63 "href" => "http://example.org/image.jpg"
70 content_html = "Some #content #mentioning <a href='#{mentioned_user.ap_id}'>@shp</shp>"
71 content = HtmlSanitizeEx.strip_tags(content_html)
72 date = DateTime.from_naive!(~N[2016-05-24 13:26:08.003], "Etc/UTC") |> DateTime.to_iso8601
74 {:ok, convo_object} = Object.context_mapping("2hu") |> Repo.insert
82 User.ap_followers(user),
83 "https://www.w3.org/ns/activitystreams#Public",
86 "actor" => User.ap_id(user),
90 "content" => content_html,
91 "inReplyToStatusId" => 213123,
96 "announcement_count" => 3,
98 "tag" => ["content", "mentioning", "nsfw"]
108 "user" => UserRepresenter.to_map(user, %{for: follower}),
111 "statusnet_html" => content_html <> "<br>\n#nsfw",
112 "text" => content <> "\n#nsfw",
113 "is_post_verb" => true,
114 "created_at" => "Tue May 24 13:26:08 +0000 2016",
115 "in_reply_to_status_id" => 213123,
116 "statusnet_conversation_id" => convo_object.id,
118 ObjectRepresenter.to_map(object)
121 UserRepresenter.to_map(mentioned_user, %{for: follower})
125 "favorited" => false,
127 "external_url" => activity.data["id"]
130 assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status