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
11 import Pleroma.Factory
13 test "a create activity with a note" do
15 other_user = insert(:user, %{nickname: "shp"})
17 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
19 result = ActivityView.render("activity.json", activity: activity)
21 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
24 "activity_type" => "post",
27 UserView.render("show.json", %{user: other_user})
29 "created_at" => activity.data["object"]["published"] |> Utils.date_to_asctime(),
30 "external_url" => activity.data["object"]["id"],
34 "in_reply_to_status_id" => nil,
36 "is_post_verb" => true,
37 "possibly_sensitive" => false,
40 "statusnet_conversation_id" => convo_id,
42 "Hey <span><a href=\"#{other_user.ap_id}\">@<span>shp</span></a></span>!",
44 "text" => "Hey @shp!",
45 "uri" => activity.data["object"]["id"],
46 "user" => UserView.render("show.json", %{user: user})
49 assert result == expected
52 test "an activity that is a reply" do
54 other_user = insert(:user, %{nickname: "shp"})
56 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
59 CommonAPI.post(other_user, %{"status" => "Hi!", "in_reply_to_status_id" => activity.id})
61 result = ActivityView.render("activity.json", %{activity: answer})
63 assert result["in_reply_to_status_id"] == activity.id
66 test "a like activity" do
68 other_user = insert(:user, %{nickname: "shp"})
70 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
71 {:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
73 result = ActivityView.render("activity.json", activity: like)
76 "activity_type" => "like",
77 "created_at" => like.data["published"] |> Utils.date_to_asctime(),
78 "external_url" => like.data["id"],
80 "in_reply_to_status_id" => activity.id,
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)
89 assert result == expected
92 test "an announce activity" do
94 other_user = insert(:user, %{nickname: "shp"})
96 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
97 {:ok, announce, _object} = CommonAPI.repeat(activity.id, other_user)
99 convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
101 activity = Repo.get(Activity, activity.id)
103 result = ActivityView.render("activity.json", activity: announce)
106 "activity_type" => "repeat",
107 "created_at" => announce.data["published"] |> Utils.date_to_asctime(),
108 "external_url" => announce.data["id"],
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
120 assert result == expected