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,
40 "is_post_verb" => true,
41 "possibly_sensitive" => false,
44 "statusnet_conversation_id" => convo_id,
46 "Hey <span><a href=\"#{other_user.ap_id}\">@<span>shp</span></a></span>!",
48 "text" => "Hey @shp!",
49 "uri" => activity.data["object"]["id"],
50 "user" => UserView.render("show.json", %{user: user}),
51 "visibility" => "direct",
55 assert result == expected
58 test "a list of activities" do
60 other_user = insert(:user, %{nickname: "shp"})
61 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
63 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
69 [context_to_conversation_id: fn _ -> false end]
74 [get_cached_by_ap_id: fn _ -> nil end]
79 [result] = ActivityView.render("index.json", activities: [activity])
81 assert result["statusnet_conversation_id"] == convo_id
83 refute called(TwitterAPI.context_to_conversation_id(:_))
84 refute called(User.get_cached_by_ap_id(user.ap_id))
85 refute called(User.get_cached_by_ap_id(other_user.ap_id))
89 test "an activity that is a reply" do
91 other_user = insert(:user, %{nickname: "shp"})
93 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
96 CommonAPI.post(other_user, %{"status" => "Hi!", "in_reply_to_status_id" => activity.id})
98 result = ActivityView.render("activity.json", %{activity: answer})
100 assert result["in_reply_to_status_id"] == activity.id
103 test "a like activity" do
105 other_user = insert(:user, %{nickname: "shp"})
107 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
108 {:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
110 result = ActivityView.render("activity.json", activity: like)
113 "activity_type" => "like",
114 "created_at" => like.data["published"] |> Utils.date_to_asctime(),
115 "external_url" => like.data["id"],
117 "in_reply_to_status_id" => activity.id,
119 "is_post_verb" => false,
120 "statusnet_html" => "shp favorited a status.",
121 "text" => "shp favorited a status.",
122 "uri" => "tag:#{like.data["id"]}:objectType=Favourite",
123 "user" => UserView.render("show.json", user: other_user)
126 assert result == expected
129 test "a like activity for deleted post" do
131 other_user = insert(:user, %{nickname: "shp"})
133 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
134 {:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
135 CommonAPI.delete(activity.id, user)
137 result = ActivityView.render("activity.json", activity: like)
140 "activity_type" => "like",
141 "created_at" => like.data["published"] |> Utils.date_to_asctime(),
142 "external_url" => like.data["id"],
144 "in_reply_to_status_id" => nil,
146 "is_post_verb" => false,
147 "statusnet_html" => "shp favorited a status.",
148 "text" => "shp favorited a status.",
149 "uri" => "tag:#{like.data["id"]}:objectType=Favourite",
150 "user" => UserView.render("show.json", user: other_user)
153 assert result == expected
156 test "an announce activity" do
158 other_user = insert(:user, %{nickname: "shp"})
160 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
161 {:ok, announce, _object} = CommonAPI.repeat(activity.id, other_user)
163 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
165 activity = Repo.get(Activity, activity.id)
167 result = ActivityView.render("activity.json", activity: announce)
170 "activity_type" => "repeat",
171 "created_at" => announce.data["published"] |> Utils.date_to_asctime(),
172 "external_url" => announce.data["id"],
175 "is_post_verb" => false,
176 "statusnet_html" => "shp retweeted a status.",
177 "text" => "shp retweeted a status.",
178 "uri" => "tag:#{announce.data["id"]}:objectType=note",
179 "user" => UserView.render("show.json", user: other_user),
180 "retweeted_status" => ActivityView.render("activity.json", activity: activity),
181 "statusnet_conversation_id" => convo_id
184 assert result == expected
187 test "A follow activity" do
189 other_user = insert(:user, %{nickname: "shp"})
191 {:ok, follower} = User.follow(user, other_user)
192 {:ok, follow} = ActivityPub.follow(follower, other_user)
194 result = ActivityView.render("activity.json", activity: follow)
197 "activity_type" => "follow",
199 "created_at" => follow.data["published"] |> Utils.date_to_asctime(),
200 "external_url" => follow.data["id"],
202 "in_reply_to_status_id" => nil,
204 "is_post_verb" => false,
205 "statusnet_html" => "#{user.nickname} started following shp",
206 "text" => "#{user.nickname} started following shp",
207 "user" => UserView.render("show.json", user: user)
210 assert result == expected
213 test "a delete activity" do
216 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
217 {:ok, delete} = CommonAPI.delete(activity.id, user)
219 result = ActivityView.render("activity.json", activity: delete)
222 "activity_type" => "delete",
224 "created_at" => delete.data["published"] |> Utils.date_to_asctime(),
225 "external_url" => delete.data["id"],
227 "in_reply_to_status_id" => nil,
229 "is_post_verb" => false,
230 "statusnet_html" => "deleted notice {{tag",
231 "text" => "deleted notice {{tag",
232 "uri" => delete.data["object"],
233 "user" => UserView.render("show.json", user: user)
236 assert result == expected