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"
54 assert result == expected
57 test "a list of activities" do
59 other_user = insert(:user, %{nickname: "shp"})
60 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
62 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
68 [context_to_conversation_id: fn _ -> false end]
73 [get_cached_by_ap_id: fn _ -> nil end]
78 [result] = ActivityView.render("index.json", activities: [activity])
80 assert result["statusnet_conversation_id"] == convo_id
82 refute called(TwitterAPI.context_to_conversation_id(:_))
83 refute called(User.get_cached_by_ap_id(user.ap_id))
84 refute called(User.get_cached_by_ap_id(other_user.ap_id))
88 test "an activity that is a reply" do
90 other_user = insert(:user, %{nickname: "shp"})
92 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
95 CommonAPI.post(other_user, %{"status" => "Hi!", "in_reply_to_status_id" => activity.id})
97 result = ActivityView.render("activity.json", %{activity: answer})
99 assert result["in_reply_to_status_id"] == activity.id
102 test "a like activity" do
104 other_user = insert(:user, %{nickname: "shp"})
106 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
107 {:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
109 result = ActivityView.render("activity.json", activity: like)
112 "activity_type" => "like",
113 "created_at" => like.data["published"] |> Utils.date_to_asctime(),
114 "external_url" => like.data["id"],
116 "in_reply_to_status_id" => activity.id,
118 "is_post_verb" => false,
119 "statusnet_html" => "shp favorited a status.",
120 "text" => "shp favorited a status.",
121 "uri" => "tag:#{like.data["id"]}:objectType=Favourite",
122 "user" => UserView.render("show.json", user: other_user)
125 assert result == expected
128 test "an announce activity" do
130 other_user = insert(:user, %{nickname: "shp"})
132 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
133 {:ok, announce, _object} = CommonAPI.repeat(activity.id, other_user)
135 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
137 activity = Repo.get(Activity, activity.id)
139 result = ActivityView.render("activity.json", activity: announce)
142 "activity_type" => "repeat",
143 "created_at" => announce.data["published"] |> Utils.date_to_asctime(),
144 "external_url" => announce.data["id"],
147 "is_post_verb" => false,
148 "statusnet_html" => "shp retweeted a status.",
149 "text" => "shp retweeted a status.",
150 "uri" => "tag:#{announce.data["id"]}:objectType=note",
151 "user" => UserView.render("show.json", user: other_user),
152 "retweeted_status" => ActivityView.render("activity.json", activity: activity),
153 "statusnet_conversation_id" => convo_id
156 assert result == expected
159 test "A follow activity" do
161 other_user = insert(:user, %{nickname: "shp"})
163 {:ok, follower} = User.follow(user, other_user)
164 {:ok, follow} = ActivityPub.follow(follower, other_user)
166 result = ActivityView.render("activity.json", activity: follow)
169 "activity_type" => "follow",
171 "created_at" => follow.data["published"] |> Utils.date_to_asctime(),
172 "external_url" => follow.data["id"],
174 "in_reply_to_status_id" => nil,
176 "is_post_verb" => false,
177 "statusnet_html" => "#{user.nickname} started following shp",
178 "text" => "#{user.nickname} started following shp",
179 "user" => UserView.render("show.json", user: user)
182 assert result == expected
185 test "a delete activity" do
188 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
189 {:ok, delete} = CommonAPI.delete(activity.id, user)
191 result = ActivityView.render("activity.json", activity: delete)
194 "activity_type" => "delete",
196 "created_at" => delete.data["published"] |> Utils.date_to_asctime(),
197 "external_url" => delete.data["id"],
199 "in_reply_to_status_id" => nil,
201 "is_post_verb" => false,
202 "statusnet_html" => "deleted notice {{tag",
203 "text" => "deleted notice {{tag",
204 "uri" => delete.data["object"],
205 "user" => UserView.render("show.json", user: user)
208 assert result == expected