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: [],
67 name: "#{note.data["object"]["tag"]}",
68 url: "/tag/#{note.data["object"]["tag"]}"
80 static_url: "corndog.png",
81 visible_in_picker: false
86 assert status == expected
90 note = insert(:note_activity)
94 CommonAPI.post(user, %{"status" => "he", "in_reply_to_status_id" => note.id})
96 status = StatusView.render("status.json", %{activity: activity})
98 assert status.in_reply_to_id == to_string(note.id)
100 [status] = StatusView.render("index.json", %{activities: [activity], as: :activity})
102 assert status.in_reply_to_id == to_string(note.id)
105 test "contains mentions" do
106 incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
107 # a user with this ap id might be in the cache.
108 recipient = "https://pleroma.soykaf.com/users/lain"
109 user = insert(:user, %{ap_id: recipient})
111 {:ok, [activity]} = OStatus.handle_incoming(incoming)
113 status = StatusView.render("status.json", %{activity: activity})
115 assert status.mentions == [AccountView.render("mention.json", %{user: user})]
118 test "attachments" do
123 "mediaType" => "image/png",
134 remote_url: "someurl",
135 preview_url: "someurl",
140 assert expected == StatusView.render("attachment.json", %{attachment: object})
142 # If theres a "id", use that instead of the generated one
143 object = Map.put(object, "id", 2)
144 assert %{id: "2"} = StatusView.render("attachment.json", %{attachment: object})
149 activity = insert(:note_activity)
151 {:ok, reblog, _} = CommonAPI.repeat(activity.id, user)
153 represented = StatusView.render("status.json", %{for: user, activity: reblog})
155 assert represented[:id] == to_string(reblog.id)
156 assert represented[:reblog][:id] == to_string(activity.id)
157 assert represented[:emojis] == []
160 describe "build_tags/1" do
161 test "it returns a a dictionary tags" do
167 "href" => "https://kawen.space/users/lain",
168 "name" => "@lain@kawen.space",
173 assert StatusView.build_tags(object_tags) == [
174 %{name: "fediverse", url: "/tag/fediverse"},
175 %{name: "mastodon", url: "/tag/mastodon"},
176 %{name: "nextcloud", url: "/tag/nextcloud"}