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