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 note" do
19 other_user = insert(:user, %{nickname: "shp"})
21 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
23 result = ActivityView.render("activity.json", activity: activity)
25 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
28 "activity_type" => "post",
31 UserView.render("show.json", %{user: other_user})
33 "created_at" => activity.data["object"]["published"] |> Utils.date_to_asctime(),
34 "external_url" => activity.data["object"]["id"],
38 "in_reply_to_status_id" => nil,
39 "in_reply_to_screen_name" => nil,
40 "in_reply_to_user_id" => nil,
41 "in_reply_to_profileurl" => nil,
42 "in_reply_to_ostatus_uri" => nil,
44 "is_post_verb" => true,
45 "possibly_sensitive" => false,
48 "statusnet_conversation_id" => convo_id,
50 "Hey <span><a data-user=\"#{other_user.id}\" href=\"#{other_user.ap_id}\">@<span>shp</span></a></span>!",
52 "text" => "Hey @shp!",
53 "uri" => activity.data["object"]["id"],
54 "user" => UserView.render("show.json", %{user: user}),
55 "visibility" => "direct",
59 assert result == expected
62 test "a list of activities" do
64 other_user = insert(:user, %{nickname: "shp"})
65 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
67 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
73 [context_to_conversation_id: fn _ -> false end]
78 [get_cached_by_ap_id: fn _ -> nil end]
83 [result] = ActivityView.render("index.json", activities: [activity])
85 assert result["statusnet_conversation_id"] == convo_id
87 refute called(TwitterAPI.context_to_conversation_id(:_))
88 refute called(User.get_cached_by_ap_id(user.ap_id))
89 refute called(User.get_cached_by_ap_id(other_user.ap_id))
93 test "an activity that is a reply" do
95 other_user = insert(:user, %{nickname: "shp"})
97 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
100 CommonAPI.post(other_user, %{"status" => "Hi!", "in_reply_to_status_id" => activity.id})
102 result = ActivityView.render("activity.json", %{activity: answer})
104 assert result["in_reply_to_status_id"] == activity.id
107 test "a like activity" do
109 other_user = insert(:user, %{nickname: "shp"})
111 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
112 {:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
114 result = ActivityView.render("activity.json", activity: like)
115 activity = Pleroma.Activity.get_by_ap_id(activity.data["id"])
118 "activity_type" => "like",
119 "created_at" => like.data["published"] |> Utils.date_to_asctime(),
120 "external_url" => like.data["id"],
122 "in_reply_to_status_id" => activity.id,
124 "is_post_verb" => false,
125 "favorited_status" => ActivityView.render("activity.json", activity: activity),
126 "statusnet_html" => "shp favorited a status.",
127 "text" => "shp favorited a status.",
128 "uri" => "tag:#{like.data["id"]}:objectType=Favourite",
129 "user" => UserView.render("show.json", user: other_user)
132 assert result == expected
135 test "a like activity for deleted post" do
137 other_user = insert(:user, %{nickname: "shp"})
139 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
140 {:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
141 CommonAPI.delete(activity.id, user)
143 result = ActivityView.render("activity.json", activity: like)
146 "activity_type" => "like",
147 "created_at" => like.data["published"] |> Utils.date_to_asctime(),
148 "external_url" => like.data["id"],
150 "in_reply_to_status_id" => nil,
152 "is_post_verb" => false,
153 "favorited_status" => nil,
154 "statusnet_html" => "shp favorited a status.",
155 "text" => "shp favorited a status.",
156 "uri" => "tag:#{like.data["id"]}:objectType=Favourite",
157 "user" => UserView.render("show.json", user: other_user)
160 assert result == expected
163 test "an announce activity" do
165 other_user = insert(:user, %{nickname: "shp"})
167 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
168 {:ok, announce, _object} = CommonAPI.repeat(activity.id, other_user)
170 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
172 activity = Repo.get(Activity, activity.id)
174 result = ActivityView.render("activity.json", activity: announce)
177 "activity_type" => "repeat",
178 "created_at" => announce.data["published"] |> Utils.date_to_asctime(),
179 "external_url" => announce.data["id"],
182 "is_post_verb" => false,
183 "statusnet_html" => "shp retweeted a status.",
184 "text" => "shp retweeted a status.",
185 "uri" => "tag:#{announce.data["id"]}:objectType=note",
186 "user" => UserView.render("show.json", user: other_user),
187 "retweeted_status" => ActivityView.render("activity.json", activity: activity),
188 "statusnet_conversation_id" => convo_id
191 assert result == expected
194 test "A follow activity" do
196 other_user = insert(:user, %{nickname: "shp"})
198 {:ok, follower} = User.follow(user, other_user)
199 {:ok, follow} = ActivityPub.follow(follower, other_user)
201 result = ActivityView.render("activity.json", activity: follow)
204 "activity_type" => "follow",
206 "created_at" => follow.data["published"] |> Utils.date_to_asctime(),
207 "external_url" => follow.data["id"],
209 "in_reply_to_status_id" => nil,
211 "is_post_verb" => false,
212 "statusnet_html" => "#{user.nickname} started following shp",
213 "text" => "#{user.nickname} started following shp",
214 "user" => UserView.render("show.json", user: user)
217 assert result == expected
220 test "a delete activity" do
223 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
224 {:ok, delete} = CommonAPI.delete(activity.id, user)
226 result = ActivityView.render("activity.json", activity: delete)
229 "activity_type" => "delete",
231 "created_at" => delete.data["published"] |> Utils.date_to_asctime(),
232 "external_url" => delete.data["id"],
234 "in_reply_to_status_id" => nil,
236 "is_post_verb" => false,
237 "statusnet_html" => "deleted notice {{tag",
238 "text" => "deleted notice {{tag",
239 "uri" => delete.data["object"],
240 "user" => UserView.render("show.json", user: user)
243 assert result == expected