Display like activities.
[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 "a like activity" do
10 user = insert(:user)
11 note_activity = insert(:note_activity)
12 object = Object.get_by_ap_id(note_activity.data["object"]["id"])
13
14 {:ok, like_activity, object} = ActivityPub.like(user, object)
15 status = ActivityRepresenter.to_map(like_activity, %{user: user, liked_activity: note_activity})
16
17 assert status["id"] == like_activity.id
18 assert status["in_reply_to_status_id"] == note_activity.id
19 end
20
21 test "an activity" do
22 {:ok, user} = UserBuilder.insert
23 {:ok, mentioned_user } = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
24 {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
25
26 object = %Object{
27 data: %{
28 "type" => "Image",
29 "url" => [
30 %{
31 "type" => "Link",
32 "mediaType" => "image/jpg",
33 "href" => "http://example.org/image.jpg"
34 }
35 ],
36 "uuid" => 1
37 }
38 }
39
40 content_html = "Some content mentioning <a href='shp'>@shp</shp>"
41 content = HtmlSanitizeEx.strip_tags(content_html)
42 date = DateTime.from_naive!(~N[2016-05-24 13:26:08.003], "Etc/UTC") |> DateTime.to_iso8601
43
44 activity = %Activity{
45 id: 1,
46 data: %{
47 "type" => "Create",
48 "to" => [
49 User.ap_followers(user),
50 "https://www.w3.org/ns/activitystreams#Public",
51 mentioned_user.ap_id
52 ],
53 "actor" => User.ap_id(user),
54 "object" => %{
55 "published" => date,
56 "type" => "Note",
57 "content" => content_html,
58 "inReplyToStatusId" => 213123,
59 "statusnetConversationId" => 4711,
60 "attachment" => [
61 object
62 ],
63 "like_count" => 5
64 },
65 "published" => date
66 }
67 }
68
69
70 expected_status = %{
71 "id" => activity.id,
72 "user" => UserRepresenter.to_map(user, %{for: follower}),
73 "is_local" => true,
74 "attentions" => [],
75 "statusnet_html" => content_html,
76 "text" => content,
77 "is_post_verb" => true,
78 "created_at" => "Tue May 24 13:26:08 +0000 2016",
79 "in_reply_to_status_id" => 213123,
80 "statusnet_conversation_id" => 4711,
81 "attachments" => [
82 ObjectRepresenter.to_map(object)
83 ],
84 "attentions" => [
85 UserRepresenter.to_map(mentioned_user, %{for: follower})
86 ],
87 "fave_num" => 5
88 }
89
90 assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status
91 end
92 end