1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
8 alias Pleroma.Web.MastodonAPI.{StatusView, AccountView}
10 alias Pleroma.Web.OStatus
11 alias Pleroma.Web.CommonAPI
12 alias Pleroma.Web.ActivityPub.ActivityPub
13 alias Pleroma.Activity
14 import Pleroma.Factory
18 mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
22 test "a note with null content" do
23 note = insert(:note_activity)
27 |> put_in(["object", "content"], nil)
31 |> Map.put(:data, data)
33 User.get_cached_by_ap_id(note.data["actor"])
35 status = StatusView.render("status.json", %{activity: note})
37 assert status.content == ""
40 test "a note activity" do
41 note = insert(:note_activity)
42 user = User.get_cached_by_ap_id(note.data["actor"])
44 status = StatusView.render("status.json", %{activity: note})
47 (note.data["object"]["published"] || "")
48 |> String.replace(~r/\.\d+Z/, ".000Z")
51 id: to_string(note.id),
52 uri: note.data["object"]["id"],
53 url: note.data["object"]["id"],
54 account: AccountView.render("account.json", %{user: user}),
56 in_reply_to_account_id: nil,
58 content: HtmlSanitizeEx.basic_html(note.data["object"]["content"]),
59 created_at: created_at,
67 spoiler_text: note.data["object"]["summary"],
69 media_attachments: [],
73 name: "#{note.data["object"]["tag"]}",
74 url: "/tag/#{note.data["object"]["tag"]}"
86 static_url: "corndog.png",
87 visible_in_picker: false
92 assert status == expected
96 note = insert(:note_activity)
100 CommonAPI.post(user, %{"status" => "he", "in_reply_to_status_id" => note.id})
102 status = StatusView.render("status.json", %{activity: activity})
104 assert status.in_reply_to_id == to_string(note.id)
106 [status] = StatusView.render("index.json", %{activities: [activity], as: :activity})
108 assert status.in_reply_to_id == to_string(note.id)
111 test "contains mentions" do
112 incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
113 # a user with this ap id might be in the cache.
114 recipient = "https://pleroma.soykaf.com/users/lain"
115 user = insert(:user, %{ap_id: recipient})
117 {:ok, [activity]} = OStatus.handle_incoming(incoming)
119 status = StatusView.render("status.json", %{activity: activity})
121 assert status.mentions == [AccountView.render("mention.json", %{user: user})]
124 test "attachments" do
129 "mediaType" => "image/png",
140 remote_url: "someurl",
141 preview_url: "someurl",
146 assert expected == StatusView.render("attachment.json", %{attachment: object})
148 # If theres a "id", use that instead of the generated one
149 object = Map.put(object, "id", 2)
150 assert %{id: "2"} = StatusView.render("attachment.json", %{attachment: object})
155 activity = insert(:note_activity)
157 {:ok, reblog, _} = CommonAPI.repeat(activity.id, user)
159 represented = StatusView.render("status.json", %{for: user, activity: reblog})
161 assert represented[:id] == to_string(reblog.id)
162 assert represented[:reblog][:id] == to_string(activity.id)
163 assert represented[:emojis] == []
166 test "a peertube video" do
170 ActivityPub.fetch_object_from_id(
171 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
174 %Activity{} = activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
176 represented = StatusView.render("status.json", %{for: user, activity: activity})
178 assert represented[:id] == to_string(activity.id)
179 assert length(represented[:media_attachments]) == 1
182 describe "build_tags/1" do
183 test "it returns a a dictionary tags" do
189 "href" => "https://kawen.space/users/lain",
190 "name" => "@lain@kawen.space",
195 assert StatusView.build_tags(object_tags) == [
196 %{name: "fediverse", url: "/tag/fediverse"},
197 %{name: "mastodon", url: "/tag/mastodon"},
198 %{name: "nextcloud", url: "/tag/nextcloud"}