1 defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
4 alias Pleroma.Web.MastodonAPI.{StatusView, AccountView}
6 alias Pleroma.Web.OStatus
7 alias Pleroma.Web.CommonAPI
8 alias Pleroma.Web.ActivityPub.ActivityPub
10 import Pleroma.Factory
14 mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
18 test "a note with null content" do
19 note = insert(:note_activity)
23 |> put_in(["object", "content"], nil)
27 |> Map.put(:data, data)
29 User.get_cached_by_ap_id(note.data["actor"])
31 status = StatusView.render("status.json", %{activity: note})
33 assert status.content == ""
36 test "a note activity" do
37 note = insert(:note_activity)
38 user = User.get_cached_by_ap_id(note.data["actor"])
40 status = StatusView.render("status.json", %{activity: note})
43 (note.data["object"]["published"] || "")
44 |> String.replace(~r/\.\d+Z/, ".000Z")
47 id: to_string(note.id),
48 uri: note.data["object"]["id"],
49 url: note.data["object"]["id"],
50 account: AccountView.render("account.json", %{user: user}),
52 in_reply_to_account_id: nil,
54 content: HtmlSanitizeEx.basic_html(note.data["object"]["content"]),
55 created_at: created_at,
63 spoiler_text: note.data["object"]["summary"],
65 media_attachments: [],
69 name: "#{note.data["object"]["tag"]}",
70 url: "/tag/#{note.data["object"]["tag"]}"
82 static_url: "corndog.png",
83 visible_in_picker: false
88 assert status == expected
92 note = insert(:note_activity)
96 CommonAPI.post(user, %{"status" => "he", "in_reply_to_status_id" => note.id})
98 status = StatusView.render("status.json", %{activity: activity})
100 assert status.in_reply_to_id == to_string(note.id)
102 [status] = StatusView.render("index.json", %{activities: [activity], as: :activity})
104 assert status.in_reply_to_id == to_string(note.id)
107 test "contains mentions" do
108 incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
109 # a user with this ap id might be in the cache.
110 recipient = "https://pleroma.soykaf.com/users/lain"
111 user = insert(:user, %{ap_id: recipient})
113 {:ok, [activity]} = OStatus.handle_incoming(incoming)
115 status = StatusView.render("status.json", %{activity: activity})
117 assert status.mentions == [AccountView.render("mention.json", %{user: user})]
120 test "attachments" do
125 "mediaType" => "image/png",
136 remote_url: "someurl",
137 preview_url: "someurl",
142 assert expected == StatusView.render("attachment.json", %{attachment: object})
144 # If theres a "id", use that instead of the generated one
145 object = Map.put(object, "id", 2)
146 assert %{id: "2"} = StatusView.render("attachment.json", %{attachment: object})
151 activity = insert(:note_activity)
153 {:ok, reblog, _} = CommonAPI.repeat(activity.id, user)
155 represented = StatusView.render("status.json", %{for: user, activity: reblog})
157 assert represented[:id] == to_string(reblog.id)
158 assert represented[:reblog][:id] == to_string(activity.id)
159 assert represented[:emojis] == []
162 test "a peertube video" do
166 ActivityPub.fetch_object_from_id(
167 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
170 %Activity{} = activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
172 represented = StatusView.render("status.json", %{for: user, activity: activity})
174 assert represented[:id] == to_string(activity.id)
175 assert length(represented[:media_attachments]) == 1
178 describe "build_tags/1" do
179 test "it returns a a dictionary tags" do
185 "href" => "https://kawen.space/users/lain",
186 "name" => "@lain@kawen.space",
191 assert StatusView.build_tags(object_tags) == [
192 %{name: "fediverse", url: "/tag/fediverse"},
193 %{name: "mastodon", url: "/tag/mastodon"},
194 %{name: "nextcloud", url: "/tag/nextcloud"}