Fix twitter api date.
[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_html = "Some content mentioning <a href='shp'>@shp</shp>"
27 content = HtmlSanitizeEx.strip_tags(content_html)
28 date = DateTime.from_naive!(~N[2016-05-24 13:26:08.003], "Etc/UTC") |> DateTime.to_iso8601
29
30 activity = %Activity{
31 id: 1,
32 data: %{
33 "type" => "Create",
34 "to" => [
35 User.ap_followers(user),
36 "https://www.w3.org/ns/activitystreams#Public",
37 mentioned_user.ap_id
38 ],
39 "actor" => User.ap_id(user),
40 "object" => %{
41 "published" => date,
42 "type" => "Note",
43 "content" => content_html,
44 "inReplyToStatusId" => 213123,
45 "statusnetConversationId" => 4711,
46 "attachment" => [
47 object
48 ]
49 },
50 "published" => date
51 }
52 }
53
54
55 expected_status = %{
56 "id" => activity.id,
57 "user" => UserRepresenter.to_map(user, %{for: follower}),
58 "is_local" => true,
59 "attentions" => [],
60 "statusnet_html" => content_html,
61 "text" => content,
62 "is_post_verb" => true,
63 "created_at" => "Tue May 24 13:26:08 +0000 2016",
64 "in_reply_to_status_id" => 213123,
65 "statusnet_conversation_id" => 4711,
66 "attachments" => [
67 ObjectRepresenter.to_map(object)
68 ],
69 "attentions" => [
70 UserRepresenter.to_map(mentioned_user, %{for: follower})
71 ]
72 }
73
74 assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status
75 end
76 end