1 defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
4 alias Pleroma.Web.MastodonAPI.{StatusView, AccountView}
6 alias Pleroma.Web.OStatus
7 alias Pleroma.Web.CommonAPI
10 test "a note with null content" do
11 note = insert(:note_activity)
13 |> put_in(["object", "content"], nil)
15 |> Map.put(:data, data)
17 user = User.get_cached_by_ap_id(note.data["actor"])
19 status = StatusView.render("status.json", %{activity: note})
21 assert status.content == ""
24 test "a note activity" do
25 note = insert(:note_activity)
26 user = User.get_cached_by_ap_id(note.data["actor"])
28 status = StatusView.render("status.json", %{activity: note})
31 (note.data["object"]["published"] || "")
32 |> String.replace(~r/\.\d+Z/, ".000Z")
35 id: to_string(note.id),
36 uri: note.data["object"]["id"],
37 url: note.data["object"]["id"],
38 account: AccountView.render("account.json", %{user: user}),
40 in_reply_to_account_id: nil,
42 content: HtmlSanitizeEx.basic_html(note.data["object"]["content"]),
43 created_at: created_at,
51 spoiler_text: note.data["object"]["summary"],
53 media_attachments: [],
65 static_url: "corndog.png",
66 visible_in_picker: false
71 assert status == expected
75 note = insert(:note_activity)
79 CommonAPI.post(user, %{"status" => "he", "in_reply_to_status_id" => note.id})
81 status = StatusView.render("status.json", %{activity: activity})
83 assert status.in_reply_to_id == to_string(note.id)
85 [status] = StatusView.render("index.json", %{activities: [activity], as: :activity})
87 assert status.in_reply_to_id == to_string(note.id)
90 test "contains mentions" do
91 incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
92 # a user with this ap id might be in the cache.
93 recipient = "https://pleroma.soykaf.com/users/lain"
94 user = insert(:user, %{ap_id: recipient})
96 {:ok, [activity]} = OStatus.handle_incoming(incoming)
98 status = StatusView.render("status.json", %{activity: activity})
100 assert status.mentions == [AccountView.render("mention.json", %{user: user})]
103 test "attachments" do
108 "mediaType" => "image/png",
119 remote_url: "someurl",
120 preview_url: "someurl",
125 assert expected == StatusView.render("attachment.json", %{attachment: object})
127 # If theres a "id", use that instead of the generated one
128 object = Map.put(object, "id", 2)
129 assert %{id: "2"} = StatusView.render("attachment.json", %{attachment: object})
134 activity = insert(:note_activity)
136 {:ok, reblog, _} = CommonAPI.repeat(activity.id, user)
138 represented = StatusView.render("status.json", %{for: user, activity: reblog})
140 assert represented[:id] == to_string(reblog.id)
141 assert represented[:reblog][:id] == to_string(activity.id)
142 assert represented[:emojis] == []