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"])
19 status = ActivityRepresenter.to_map(announce_activity, %{users: [user, activity_actor], announced_activity: note_activity, for: user})
21 assert status["id"] == announce_activity.id
22 assert status["user"] == UserView.render("show.json", %{user: user, for: user})
24 retweeted_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
25 assert retweeted_status["repeated"] == true
26 assert retweeted_status["id"] == note_activity.id
27 assert status["statusnet_conversation_id"] == retweeted_status["statusnet_conversation_id"]
29 assert status["retweeted_status"] == retweeted_status
30 assert status["activity_type"] == "repeat"
33 test "a like activity" do
35 note_activity = insert(:note_activity)
36 object = Object.get_by_ap_id(note_activity.data["object"]["id"])
38 {:ok, like_activity, _object} = ActivityPub.like(user, object)
39 status = ActivityRepresenter.to_map(like_activity, %{user: user, liked_activity: note_activity})
41 assert status["id"] == like_activity.id
42 assert status["in_reply_to_status_id"] == note_activity.id
44 note_activity = Activity.get_by_ap_id(note_activity.data["id"])
45 activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"])
46 liked_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
47 assert liked_status["favorited"] == true
48 assert status["activity_type"] == "like"
52 {:ok, user} = UserBuilder.insert
53 # {:ok, mentioned_user } = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
54 mentioned_user = insert(:user, %{nickname: "shp"})
56 # {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
57 follower = insert(:user, %{following: [User.ap_followers(user)]})
65 "mediaType" => "image/jpg",
66 "href" => "http://example.org/image.jpg"
73 content_html = "<script>alert('YAY')</script>Some content mentioning <a href='#{mentioned_user.ap_id}'>@shp</shp>"
74 content = HtmlSanitizeEx.strip_tags(content_html)
75 date = DateTime.from_naive!(~N[2016-05-24 13:26:08.003], "Etc/UTC") |> DateTime.to_iso8601
77 {:ok, convo_object} = Object.context_mapping("2hu") |> Repo.insert
85 User.ap_followers(user),
86 "https://www.w3.org/ns/activitystreams#Public",
89 "actor" => User.ap_id(user),
93 "content" => content_html,
94 "inReplyToStatusId" => 213123,
98 "external_url" => "some url",
100 "announcement_count" => 3,
102 "tag" => ["content", "mentioning", "nsfw"]
113 "user" => UserView.render("show.json", %{user: user, for: follower}),
115 "statusnet_html" => HtmlSanitizeEx.basic_html(content_html),
117 "is_post_verb" => true,
118 "created_at" => "Tue May 24 13:26:08 +0000 2016",
119 "in_reply_to_status_id" => 213123,
120 "statusnet_conversation_id" => convo_object.id,
122 ObjectRepresenter.to_map(object)
125 UserView.render("show.json", %{user: mentioned_user, for: follower})
129 "favorited" => false,
131 "external_url" => "some url",
132 "tags" => ["content", "mentioning", "nsfw"],
133 "activity_type" => "post",
134 "possibly_sensitive" => true,
135 "uri" => activity.data["object"]["id"]
138 assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status
141 test "an undo for a follow" do
142 follower = insert(:user)
143 followed = insert(:user)
145 {:ok, follow} = ActivityPub.follow(follower, followed)
146 {:ok, unfollow} = ActivityPub.unfollow(follower, followed)
148 map = ActivityRepresenter.to_map(unfollow, %{user: follower})
149 assert map["is_post_verb"] == false
150 assert map["activity_type"] == "undo"
153 test "a delete activity" do
154 object = insert(:note)
155 user = User.get_by_ap_id(object.data["actor"])
157 {:ok, delete} = ActivityPub.delete(object)
159 map = ActivityRepresenter.to_map(delete, %{user: user})
161 assert map["is_post_verb"] == false
162 assert map["activity_type"] == "delete"
163 assert map["uri"] == object.data["id"]