Format the code.
[akkoma] / test / web / mastodon_api / status_view_test.exs
1 defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
2 use Pleroma.DataCase
3
4 alias Pleroma.Web.MastodonAPI.{StatusView, AccountView}
5 alias Pleroma.User
6 alias Pleroma.Web.OStatus
7 alias Pleroma.Web.CommonAPI
8 import Pleroma.Factory
9
10 test "a note activity" do
11 note = insert(:note_activity)
12 user = User.get_cached_by_ap_id(note.data["actor"])
13
14 status = StatusView.render("status.json", %{activity: note})
15
16 created_at =
17 (note.data["object"]["published"] || "")
18 |> String.replace(~r/\.\d+Z/, ".000Z")
19
20 expected = %{
21 id: to_string(note.id),
22 uri: note.data["object"]["id"],
23 url: note.data["object"]["id"],
24 account: AccountView.render("account.json", %{user: user}),
25 in_reply_to_id: nil,
26 in_reply_to_account_id: nil,
27 reblog: nil,
28 content: HtmlSanitizeEx.basic_html(note.data["object"]["content"]),
29 created_at: created_at,
30 reblogs_count: 0,
31 favourites_count: 0,
32 reblogged: false,
33 favourited: false,
34 muted: false,
35 sensitive: false,
36 spoiler_text: note.data["object"]["summary"],
37 visibility: "public",
38 media_attachments: [],
39 mentions: [],
40 tags: [],
41 application: %{
42 name: "Web",
43 website: nil
44 },
45 language: nil,
46 emojis: [
47 %{
48 shortcode: "2hu",
49 url: "corndog.png",
50 static_url: "corndog.png"
51 }
52 ]
53 }
54
55 assert status == expected
56 end
57
58 test "a reply" do
59 note = insert(:note_activity)
60 user = insert(:user)
61
62 {:ok, activity} =
63 CommonAPI.post(user, %{"status" => "he", "in_reply_to_status_id" => note.id})
64
65 status = StatusView.render("status.json", %{activity: activity})
66
67 assert status.in_reply_to_id == note.id
68
69 [status] = StatusView.render("index.json", %{activities: [activity], as: :activity})
70
71 assert status.in_reply_to_id == note.id
72 end
73
74 test "contains mentions" do
75 incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
76 # a user with this ap id might be in the cache.
77 recipient = "https://pleroma.soykaf.com/users/lain"
78 user = insert(:user, %{ap_id: recipient})
79
80 {:ok, [activity]} = OStatus.handle_incoming(incoming)
81
82 status = StatusView.render("status.json", %{activity: activity})
83
84 assert status.mentions == [AccountView.render("mention.json", %{user: user})]
85 end
86
87 test "attachments" do
88 object = %{
89 "type" => "Image",
90 "url" => [
91 %{
92 "mediaType" => "image/png",
93 "href" => "someurl"
94 }
95 ],
96 "uuid" => 6
97 }
98
99 expected = %{
100 id: "1638338801",
101 type: "image",
102 url: "someurl",
103 remote_url: "someurl",
104 preview_url: "someurl",
105 text_url: "someurl"
106 }
107
108 assert expected == StatusView.render("attachment.json", %{attachment: object})
109
110 # If theres a "id", use that instead of the generated one
111 object = Map.put(object, "id", 2)
112 assert %{id: "2"} = StatusView.render("attachment.json", %{attachment: object})
113 end
114
115 test "a reblog" do
116 user = insert(:user)
117 activity = insert(:note_activity)
118
119 {:ok, reblog, _} = CommonAPI.repeat(activity.id, user)
120
121 represented = StatusView.render("status.json", %{for: user, activity: reblog})
122
123 assert represented[:id] == to_string(reblog.id)
124 assert represented[:reblog][:id] == to_string(activity.id)
125 assert represented[:emojis] == []
126 end
127 end