1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
7 alias Pleroma.{User, Activity, Object}
8 alias Pleroma.Web.TwitterAPI.Representers.{ActivityRepresenter, ObjectRepresenter}
9 alias Pleroma.Web.ActivityPub.ActivityPub
10 alias Pleroma.Web.TwitterAPI.UserView
11 import Pleroma.Factory
13 test "an announce activity" do
15 note_activity = insert(:note_activity)
16 activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"])
17 object = Object.get_by_ap_id(note_activity.data["object"]["id"])
19 {:ok, announce_activity, _object} = ActivityPub.announce(user, object)
20 note_activity = Activity.get_by_ap_id(note_activity.data["id"])
23 ActivityRepresenter.to_map(announce_activity, %{
24 users: [user, activity_actor],
25 announced_activity: note_activity,
29 assert status["id"] == announce_activity.id
30 assert status["user"] == UserView.render("show.json", %{user: user, for: user})
33 ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
35 assert retweeted_status["repeated"] == true
36 assert retweeted_status["id"] == note_activity.id
37 assert status["statusnet_conversation_id"] == retweeted_status["statusnet_conversation_id"]
39 assert status["retweeted_status"] == retweeted_status
40 assert status["activity_type"] == "repeat"
43 test "a like activity" do
45 note_activity = insert(:note_activity)
46 object = Object.get_by_ap_id(note_activity.data["object"]["id"])
48 {:ok, like_activity, _object} = ActivityPub.like(user, object)
51 ActivityRepresenter.to_map(like_activity, %{user: user, liked_activity: note_activity})
53 assert status["id"] == like_activity.id
54 assert status["in_reply_to_status_id"] == note_activity.id
56 note_activity = Activity.get_by_ap_id(note_activity.data["id"])
57 activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"])
58 liked_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
59 assert liked_status["favorited"] == true
60 assert status["activity_type"] == "like"
65 # {:ok, mentioned_user } = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
66 mentioned_user = insert(:user, %{nickname: "shp"})
68 # {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
69 follower = insert(:user, %{following: [User.ap_followers(user)]})
77 "mediaType" => "image/jpg",
78 "href" => "http://example.org/image.jpg"
86 "<script>alert('YAY')</script>Some :2hu: content mentioning <a href='#{mentioned_user.ap_id}'>@shp</shp>"
88 content = HtmlSanitizeEx.strip_tags(content_html)
89 date = DateTime.from_naive!(~N[2016-05-24 13:26:08.003], "Etc/UTC") |> DateTime.to_iso8601()
91 {:ok, convo_object} = Object.context_mapping("2hu") |> Repo.insert()
94 User.ap_followers(user),
95 "https://www.w3.org/ns/activitystreams#Public",
105 "actor" => User.ap_id(user),
109 "content" => content_html,
110 "summary" => "2hu :2hu:",
111 "inReplyToStatusId" => 213_123,
115 "external_url" => "some url",
117 "announcement_count" => 3,
119 "tag" => ["content", "mentioning", "nsfw"],
121 "2hu" => "corndog.png"
132 "<p>2hu <img height=\"32px\" width=\"32px\" alt=\"2hu\" title=\"2hu\" src=\"corndog.png\" /></p>alert('YAY')Some <img height=\"32px\" width=\"32px\" alt=\"2hu\" title=\"2hu\" src=\"corndog.png\" /> content mentioning <a href=\"#{
138 "user" => UserView.render("show.json", %{user: user, for: follower}),
140 "statusnet_html" => expected_html,
141 "text" => "2hu :2hu:" <> content,
142 "is_post_verb" => true,
143 "created_at" => "Tue May 24 13:26:08 +0000 2016",
144 "in_reply_to_status_id" => 213_123,
145 "in_reply_to_screen_name" => nil,
146 "in_reply_to_user_id" => nil,
147 "in_reply_to_profileurl" => nil,
148 "in_reply_to_ostatus_uri" => nil,
149 "statusnet_conversation_id" => convo_object.id,
151 ObjectRepresenter.to_map(object)
154 UserView.render("show.json", %{user: mentioned_user, for: follower})
158 "favorited" => false,
161 "external_url" => "some url",
162 "tags" => ["nsfw", "content", "mentioning"],
163 "activity_type" => "post",
164 "possibly_sensitive" => true,
165 "uri" => activity.data["object"]["id"],
166 "visibility" => "direct",
167 "summary" => "2hu :2hu:",
169 "2hu <img height=\"32px\" width=\"32px\" alt=\"2hu\" title=\"2hu\" src=\"corndog.png\" />"
172 assert ActivityRepresenter.to_map(activity, %{
175 mentioned: [mentioned_user]
176 }) == expected_status
179 test "an undo for a follow" do
180 follower = insert(:user)
181 followed = insert(:user)
183 {:ok, _follow} = ActivityPub.follow(follower, followed)
184 {:ok, unfollow} = ActivityPub.unfollow(follower, followed)
186 map = ActivityRepresenter.to_map(unfollow, %{user: follower})
187 assert map["is_post_verb"] == false
188 assert map["activity_type"] == "undo"
191 test "a delete activity" do
192 object = insert(:note)
193 user = User.get_by_ap_id(object.data["actor"])
195 {:ok, delete} = ActivityPub.delete(object)
197 map = ActivityRepresenter.to_map(delete, %{user: user})
199 assert map["is_post_verb"] == false
200 assert map["activity_type"] == "delete"
201 assert map["uri"] == object.data["id"]