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)
117 "activity_type" => "like",
118 "created_at" => like.data["published"] |> Utils.date_to_asctime(),
119 "external_url" => like.data["id"],
121 "in_reply_to_status_id" => activity.id,
123 "is_post_verb" => false,
124 "statusnet_html" => "shp favorited a status.",
125 "text" => "shp favorited a status.",
126 "uri" => "tag:#{like.data["id"]}:objectType=Favourite",
127 "user" => UserView.render("show.json", user: other_user)
130 assert result == expected
133 test "a like activity for deleted post" do
135 other_user = insert(:user, %{nickname: "shp"})
137 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
138 {:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
139 CommonAPI.delete(activity.id, user)
141 result = ActivityView.render("activity.json", activity: like)
144 "activity_type" => "like",
145 "created_at" => like.data["published"] |> Utils.date_to_asctime(),
146 "external_url" => like.data["id"],
148 "in_reply_to_status_id" => nil,
150 "is_post_verb" => false,
151 "statusnet_html" => "shp favorited a status.",
152 "text" => "shp favorited a status.",
153 "uri" => "tag:#{like.data["id"]}:objectType=Favourite",
154 "user" => UserView.render("show.json", user: other_user)
157 assert result == expected
160 test "an announce activity" do
162 other_user = insert(:user, %{nickname: "shp"})
164 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
165 {:ok, announce, _object} = CommonAPI.repeat(activity.id, other_user)
167 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
169 activity = Repo.get(Activity, activity.id)
171 result = ActivityView.render("activity.json", activity: announce)
174 "activity_type" => "repeat",
175 "created_at" => announce.data["published"] |> Utils.date_to_asctime(),
176 "external_url" => announce.data["id"],
179 "is_post_verb" => false,
180 "statusnet_html" => "shp retweeted a status.",
181 "text" => "shp retweeted a status.",
182 "uri" => "tag:#{announce.data["id"]}:objectType=note",
183 "user" => UserView.render("show.json", user: other_user),
184 "retweeted_status" => ActivityView.render("activity.json", activity: activity),
185 "statusnet_conversation_id" => convo_id
188 assert result == expected
191 test "A follow activity" do
193 other_user = insert(:user, %{nickname: "shp"})
195 {:ok, follower} = User.follow(user, other_user)
196 {:ok, follow} = ActivityPub.follow(follower, other_user)
198 result = ActivityView.render("activity.json", activity: follow)
201 "activity_type" => "follow",
203 "created_at" => follow.data["published"] |> Utils.date_to_asctime(),
204 "external_url" => follow.data["id"],
206 "in_reply_to_status_id" => nil,
208 "is_post_verb" => false,
209 "statusnet_html" => "#{user.nickname} started following shp",
210 "text" => "#{user.nickname} started following shp",
211 "user" => UserView.render("show.json", user: user)
214 assert result == expected
217 test "a delete activity" do
220 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
221 {:ok, delete} = CommonAPI.delete(activity.id, user)
223 result = ActivityView.render("activity.json", activity: delete)
226 "activity_type" => "delete",
228 "created_at" => delete.data["published"] |> Utils.date_to_asctime(),
229 "external_url" => delete.data["id"],
231 "in_reply_to_status_id" => nil,
233 "is_post_verb" => false,
234 "statusnet_html" => "deleted notice {{tag",
235 "text" => "deleted notice {{tag",
236 "uri" => delete.data["object"],
237 "user" => UserView.render("show.json", user: user)
240 assert result == expected