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