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
13 import Pleroma.Factory
15 test "a create activity with a note" do
17 other_user = insert(:user, %{nickname: "shp"})
19 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
21 result = ActivityView.render("activity.json", activity: activity)
23 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
26 "activity_type" => "post",
29 UserView.render("show.json", %{user: other_user})
31 "created_at" => activity.data["object"]["published"] |> Utils.date_to_asctime(),
32 "external_url" => activity.data["object"]["id"],
36 "in_reply_to_status_id" => nil,
38 "is_post_verb" => true,
39 "possibly_sensitive" => false,
42 "statusnet_conversation_id" => convo_id,
44 "Hey <span><a href=\"#{other_user.ap_id}\">@<span>shp</span></a></span>!",
46 "text" => "Hey @shp!",
47 "uri" => activity.data["object"]["id"],
48 "user" => UserView.render("show.json", %{user: user})
51 assert result == expected
54 test "an activity that is a reply" do
56 other_user = insert(:user, %{nickname: "shp"})
58 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
61 CommonAPI.post(other_user, %{"status" => "Hi!", "in_reply_to_status_id" => activity.id})
63 result = ActivityView.render("activity.json", %{activity: answer})
65 assert result["in_reply_to_status_id"] == activity.id
68 test "a like activity" do
70 other_user = insert(:user, %{nickname: "shp"})
72 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
73 {:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
75 result = ActivityView.render("activity.json", activity: like)
78 "activity_type" => "like",
79 "created_at" => like.data["published"] |> Utils.date_to_asctime(),
80 "external_url" => like.data["id"],
82 "in_reply_to_status_id" => activity.id,
84 "is_post_verb" => false,
85 "statusnet_html" => "shp favorited a status.",
86 "text" => "shp favorited a status.",
87 "uri" => "tag:#{like.data["id"]}:objectType=Favourite",
88 "user" => UserView.render("show.json", user: other_user)
91 assert result == expected
94 test "an announce activity" do
96 other_user = insert(:user, %{nickname: "shp"})
98 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
99 {:ok, announce, _object} = CommonAPI.repeat(activity.id, other_user)
101 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
103 activity = Repo.get(Activity, activity.id)
105 result = ActivityView.render("activity.json", activity: announce)
108 "activity_type" => "repeat",
109 "created_at" => announce.data["published"] |> Utils.date_to_asctime(),
110 "external_url" => announce.data["id"],
113 "is_post_verb" => false,
114 "statusnet_html" => "shp retweeted a status.",
115 "text" => "shp retweeted a status.",
116 "uri" => "tag:#{announce.data["id"]}:objectType=note",
117 "user" => UserView.render("show.json", user: other_user),
118 "retweeted_status" => ActivityView.render("activity.json", activity: activity),
119 "statusnet_conversation_id" => convo_id
122 assert result == expected
125 test "A follow activity" do
127 other_user = insert(:user, %{nickname: "shp"})
129 {:ok, follower} = User.follow(user, other_user)
130 {:ok, follow} = ActivityPub.follow(follower, other_user)
132 result = ActivityView.render("activity.json", activity: follow)
135 "activity_type" => "follow",
137 "created_at" => follow.data["published"] |> Utils.date_to_asctime(),
138 "external_url" => follow.data["id"],
140 "in_reply_to_status_id" => nil,
142 "is_post_verb" => false,
143 "statusnet_html" => "#{user.nickname} started following shp",
144 "text" => "#{user.nickname} started following shp",
145 "user" => UserView.render("show.json", user: user)
148 assert result == expected
151 test "a delete activity" do
154 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
155 {:ok, delete} = CommonAPI.delete(activity.id, user)
157 result = ActivityView.render("activity.json", activity: delete)
160 "activity_type" => "delete",
162 "created_at" => delete.data["published"] |> Utils.date_to_asctime(),
163 "external_url" => delete.data["id"],
165 "in_reply_to_status_id" => nil,
167 "is_post_verb" => false,
168 "statusnet_html" => "deleted notice {{tag",
169 "text" => "deleted notice {{tag",
170 "uri" => delete.data["object"],
171 "user" => UserView.render("show.json", user: user)
174 assert result == expected