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!"})
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})
53 assert result == expected
56 test "a list of activities" do
58 other_user = insert(:user, %{nickname: "shp"})
59 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
61 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
67 [context_to_conversation_id: fn _ -> false end]
72 [get_cached_by_ap_id: fn _ -> nil end]
77 [result] = ActivityView.render("index.json", activities: [activity])
79 assert result["statusnet_conversation_id"] == convo_id
81 refute called(TwitterAPI.context_to_conversation_id(:_))
82 refute called(User.get_cached_by_ap_id(user.ap_id))
83 refute called(User.get_cached_by_ap_id(other_user.ap_id))
87 test "an activity that is a reply" do
89 other_user = insert(:user, %{nickname: "shp"})
91 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
94 CommonAPI.post(other_user, %{"status" => "Hi!", "in_reply_to_status_id" => activity.id})
96 result = ActivityView.render("activity.json", %{activity: answer})
98 assert result["in_reply_to_status_id"] == activity.id
101 test "a like activity" do
103 other_user = insert(:user, %{nickname: "shp"})
105 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
106 {:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
108 result = ActivityView.render("activity.json", activity: like)
111 "activity_type" => "like",
112 "created_at" => like.data["published"] |> Utils.date_to_asctime(),
113 "external_url" => like.data["id"],
115 "in_reply_to_status_id" => activity.id,
117 "is_post_verb" => false,
118 "statusnet_html" => "shp favorited a status.",
119 "text" => "shp favorited a status.",
120 "uri" => "tag:#{like.data["id"]}:objectType=Favourite",
121 "user" => UserView.render("show.json", user: other_user)
124 assert result == expected
127 test "an announce activity" do
129 other_user = insert(:user, %{nickname: "shp"})
131 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
132 {:ok, announce, _object} = CommonAPI.repeat(activity.id, other_user)
134 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
136 activity = Repo.get(Activity, activity.id)
138 result = ActivityView.render("activity.json", activity: announce)
141 "activity_type" => "repeat",
142 "created_at" => announce.data["published"] |> Utils.date_to_asctime(),
143 "external_url" => announce.data["id"],
146 "is_post_verb" => false,
147 "statusnet_html" => "shp retweeted a status.",
148 "text" => "shp retweeted a status.",
149 "uri" => "tag:#{announce.data["id"]}:objectType=note",
150 "user" => UserView.render("show.json", user: other_user),
151 "retweeted_status" => ActivityView.render("activity.json", activity: activity),
152 "statusnet_conversation_id" => convo_id
155 assert result == expected
158 test "A follow activity" do
160 other_user = insert(:user, %{nickname: "shp"})
162 {:ok, follower} = User.follow(user, other_user)
163 {:ok, follow} = ActivityPub.follow(follower, other_user)
165 result = ActivityView.render("activity.json", activity: follow)
168 "activity_type" => "follow",
170 "created_at" => follow.data["published"] |> Utils.date_to_asctime(),
171 "external_url" => follow.data["id"],
173 "in_reply_to_status_id" => nil,
175 "is_post_verb" => false,
176 "statusnet_html" => "#{user.nickname} started following shp",
177 "text" => "#{user.nickname} started following shp",
178 "user" => UserView.render("show.json", user: user)
181 assert result == expected
184 test "a delete activity" do
187 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
188 {:ok, delete} = CommonAPI.delete(activity.id, user)
190 result = ActivityView.render("activity.json", activity: delete)
193 "activity_type" => "delete",
195 "created_at" => delete.data["published"] |> Utils.date_to_asctime(),
196 "external_url" => delete.data["id"],
198 "in_reply_to_status_id" => nil,
200 "is_post_verb" => false,
201 "statusnet_html" => "deleted notice {{tag",
202 "text" => "deleted notice {{tag",
203 "uri" => delete.data["object"],
204 "user" => UserView.render("show.json", user: user)
207 assert result == expected