TwApi ActivityView: Add announces.
[akkoma] / test / web / twitter_api / views / activity_view_test.exs
1 defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
2 use Pleroma.DataCase
3
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
9 alias Pleroma.Repo
10 alias Pleroma.Activity
11 import Pleroma.Factory
12
13 test "a create activity with a note" do
14 user = insert(:user)
15 other_user = insert(:user, %{nickname: "shp"})
16
17 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
18
19 result = ActivityView.render("activity.json", activity: activity)
20
21 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
22
23 expected = %{
24 "activity_type" => "post",
25 "attachments" => [],
26 "attentions" => [
27 UserView.render("show.json", %{user: other_user})
28 ],
29 "created_at" => activity.data["object"]["published"] |> Utils.date_to_asctime(),
30 "external_url" => activity.data["object"]["id"],
31 "fave_num" => 0,
32 "favorited" => false,
33 "id" => activity.id,
34 "in_reply_to_status_id" => nil,
35 "is_local" => true,
36 "is_post_verb" => true,
37 "possibly_sensitive" => false,
38 "repeat_num" => 0,
39 "repeated" => false,
40 "statusnet_conversation_id" => convo_id,
41 "statusnet_html" =>
42 "Hey <span><a href=\"#{other_user.ap_id}\">@<span>shp</span></a></span>!",
43 "tags" => [],
44 "text" => "Hey @shp!",
45 "uri" => activity.data["object"]["id"],
46 "user" => UserView.render("show.json", %{user: user})
47 }
48
49 assert result == expected
50 end
51
52 test "an activity that is a reply" do
53 user = insert(:user)
54 other_user = insert(:user, %{nickname: "shp"})
55
56 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
57
58 {:ok, answer} =
59 CommonAPI.post(other_user, %{"status" => "Hi!", "in_reply_to_status_id" => activity.id})
60
61 result = ActivityView.render("activity.json", %{activity: answer})
62
63 assert result["in_reply_to_status_id"] == activity.id
64 end
65
66 test "a like activity" do
67 user = insert(:user)
68 other_user = insert(:user, %{nickname: "shp"})
69
70 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
71 {:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
72
73 result = ActivityView.render("activity.json", activity: like)
74
75 expected = %{
76 "activity_type" => "like",
77 "created_at" => like.data["published"] |> Utils.date_to_asctime(),
78 "external_url" => like.data["id"],
79 "id" => like.id,
80 "in_reply_to_status_id" => activity.id,
81 "is_local" => true,
82 "is_post_verb" => false,
83 "statusnet_html" => "shp favorited a status.",
84 "text" => "shp favorited a status.",
85 "uri" => "tag:#{like.data["id"]}:objectType=Favourite",
86 "user" => UserView.render("show.json", user: other_user)
87 }
88
89 assert result == expected
90 end
91
92 test "an announce activity" do
93 user = insert(:user)
94 other_user = insert(:user, %{nickname: "shp"})
95
96 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
97 {:ok, announce, _object} = CommonAPI.repeat(activity.id, other_user)
98
99 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
100
101 activity = Repo.get(Activity, activity.id)
102
103 result = ActivityView.render("activity.json", activity: announce)
104
105 expected = %{
106 "activity_type" => "repeat",
107 "created_at" => announce.data["published"] |> Utils.date_to_asctime(),
108 "external_url" => announce.data["id"],
109 "id" => announce.id,
110 "is_local" => true,
111 "is_post_verb" => false,
112 "statusnet_html" => "shp retweeted a status.",
113 "text" => "shp retweeted a status.",
114 "uri" => "tag:#{announce.data["id"]}:objectType=note",
115 "user" => UserView.render("show.json", user: other_user),
116 "retweeted_status" => ActivityView.render("activity.json", activity: activity),
117 "statusnet_conversation_id" => convo_id
118 }
119
120 assert result == expected
121 end
122 end