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
10 alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
11 alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
12 alias Pleroma.Web.ActivityPub.ActivityPub
13 alias Pleroma.Web.TwitterAPI.UserView
14 import Pleroma.Factory
16 test "a like activity" do
18 note_activity = insert(:note_activity)
19 object = Object.get_by_ap_id(note_activity.data["object"]["id"])
21 {:ok, like_activity, _object} = ActivityPub.like(user, object)
24 ActivityRepresenter.to_map(like_activity, %{user: user, liked_activity: note_activity})
26 assert status["id"] == like_activity.id
27 assert status["in_reply_to_status_id"] == note_activity.id
29 note_activity = Activity.get_by_ap_id(note_activity.data["id"])
30 activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"])
31 liked_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
32 assert liked_status["favorited"] == true
33 assert status["activity_type"] == "like"
38 # {:ok, mentioned_user } = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
39 mentioned_user = insert(:user, %{nickname: "shp"})
41 # {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
42 follower = insert(:user, %{following: [User.ap_followers(user)]})
50 "mediaType" => "image/jpg",
51 "href" => "http://example.org/image.jpg"
59 "<script>alert('YAY')</script>Some :2hu: content mentioning <a href='#{mentioned_user.ap_id}'>@shp</shp>"
61 content = HtmlSanitizeEx.strip_tags(content_html)
62 date = DateTime.from_naive!(~N[2016-05-24 13:26:08.003], "Etc/UTC") |> DateTime.to_iso8601()
64 {:ok, convo_object} = Object.context_mapping("2hu") |> Repo.insert()
67 User.ap_followers(user),
68 "https://www.w3.org/ns/activitystreams#Public",
78 "actor" => User.ap_id(user),
82 "content" => content_html,
83 "summary" => "2hu :2hu:",
84 "inReplyToStatusId" => 213_123,
88 "external_url" => "some url",
90 "announcement_count" => 3,
92 "tag" => ["content", "mentioning", "nsfw"],
94 "2hu" => "corndog.png"
105 "<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=\"#{
111 "user" => UserView.render("show.json", %{user: user, for: follower}),
113 "statusnet_html" => expected_html,
114 "text" => "2hu :2hu:" <> content,
115 "is_post_verb" => true,
116 "created_at" => "Tue May 24 13:26:08 +0000 2016",
117 "in_reply_to_status_id" => 213_123,
118 "in_reply_to_screen_name" => nil,
119 "in_reply_to_user_id" => nil,
120 "in_reply_to_profileurl" => nil,
121 "in_reply_to_ostatus_uri" => nil,
122 "statusnet_conversation_id" => convo_object.id,
124 ObjectRepresenter.to_map(object)
127 UserView.render("show.json", %{user: mentioned_user, for: follower})
131 "favorited" => false,
134 "external_url" => "some url",
135 "tags" => ["nsfw", "content", "mentioning"],
136 "activity_type" => "post",
137 "possibly_sensitive" => true,
138 "uri" => activity.data["object"]["id"],
139 "visibility" => "direct",
142 "summary" => "2hu :2hu:",
144 "2hu <img height=\"32px\" width=\"32px\" alt=\"2hu\" title=\"2hu\" src=\"corndog.png\" />"
147 assert ActivityRepresenter.to_map(activity, %{
150 mentioned: [mentioned_user]
151 }) == expected_status
154 test "a delete activity" do
155 object = insert(:note)
156 user = User.get_by_ap_id(object.data["actor"])
158 {:ok, delete} = ActivityPub.delete(object)
160 map = ActivityRepresenter.to_map(delete, %{user: user})
162 assert map["is_post_verb"] == false
163 assert map["activity_type"] == "delete"
164 assert map["uri"] == object.data["id"]