Return directly addressed activities in friends timeline.
[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.Builders.UserBuilder
6
7 test "an activity" do
8 {:ok, user} = UserBuilder.insert
9 {:ok, mentioned_user } = UserBuilder.insert(%{nickname: "shp", ap_id: "shp"})
10 {:ok, follower} = UserBuilder.insert(%{following: [User.ap_followers(user)]})
11
12 object = %Object{
13 data: %{
14 "type" => "Image",
15 "url" => [
16 %{
17 "type" => "Link",
18 "mediaType" => "image/jpg",
19 "href" => "http://example.org/image.jpg"
20 }
21 ],
22 "uuid" => 1
23 }
24 }
25
26 content = "Some content mentioning @shp"
27 date = DateTime.utc_now() |> DateTime.to_iso8601
28
29 activity = %Activity{
30 id: 1,
31 data: %{
32 "type" => "Create",
33 "to" => [
34 User.ap_followers(user),
35 "https://www.w3.org/ns/activitystreams#Public",
36 mentioned_user.ap_id
37 ],
38 "actor" => User.ap_id(user),
39 "object" => %{
40 "published" => date,
41 "type" => "Note",
42 "content" => content,
43 "inReplyToStatusId" => 213123,
44 "statusnetConversationId" => 4711,
45 "attachment" => [
46 object
47 ]
48 },
49 "published" => date
50 }
51 }
52
53
54 expected_status = %{
55 "id" => activity.id,
56 "user" => UserRepresenter.to_map(user, %{for: follower}),
57 "is_local" => true,
58 "attentions" => [],
59 "statusnet_html" => content,
60 "text" => content,
61 "is_post_verb" => true,
62 "created_at" => date,
63 "in_reply_to_status_id" => 213123,
64 "statusnet_conversation_id" => 4711,
65 "attachments" => [
66 ObjectRepresenter.to_map(object)
67 ],
68 "attentions" => [
69 UserRepresenter.to_map(mentioned_user, %{for: follower})
70 ]
71 }
72
73 assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status
74 end
75 end