Add statusnet_profile_url to the TwAPI.
[akkoma] / test / web / twitter_api / representers / activity_representer_test.exs
1 defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
2 use Pleroma.DataCase
3 alias Pleroma.{User, Activity, Object}
4 alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ActivityRepresenter, ObjectRepresenter}
5 alias Pleroma.Web.ActivityPub.ActivityPub
6 alias Pleroma.Builders.UserBuilder
7 import Pleroma.Factory
8
9 test "an announce activity" do
10 user = insert(:user)
11 note_activity = insert(:note_activity)
12 activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"])
13 object = Object.get_by_ap_id(note_activity.data["object"]["id"])
14
15 {:ok, announce_activity, _object} = ActivityPub.announce(user, object)
16 note_activity = Activity.get_by_ap_id(note_activity.data["id"])
17
18 status = ActivityRepresenter.to_map(announce_activity, %{users: [user, activity_actor], announced_activity: note_activity, for: user})
19
20 assert status["id"] == announce_activity.id
21 assert status["user"] == UserRepresenter.to_map(user, %{for: user})
22
23 retweeted_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
24 assert retweeted_status["repeated"] == true
25
26 assert status["retweeted_status"] == retweeted_status
27 end
28
29 test "a like activity" do
30 user = insert(:user)
31 note_activity = insert(:note_activity)
32 object = Object.get_by_ap_id(note_activity.data["object"]["id"])
33
34 {:ok, like_activity, _object} = ActivityPub.like(user, object)
35 status = ActivityRepresenter.to_map(like_activity, %{user: user, liked_activity: note_activity})
36
37 assert status["id"] == like_activity.id
38 assert status["in_reply_to_status_id"] == note_activity.id
39
40 note_activity = Activity.get_by_ap_id(note_activity.data["id"])
41 activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"])
42 liked_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
43 assert liked_status["favorited"] == true
44 end
45
46 test "an activity" do
47 {:ok, user} = UserBuilder.insert
48 # {:ok, mentioned_user } = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
49 mentioned_user = insert(:user, %{nickname: "shp"})
50
51 # {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
52 follower = insert(:user, %{following: [User.ap_followers(user)]})
53
54 object = %Object{
55 data: %{
56 "type" => "Image",
57 "url" => [
58 %{
59 "type" => "Link",
60 "mediaType" => "image/jpg",
61 "href" => "http://example.org/image.jpg"
62 }
63 ],
64 "uuid" => 1
65 }
66 }
67
68 content_html = "Some content mentioning <a href='#{mentioned_user.ap_id}'>@shp</shp>"
69 content = HtmlSanitizeEx.strip_tags(content_html)
70 date = DateTime.from_naive!(~N[2016-05-24 13:26:08.003], "Etc/UTC") |> DateTime.to_iso8601
71
72 {:ok, convo_object} = Object.context_mapping("2hu") |> Repo.insert
73
74 activity = %Activity{
75 id: 1,
76 data: %{
77 "type" => "Create",
78 "to" => [
79 User.ap_followers(user),
80 "https://www.w3.org/ns/activitystreams#Public",
81 mentioned_user.ap_id
82 ],
83 "actor" => User.ap_id(user),
84 "object" => %{
85 "published" => date,
86 "type" => "Note",
87 "content" => content_html,
88 "inReplyToStatusId" => 213123,
89 "attachment" => [
90 object
91 ],
92 "like_count" => 5,
93 "announcement_count" => 3,
94 "context" => "2hu"
95 },
96 "published" => date,
97 "context" => "2hu"
98 }
99 }
100
101
102 expected_status = %{
103 "id" => activity.id,
104 "user" => UserRepresenter.to_map(user, %{for: follower}),
105 "is_local" => true,
106 "attentions" => [],
107 "statusnet_html" => content_html,
108 "text" => content,
109 "is_post_verb" => true,
110 "created_at" => "Tue May 24 13:26:08 +0000 2016",
111 "in_reply_to_status_id" => 213123,
112 "statusnet_conversation_id" => convo_object.id,
113 "attachments" => [
114 ObjectRepresenter.to_map(object)
115 ],
116 "attentions" => [
117 UserRepresenter.to_map(mentioned_user, %{for: follower})
118 ],
119 "fave_num" => 5,
120 "repeat_num" => 3,
121 "favorited" => false,
122 "repeated" => false
123 }
124
125 assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status
126 end
127 end