1 defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
4 alias Pleroma.Web.MastodonAPI.{StatusView, AccountView}
6 alias Pleroma.Web.OStatus
7 alias Pleroma.Web.CommonAPI
12 mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
16 test "a note with null content" do
17 note = insert(:note_activity)
21 |> put_in(["object", "content"], nil)
25 |> Map.put(:data, data)
27 User.get_cached_by_ap_id(note.data["actor"])
29 status = StatusView.render("status.json", %{activity: note})
31 assert status.content == ""
34 test "a note activity" do
35 note = insert(:note_activity)
36 user = User.get_cached_by_ap_id(note.data["actor"])
38 status = StatusView.render("status.json", %{activity: note})
41 (note.data["object"]["published"] || "")
42 |> String.replace(~r/\.\d+Z/, ".000Z")
45 id: to_string(note.id),
46 uri: note.data["object"]["id"],
47 url: note.data["object"]["id"],
48 account: AccountView.render("account.json", %{user: user}),
50 in_reply_to_account_id: nil,
52 content: HtmlSanitizeEx.basic_html(note.data["object"]["content"]),
53 created_at: created_at,
61 spoiler_text: note.data["object"]["summary"],
63 media_attachments: [],
65 tags: note.data["object"]["tag"],
75 static_url: "corndog.png",
76 visible_in_picker: false
81 assert status == expected
85 note = insert(:note_activity)
89 CommonAPI.post(user, %{"status" => "he", "in_reply_to_status_id" => note.id})
91 status = StatusView.render("status.json", %{activity: activity})
93 assert status.in_reply_to_id == to_string(note.id)
95 [status] = StatusView.render("index.json", %{activities: [activity], as: :activity})
97 assert status.in_reply_to_id == to_string(note.id)
100 test "contains mentions" do
101 incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
102 # a user with this ap id might be in the cache.
103 recipient = "https://pleroma.soykaf.com/users/lain"
104 user = insert(:user, %{ap_id: recipient})
106 {:ok, [activity]} = OStatus.handle_incoming(incoming)
108 status = StatusView.render("status.json", %{activity: activity})
110 assert status.mentions == [AccountView.render("mention.json", %{user: user})]
113 test "attachments" do
118 "mediaType" => "image/png",
129 remote_url: "someurl",
130 preview_url: "someurl",
135 assert expected == StatusView.render("attachment.json", %{attachment: object})
137 # If theres a "id", use that instead of the generated one
138 object = Map.put(object, "id", 2)
139 assert %{id: "2"} = StatusView.render("attachment.json", %{attachment: object})
144 activity = insert(:note_activity)
146 {:ok, reblog, _} = CommonAPI.repeat(activity.id, user)
148 represented = StatusView.render("status.json", %{for: user, activity: reblog})
150 assert represented[:id] == to_string(reblog.id)
151 assert represented[:reblog][:id] == to_string(activity.id)
152 assert represented[:emojis] == []