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
32 test "a like activity" do
34 note_activity = insert(:note_activity)
35 object = Object.get_by_ap_id(note_activity.data["object"]["id"])
37 {:ok, like_activity, _object} = ActivityPub.like(user, object)
38 status = ActivityRepresenter.to_map(like_activity, %{user: user, liked_activity: note_activity})
40 assert status["id"] == like_activity.id
41 assert status["in_reply_to_status_id"] == note_activity.id
43 note_activity = Activity.get_by_ap_id(note_activity.data["id"])
44 activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"])
45 liked_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
46 assert liked_status["favorited"] == true
50 {:ok, user} = UserBuilder.insert
51 # {:ok, mentioned_user } = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
52 mentioned_user = insert(:user, %{nickname: "shp"})
54 # {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
55 follower = insert(:user, %{following: [User.ap_followers(user)]})
63 "mediaType" => "image/jpg",
64 "href" => "http://example.org/image.jpg"
71 content_html = "<script>alert('YAY')</script>Some content mentioning <a href='#{mentioned_user.ap_id}'>@shp</shp>"
72 content = HtmlSanitizeEx.strip_tags(content_html)
73 date = DateTime.from_naive!(~N[2016-05-24 13:26:08.003], "Etc/UTC") |> DateTime.to_iso8601
75 {:ok, convo_object} = Object.context_mapping("2hu") |> Repo.insert
83 User.ap_followers(user),
84 "https://www.w3.org/ns/activitystreams#Public",
87 "actor" => User.ap_id(user),
91 "content" => content_html,
92 "inReplyToStatusId" => 213123,
96 "external_url" => "some url",
98 "announcement_count" => 3,
100 "tag" => ["content", "mentioning", "nsfw"]
111 "user" => UserView.render("show.json", %{user: user, for: follower}),
113 "statusnet_html" => HtmlSanitizeEx.basic_html(content_html),
115 "is_post_verb" => true,
116 "created_at" => "Tue May 24 13:26:08 +0000 2016",
117 "in_reply_to_status_id" => 213123,
118 "statusnet_conversation_id" => convo_object.id,
120 ObjectRepresenter.to_map(object)
123 UserView.render("show.json", %{user: mentioned_user, for: follower})
127 "favorited" => false,
129 "external_url" => "some url",
130 "tags" => ["content", "mentioning", "nsfw"]
133 assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status
136 test "an undo for a follow" do
137 follower = insert(:user)
138 followed = insert(:user)
140 {:ok, follow} = ActivityPub.follow(follower, followed)
141 {:ok, unfollow} = ActivityPub.unfollow(follower, followed)
143 map = ActivityRepresenter.to_map(unfollow, %{user: follower})
144 assert map["is_post_verb"] == false