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,
68 spoiler_text: note.data["object"]["summary"],
70 media_attachments: [],
74 name: "#{note.data["object"]["tag"]}",
75 url: "/tag/#{note.data["object"]["tag"]}"
87 static_url: "corndog.png",
88 visible_in_picker: false
93 assert status == expected
97 note = insert(:note_activity)
101 CommonAPI.post(user, %{"status" => "he", "in_reply_to_status_id" => note.id})
103 status = StatusView.render("status.json", %{activity: activity})
105 assert status.in_reply_to_id == to_string(note.id)
107 [status] = StatusView.render("index.json", %{activities: [activity], as: :activity})
109 assert status.in_reply_to_id == to_string(note.id)
112 test "contains mentions" do
113 incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
114 # a user with this ap id might be in the cache.
115 recipient = "https://pleroma.soykaf.com/users/lain"
116 user = insert(:user, %{ap_id: recipient})
118 {:ok, [activity]} = OStatus.handle_incoming(incoming)
120 status = StatusView.render("status.json", %{activity: activity})
122 assert status.mentions == [AccountView.render("mention.json", %{user: user})]
125 test "attachments" do
130 "mediaType" => "image/png",
141 remote_url: "someurl",
142 preview_url: "someurl",
147 assert expected == StatusView.render("attachment.json", %{attachment: object})
149 # If theres a "id", use that instead of the generated one
150 object = Map.put(object, "id", 2)
151 assert %{id: "2"} = StatusView.render("attachment.json", %{attachment: object})
156 activity = insert(:note_activity)
158 {:ok, reblog, _} = CommonAPI.repeat(activity.id, user)
160 represented = StatusView.render("status.json", %{for: user, activity: reblog})
162 assert represented[:id] == to_string(reblog.id)
163 assert represented[:reblog][:id] == to_string(activity.id)
164 assert represented[:emojis] == []
167 test "a peertube video" do
171 ActivityPub.fetch_object_from_id(
172 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
175 %Activity{} = activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
177 represented = StatusView.render("status.json", %{for: user, activity: activity})
179 assert represented[:id] == to_string(activity.id)
180 assert length(represented[:media_attachments]) == 1
183 describe "build_tags/1" do
184 test "it returns a a dictionary tags" do
190 "href" => "https://kawen.space/users/lain",
191 "name" => "@lain@kawen.space",
196 assert StatusView.build_tags(object_tags) == [
197 %{name: "fediverse", url: "/tag/fediverse"},
198 %{name: "mastodon", url: "/tag/mastodon"},
199 %{name: "nextcloud", url: "/tag/nextcloud"}