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