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 "<p>2hu</p>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 "in_reply_to_screen_name" => nil,
143 "in_reply_to_user_id" => nil,
144 "in_reply_to_profileurl" => nil,
145 "in_reply_to_ostatus_uri" => nil,
146 "statusnet_conversation_id" => convo_object.id,
148 ObjectRepresenter.to_map(object)
151 UserView.render("show.json", %{user: mentioned_user, for: follower})
155 "favorited" => false,
157 "external_url" => "some url",
158 "tags" => ["nsfw", "content", "mentioning"],
159 "activity_type" => "post",
160 "possibly_sensitive" => true,
161 "uri" => activity.data["object"]["id"],
162 "visibility" => "direct",
166 assert ActivityRepresenter.to_map(activity, %{
169 mentioned: [mentioned_user]
170 }) == expected_status
173 test "an undo for a follow" do
174 follower = insert(:user)
175 followed = insert(:user)
177 {:ok, _follow} = ActivityPub.follow(follower, followed)
178 {:ok, unfollow} = ActivityPub.unfollow(follower, followed)
180 map = ActivityRepresenter.to_map(unfollow, %{user: follower})
181 assert map["is_post_verb"] == false
182 assert map["activity_type"] == "undo"
185 test "a delete activity" do
186 object = insert(:note)
187 user = User.get_by_ap_id(object.data["actor"])
189 {:ok, delete} = ActivityPub.delete(object)
191 map = ActivityRepresenter.to_map(delete, %{user: user})
193 assert map["is_post_verb"] == false
194 assert map["activity_type"] == "delete"
195 assert map["uri"] == object.data["id"]