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 [result] = ActivityView.render("index.json", activities: [activity])
74 assert result["statusnet_conversation_id"] == convo_id
76 refute called TwitterAPI.context_to_conversation_id(:_)
80 test "an activity that is a reply" do
82 other_user = insert(:user, %{nickname: "shp"})
84 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
87 CommonAPI.post(other_user, %{"status" => "Hi!", "in_reply_to_status_id" => activity.id})
89 result = ActivityView.render("activity.json", %{activity: answer})
91 assert result["in_reply_to_status_id"] == activity.id
94 test "a like activity" do
96 other_user = insert(:user, %{nickname: "shp"})
98 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
99 {:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
101 result = ActivityView.render("activity.json", activity: like)
104 "activity_type" => "like",
105 "created_at" => like.data["published"] |> Utils.date_to_asctime(),
106 "external_url" => like.data["id"],
108 "in_reply_to_status_id" => activity.id,
110 "is_post_verb" => false,
111 "statusnet_html" => "shp favorited a status.",
112 "text" => "shp favorited a status.",
113 "uri" => "tag:#{like.data["id"]}:objectType=Favourite",
114 "user" => UserView.render("show.json", user: other_user)
117 assert result == expected
120 test "an announce activity" do
122 other_user = insert(:user, %{nickname: "shp"})
124 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
125 {:ok, announce, _object} = CommonAPI.repeat(activity.id, other_user)
127 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
129 activity = Repo.get(Activity, activity.id)
131 result = ActivityView.render("activity.json", activity: announce)
134 "activity_type" => "repeat",
135 "created_at" => announce.data["published"] |> Utils.date_to_asctime(),
136 "external_url" => announce.data["id"],
139 "is_post_verb" => false,
140 "statusnet_html" => "shp retweeted a status.",
141 "text" => "shp retweeted a status.",
142 "uri" => "tag:#{announce.data["id"]}:objectType=note",
143 "user" => UserView.render("show.json", user: other_user),
144 "retweeted_status" => ActivityView.render("activity.json", activity: activity),
145 "statusnet_conversation_id" => convo_id
148 assert result == expected
151 test "A follow activity" do
153 other_user = insert(:user, %{nickname: "shp"})
155 {:ok, follower} = User.follow(user, other_user)
156 {:ok, follow} = ActivityPub.follow(follower, other_user)
158 result = ActivityView.render("activity.json", activity: follow)
161 "activity_type" => "follow",
163 "created_at" => follow.data["published"] |> Utils.date_to_asctime(),
164 "external_url" => follow.data["id"],
166 "in_reply_to_status_id" => nil,
168 "is_post_verb" => false,
169 "statusnet_html" => "#{user.nickname} started following shp",
170 "text" => "#{user.nickname} started following shp",
171 "user" => UserView.render("show.json", user: user)
174 assert result == expected
177 test "a delete activity" do
180 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
181 {:ok, delete} = CommonAPI.delete(activity.id, user)
183 result = ActivityView.render("activity.json", activity: delete)
186 "activity_type" => "delete",
188 "created_at" => delete.data["published"] |> Utils.date_to_asctime(),
189 "external_url" => delete.data["id"],
191 "in_reply_to_status_id" => nil,
193 "is_post_verb" => false,
194 "statusnet_html" => "deleted notice {{tag",
195 "text" => "deleted notice {{tag",
196 "uri" => delete.data["object"],
197 "user" => UserView.render("show.json", user: user)
200 assert result == expected