1 defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
3 alias Pleroma.{User, Activity, Object}
4 alias Pleroma.Web.TwitterAPI.Representers.{ActivityRepresenter, ObjectRepresenter}
5 alias Pleroma.Web.ActivityPub.ActivityPub
6 alias Pleroma.Builders.UserBuilder
7 alias Pleroma.Web.TwitterAPI.UserView
10 test "an announce activity" do
12 note_activity = insert(:note_activity)
13 activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"])
14 object = Object.get_by_ap_id(note_activity.data["object"]["id"])
16 {:ok, announce_activity, _object} = ActivityPub.announce(user, object)
17 note_activity = Activity.get_by_ap_id(note_activity.data["id"])
20 ActivityRepresenter.to_map(announce_activity, %{
21 users: [user, activity_actor],
22 announced_activity: note_activity,
26 assert status["id"] == announce_activity.id
27 assert status["user"] == UserView.render("show.json", %{user: user, for: user})
30 ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
32 assert retweeted_status["repeated"] == true
33 assert retweeted_status["id"] == note_activity.id
34 assert status["statusnet_conversation_id"] == retweeted_status["statusnet_conversation_id"]
36 assert status["retweeted_status"] == retweeted_status
37 assert status["activity_type"] == "repeat"
40 test "a like activity" do
42 note_activity = insert(:note_activity)
43 object = Object.get_by_ap_id(note_activity.data["object"]["id"])
45 {:ok, like_activity, _object} = ActivityPub.like(user, object)
48 ActivityRepresenter.to_map(like_activity, %{user: user, liked_activity: note_activity})
50 assert status["id"] == like_activity.id
51 assert status["in_reply_to_status_id"] == note_activity.id
53 note_activity = Activity.get_by_ap_id(note_activity.data["id"])
54 activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"])
55 liked_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
56 assert liked_status["favorited"] == true
57 assert status["activity_type"] == "like"
61 {:ok, user} = UserBuilder.insert()
62 # {:ok, mentioned_user } = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
63 mentioned_user = insert(:user, %{nickname: "shp"})
65 # {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
66 follower = insert(:user, %{following: [User.ap_followers(user)]})
74 "mediaType" => "image/jpg",
75 "href" => "http://example.org/image.jpg"
83 "<script>alert('YAY')</script>Some :2hu: content mentioning <a href='#{mentioned_user.ap_id}'>@shp</shp>"
85 content = HtmlSanitizeEx.strip_tags(content_html)
86 date = DateTime.from_naive!(~N[2016-05-24 13:26:08.003], "Etc/UTC") |> DateTime.to_iso8601()
88 {:ok, convo_object} = Object.context_mapping("2hu") |> Repo.insert()
91 User.ap_followers(user),
92 "https://www.w3.org/ns/activitystreams#Public",
102 "actor" => User.ap_id(user),
106 "content" => content_html,
108 "inReplyToStatusId" => 213_123,
112 "external_url" => "some url",
114 "announcement_count" => 3,
116 "tag" => ["content", "mentioning", "nsfw"],
118 "2hu" => "corndog.png"
129 "<span>2hu</span><br />alert('YAY')Some <img height='32px' width='32px' alt='2hu' title='2hu' src='corndog.png' /> content mentioning <a href=\"#{
135 "user" => UserView.render("show.json", %{user: user, for: follower}),
137 "statusnet_html" => expected_html,
138 "text" => "2hu" <> content,
139 "is_post_verb" => true,
140 "created_at" => "Tue May 24 13:26:08 +0000 2016",
141 "in_reply_to_status_id" => 213_123,
142 "statusnet_conversation_id" => convo_object.id,
144 ObjectRepresenter.to_map(object)
147 UserView.render("show.json", %{user: mentioned_user, for: follower})
151 "favorited" => false,
153 "external_url" => "some url",
154 "tags" => ["nsfw", "content", "mentioning"],
155 "activity_type" => "post",
156 "possibly_sensitive" => true,
157 "uri" => activity.data["object"]["id"],
158 "visibility" => "direct"
161 assert ActivityRepresenter.to_map(activity, %{
164 mentioned: [mentioned_user]
165 }) == expected_status
168 test "an undo for a follow" do
169 follower = insert(:user)
170 followed = insert(:user)
172 {:ok, _follow} = ActivityPub.follow(follower, followed)
173 {:ok, unfollow} = ActivityPub.unfollow(follower, followed)
175 map = ActivityRepresenter.to_map(unfollow, %{user: follower})
176 assert map["is_post_verb"] == false
177 assert map["activity_type"] == "undo"
180 test "a delete activity" do
181 object = insert(:note)
182 user = User.get_by_ap_id(object.data["actor"])
184 {:ok, delete} = ActivityPub.delete(object)
186 map = ActivityRepresenter.to_map(delete, %{user: user})
188 assert map["is_post_verb"] == false
189 assert map["activity_type"] == "delete"
190 assert map["uri"] == object.data["id"]