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
26 assert status["retweeted_status"] == retweeted_status
29 test "a like activity" do
31 note_activity = insert(:note_activity)
32 object = Object.get_by_ap_id(note_activity.data["object"]["id"])
34 {:ok, like_activity, _object} = ActivityPub.like(user, object)
35 status = ActivityRepresenter.to_map(like_activity, %{user: user, liked_activity: note_activity})
37 assert status["id"] == like_activity.id
38 assert status["in_reply_to_status_id"] == note_activity.id
40 note_activity = Activity.get_by_ap_id(note_activity.data["id"])
41 activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"])
42 liked_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
43 assert liked_status["favorited"] == true
47 {:ok, user} = UserBuilder.insert
48 {:ok, mentioned_user } = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
49 {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
57 "mediaType" => "image/jpg",
58 "href" => "http://example.org/image.jpg"
65 content_html = "Some content mentioning <a href='shp'>@shp</shp>"
66 content = HtmlSanitizeEx.strip_tags(content_html)
67 date = DateTime.from_naive!(~N[2016-05-24 13:26:08.003], "Etc/UTC") |> DateTime.to_iso8601
74 User.ap_followers(user),
75 "https://www.w3.org/ns/activitystreams#Public",
78 "actor" => User.ap_id(user),
82 "content" => content_html,
83 "inReplyToStatusId" => 213123,
84 "statusnetConversationId" => 4711,
89 "announcement_count" => 3
98 "user" => UserRepresenter.to_map(user, %{for: follower}),
101 "statusnet_html" => content_html,
103 "is_post_verb" => true,
104 "created_at" => "Tue May 24 13:26:08 +0000 2016",
105 "in_reply_to_status_id" => 213123,
106 "statusnet_conversation_id" => 4711,
108 ObjectRepresenter.to_map(object)
111 UserRepresenter.to_map(mentioned_user, %{for: follower})
115 "favorited" => false,
119 assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status