1 defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
4 alias Pleroma.Web.CommonAPI
5 alias Pleroma.Web.CommonAPI.Utils
6 alias Pleroma.Web.TwitterAPI.ActivityView
7 alias Pleroma.Web.TwitterAPI.UserView
8 alias Pleroma.Web.TwitterAPI.TwitterAPI
10 alias Pleroma.Activity
12 alias Pleroma.Web.ActivityPub.ActivityPub
14 import Pleroma.Factory
17 test "a create activity with a html status" do
19 #Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg
22 {:ok, activity} = CommonAPI.post(insert(:user), %{"status" => text})
24 result = ActivityView.render("activity.json", activity: activity)
26 assert result["statusnet_html"] ==
27 "<a data-tag=\"bike\" href=\"http://localhost:4001/tag/bike\">#Bike</a> log - Commute Tuesday<br /><a href=\"https://pla.bike/posts/20181211/\">https://pla.bike/posts/20181211/</a><br /><a data-tag=\"cycling\" href=\"http://localhost:4001/tag/cycling\">#cycling</a> <a data-tag=\"chscycling\" href=\"http://localhost:4001/tag/chscycling\">#CHScycling</a> <a data-tag=\"commute\" href=\"http://localhost:4001/tag/commute\">#commute</a><br />MVIMG_20181211_054020.jpg"
29 assert result["text"] ==
30 "#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg"
33 test "a create activity with a note" do
35 other_user = insert(:user, %{nickname: "shp"})
37 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
39 result = ActivityView.render("activity.json", activity: activity)
41 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
44 "activity_type" => "post",
47 UserView.render("show.json", %{user: other_user})
49 "created_at" => activity.data["object"]["published"] |> Utils.date_to_asctime(),
50 "external_url" => activity.data["object"]["id"],
54 "in_reply_to_status_id" => nil,
55 "in_reply_to_screen_name" => nil,
56 "in_reply_to_user_id" => nil,
57 "in_reply_to_profileurl" => nil,
58 "in_reply_to_ostatus_uri" => nil,
60 "is_post_verb" => true,
61 "possibly_sensitive" => false,
64 "statusnet_conversation_id" => convo_id,
66 "Hey <span><a data-user=\"#{other_user.id}\" href=\"#{other_user.ap_id}\">@<span>shp</span></a></span>!",
68 "text" => "Hey @shp!",
69 "uri" => activity.data["object"]["id"],
70 "user" => UserView.render("show.json", %{user: user}),
71 "visibility" => "direct",
75 assert result == expected
78 test "a list of activities" do
80 other_user = insert(:user, %{nickname: "shp"})
81 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
83 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
89 [context_to_conversation_id: fn _ -> false end]
94 [get_cached_by_ap_id: fn _ -> nil end]
99 [result] = ActivityView.render("index.json", activities: [activity])
101 assert result["statusnet_conversation_id"] == convo_id
102 assert result["user"]
103 refute called(TwitterAPI.context_to_conversation_id(:_))
104 refute called(User.get_cached_by_ap_id(user.ap_id))
105 refute called(User.get_cached_by_ap_id(other_user.ap_id))
109 test "an activity that is a reply" do
111 other_user = insert(:user, %{nickname: "shp"})
113 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
116 CommonAPI.post(other_user, %{"status" => "Hi!", "in_reply_to_status_id" => activity.id})
118 result = ActivityView.render("activity.json", %{activity: answer})
120 assert result["in_reply_to_status_id"] == activity.id
123 test "a like activity" do
125 other_user = insert(:user, %{nickname: "shp"})
127 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
128 {:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
130 result = ActivityView.render("activity.json", activity: like)
131 activity = Pleroma.Activity.get_by_ap_id(activity.data["id"])
134 "activity_type" => "like",
135 "created_at" => like.data["published"] |> Utils.date_to_asctime(),
136 "external_url" => like.data["id"],
138 "in_reply_to_status_id" => activity.id,
140 "is_post_verb" => false,
141 "favorited_status" => ActivityView.render("activity.json", activity: activity),
142 "statusnet_html" => "shp favorited a status.",
143 "text" => "shp favorited a status.",
144 "uri" => "tag:#{like.data["id"]}:objectType=Favourite",
145 "user" => UserView.render("show.json", user: other_user)
148 assert result == expected
151 test "a like activity for deleted post" do
153 other_user = insert(:user, %{nickname: "shp"})
155 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
156 {:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
157 CommonAPI.delete(activity.id, user)
159 result = ActivityView.render("activity.json", activity: like)
162 "activity_type" => "like",
163 "created_at" => like.data["published"] |> Utils.date_to_asctime(),
164 "external_url" => like.data["id"],
166 "in_reply_to_status_id" => nil,
168 "is_post_verb" => false,
169 "favorited_status" => nil,
170 "statusnet_html" => "shp favorited a status.",
171 "text" => "shp favorited a status.",
172 "uri" => "tag:#{like.data["id"]}:objectType=Favourite",
173 "user" => UserView.render("show.json", user: other_user)
176 assert result == expected
179 test "an announce activity" do
181 other_user = insert(:user, %{nickname: "shp"})
183 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
184 {:ok, announce, _object} = CommonAPI.repeat(activity.id, other_user)
186 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
188 activity = Repo.get(Activity, activity.id)
190 result = ActivityView.render("activity.json", activity: announce)
193 "activity_type" => "repeat",
194 "created_at" => announce.data["published"] |> Utils.date_to_asctime(),
195 "external_url" => announce.data["id"],
198 "is_post_verb" => false,
199 "statusnet_html" => "shp retweeted a status.",
200 "text" => "shp retweeted a status.",
201 "uri" => "tag:#{announce.data["id"]}:objectType=note",
202 "user" => UserView.render("show.json", user: other_user),
203 "retweeted_status" => ActivityView.render("activity.json", activity: activity),
204 "statusnet_conversation_id" => convo_id
207 assert result == expected
210 test "A follow activity" do
212 other_user = insert(:user, %{nickname: "shp"})
214 {:ok, follower} = User.follow(user, other_user)
215 {:ok, follow} = ActivityPub.follow(follower, other_user)
217 result = ActivityView.render("activity.json", activity: follow)
220 "activity_type" => "follow",
222 "created_at" => follow.data["published"] |> Utils.date_to_asctime(),
223 "external_url" => follow.data["id"],
225 "in_reply_to_status_id" => nil,
227 "is_post_verb" => false,
228 "statusnet_html" => "#{user.nickname} started following shp",
229 "text" => "#{user.nickname} started following shp",
230 "user" => UserView.render("show.json", user: user)
233 assert result == expected
236 test "a delete activity" do
239 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
240 {:ok, delete} = CommonAPI.delete(activity.id, user)
242 result = ActivityView.render("activity.json", activity: delete)
245 "activity_type" => "delete",
247 "created_at" => delete.data["published"] |> Utils.date_to_asctime(),
248 "external_url" => delete.data["id"],
250 "in_reply_to_status_id" => nil,
252 "is_post_verb" => false,
253 "statusnet_html" => "deleted notice {{tag",
254 "text" => "deleted notice {{tag",
255 "uri" => delete.data["object"],
256 "user" => UserView.render("show.json", user: user)
259 assert result == expected