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,
41 "is_post_verb" => true,
42 "possibly_sensitive" => false,
45 "statusnet_conversation_id" => convo_id,
47 "Hey <span><a href=\"#{other_user.ap_id}\">@<span>shp</span></a></span>!",
49 "text" => "Hey @shp!",
50 "uri" => activity.data["object"]["id"],
51 "user" => UserView.render("show.json", %{user: user}),
52 "visibility" => "direct",
56 assert result == expected
59 test "a list of activities" do
61 other_user = insert(:user, %{nickname: "shp"})
62 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
64 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
70 [context_to_conversation_id: fn _ -> false end]
75 [get_cached_by_ap_id: fn _ -> nil end]
80 [result] = ActivityView.render("index.json", activities: [activity])
82 assert result["statusnet_conversation_id"] == convo_id
84 refute called(TwitterAPI.context_to_conversation_id(:_))
85 refute called(User.get_cached_by_ap_id(user.ap_id))
86 refute called(User.get_cached_by_ap_id(other_user.ap_id))
90 test "an activity that is a reply" do
92 other_user = insert(:user, %{nickname: "shp"})
94 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
97 CommonAPI.post(other_user, %{"status" => "Hi!", "in_reply_to_status_id" => activity.id})
99 result = ActivityView.render("activity.json", %{activity: answer})
101 assert result["in_reply_to_status_id"] == activity.id
104 test "a like activity" do
106 other_user = insert(:user, %{nickname: "shp"})
108 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
109 {:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
111 result = ActivityView.render("activity.json", activity: like)
114 "activity_type" => "like",
115 "created_at" => like.data["published"] |> Utils.date_to_asctime(),
116 "external_url" => like.data["id"],
118 "in_reply_to_status_id" => activity.id,
120 "is_post_verb" => false,
121 "statusnet_html" => "shp favorited a status.",
122 "text" => "shp favorited a status.",
123 "uri" => "tag:#{like.data["id"]}:objectType=Favourite",
124 "user" => UserView.render("show.json", user: other_user)
127 assert result == expected
130 test "a like activity for deleted post" do
132 other_user = insert(:user, %{nickname: "shp"})
134 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
135 {:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
136 CommonAPI.delete(activity.id, user)
138 result = ActivityView.render("activity.json", activity: like)
141 "activity_type" => "like",
142 "created_at" => like.data["published"] |> Utils.date_to_asctime(),
143 "external_url" => like.data["id"],
145 "in_reply_to_status_id" => nil,
147 "is_post_verb" => false,
148 "statusnet_html" => "shp favorited a status.",
149 "text" => "shp favorited a status.",
150 "uri" => "tag:#{like.data["id"]}:objectType=Favourite",
151 "user" => UserView.render("show.json", user: other_user)
154 assert result == expected
157 test "an announce activity" do
159 other_user = insert(:user, %{nickname: "shp"})
161 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
162 {:ok, announce, _object} = CommonAPI.repeat(activity.id, other_user)
164 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
166 activity = Repo.get(Activity, activity.id)
168 result = ActivityView.render("activity.json", activity: announce)
171 "activity_type" => "repeat",
172 "created_at" => announce.data["published"] |> Utils.date_to_asctime(),
173 "external_url" => announce.data["id"],
176 "is_post_verb" => false,
177 "statusnet_html" => "shp retweeted a status.",
178 "text" => "shp retweeted a status.",
179 "uri" => "tag:#{announce.data["id"]}:objectType=note",
180 "user" => UserView.render("show.json", user: other_user),
181 "retweeted_status" => ActivityView.render("activity.json", activity: activity),
182 "statusnet_conversation_id" => convo_id
185 assert result == expected
188 test "A follow activity" do
190 other_user = insert(:user, %{nickname: "shp"})
192 {:ok, follower} = User.follow(user, other_user)
193 {:ok, follow} = ActivityPub.follow(follower, other_user)
195 result = ActivityView.render("activity.json", activity: follow)
198 "activity_type" => "follow",
200 "created_at" => follow.data["published"] |> Utils.date_to_asctime(),
201 "external_url" => follow.data["id"],
203 "in_reply_to_status_id" => nil,
205 "is_post_verb" => false,
206 "statusnet_html" => "#{user.nickname} started following shp",
207 "text" => "#{user.nickname} started following shp",
208 "user" => UserView.render("show.json", user: user)
211 assert result == expected
214 test "a delete activity" do
217 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
218 {:ok, delete} = CommonAPI.delete(activity.id, user)
220 result = ActivityView.render("activity.json", activity: delete)
223 "activity_type" => "delete",
225 "created_at" => delete.data["published"] |> Utils.date_to_asctime(),
226 "external_url" => delete.data["id"],
228 "in_reply_to_status_id" => nil,
230 "is_post_verb" => false,
231 "statusnet_html" => "deleted notice {{tag",
232 "text" => "deleted notice {{tag",
233 "uri" => delete.data["object"],
234 "user" => UserView.render("show.json", user: user)
237 assert result == expected