Update status_view_test.exs
[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 visible_in_picker: false
52 }
53 ]
54 }
55
56 assert status == expected
57 end
58
59 test "a reply" do
60 note = insert(:note_activity)
61 user = insert(:user)
62
63 {:ok, activity} =
64 CommonAPI.post(user, %{"status" => "he", "in_reply_to_status_id" => note.id})
65
66 status = StatusView.render("status.json", %{activity: activity})
67
68 assert status.in_reply_to_id == to_string(note.id)
69
70 [status] = StatusView.render("index.json", %{activities: [activity], as: :activity})
71
72 assert status.in_reply_to_id == to_string(note.id)
73 end
74
75 test "contains mentions" do
76 incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
77 # a user with this ap id might be in the cache.
78 recipient = "https://pleroma.soykaf.com/users/lain"
79 user = insert(:user, %{ap_id: recipient})
80
81 {:ok, [activity]} = OStatus.handle_incoming(incoming)
82
83 status = StatusView.render("status.json", %{activity: activity})
84
85 assert status.mentions == [AccountView.render("mention.json", %{user: user})]
86 end
87
88 test "attachments" do
89 object = %{
90 "type" => "Image",
91 "url" => [
92 %{
93 "mediaType" => "image/png",
94 "href" => "someurl"
95 }
96 ],
97 "uuid" => 6
98 }
99
100 expected = %{
101 id: "1638338801",
102 type: "image",
103 url: "someurl",
104 remote_url: "someurl",
105 preview_url: "someurl",
106 text_url: "someurl",
107 description: nil
108 }
109
110 assert expected == StatusView.render("attachment.json", %{attachment: object})
111
112 # If theres a "id", use that instead of the generated one
113 object = Map.put(object, "id", 2)
114 assert %{id: "2"} = StatusView.render("attachment.json", %{attachment: object})
115 end
116
117 test "a reblog" do
118 user = insert(:user)
119 activity = insert(:note_activity)
120
121 {:ok, reblog, _} = CommonAPI.repeat(activity.id, user)
122
123 represented = StatusView.render("status.json", %{for: user, activity: reblog})
124
125 assert represented[:id] == to_string(reblog.id)
126 assert represented[:reblog][:id] == to_string(activity.id)
127 assert represented[:emojis] == []
128 end
129 end