1 defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
4 alias Pleroma.Web.MastodonAPI.{StatusView, AccountView}
5 alias Pleroma.{Repo, User, Object}
6 alias Pleroma.Web.OStatus
7 alias Pleroma.Web.CommonAPI
10 test "a note with null content" do
11 note = insert(:note_activity)
12 note_object = Object.normalize(note.data["object"])
16 |> Map.put("content", nil)
18 Object.change(note_object, %{data: data})
21 user = User.get_cached_by_ap_id(note.data["actor"])
23 status = StatusView.render("status.json", %{activity: note})
25 assert status.content == ""
28 test "a note activity" do
29 note = insert(:note_activity)
30 user = User.get_cached_by_ap_id(note.data["actor"])
32 status = StatusView.render("status.json", %{activity: note})
35 (note.data["object"]["published"] || "")
36 |> String.replace(~r/\.\d+Z/, ".000Z")
39 id: to_string(note.id),
40 uri: note.data["object"]["id"],
41 url: note.data["object"]["id"],
42 account: AccountView.render("account.json", %{user: user}),
44 in_reply_to_account_id: nil,
46 content: HtmlSanitizeEx.basic_html(note.data["object"]["content"]),
47 created_at: created_at,
55 spoiler_text: note.data["object"]["summary"],
57 media_attachments: [],
69 static_url: "corndog.png",
70 visible_in_picker: false
75 assert status == expected
79 note = insert(:note_activity)
83 CommonAPI.post(user, %{"status" => "he", "in_reply_to_status_id" => note.id})
85 status = StatusView.render("status.json", %{activity: activity})
87 assert status.in_reply_to_id == to_string(note.id)
89 [status] = StatusView.render("index.json", %{activities: [activity], as: :activity})
91 assert status.in_reply_to_id == to_string(note.id)
94 test "contains mentions" do
95 incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
96 # a user with this ap id might be in the cache.
97 recipient = "https://pleroma.soykaf.com/users/lain"
98 user = insert(:user, %{ap_id: recipient})
100 {:ok, [activity]} = OStatus.handle_incoming(incoming)
102 status = StatusView.render("status.json", %{activity: activity})
104 assert status.mentions == [AccountView.render("mention.json", %{user: user})]
107 test "attachments" do
112 "mediaType" => "image/png",
123 remote_url: "someurl",
124 preview_url: "someurl",
129 assert expected == StatusView.render("attachment.json", %{attachment: object})
131 # If theres a "id", use that instead of the generated one
132 object = Map.put(object, "id", 2)
133 assert %{id: "2"} = StatusView.render("attachment.json", %{attachment: object})
138 activity = insert(:note_activity)
140 {:ok, reblog, _} = CommonAPI.repeat(activity.id, user)
142 represented = StatusView.render("status.json", %{for: user, activity: reblog})
144 assert represented[:id] == to_string(reblog.id)
145 assert represented[:reblog][:id] == to_string(activity.id)
146 assert represented[:emojis] == []