1 defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
4 alias Pleroma.Web.MastodonAPI.{StatusView, AccountView}
6 alias Pleroma.Web.OStatus
7 alias Pleroma.Web.CommonAPI
10 test "a note activity" do
11 note = insert(:note_activity)
12 user = User.get_cached_by_ap_id(note.data["actor"])
14 status = StatusView.render("status.json", %{activity: note})
17 (note.data["object"]["published"] || "")
18 |> String.replace(~r/\.\d+Z/, ".000Z")
21 id: to_string(note.id),
22 uri: note.data["object"]["id"],
23 url: note.data["object"]["id"],
24 account: AccountView.render("account.json", %{user: user}),
26 in_reply_to_account_id: nil,
28 content: HtmlSanitizeEx.basic_html(note.data["object"]["content"]),
29 created_at: created_at,
37 spoiler_text: note.data["object"]["summary"],
39 media_attachments: [],
51 static_url: "corndog.png",
52 visible_in_picker: false
57 assert status == expected
61 note = insert(:note_activity)
65 CommonAPI.post(user, %{"status" => "he", "in_reply_to_status_id" => note.id})
67 status = StatusView.render("status.json", %{activity: activity})
69 assert status.in_reply_to_id == to_string(note.id)
71 [status] = StatusView.render("index.json", %{activities: [activity], as: :activity})
73 assert status.in_reply_to_id == to_string(note.id)
76 test "contains mentions" do
77 incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
78 # a user with this ap id might be in the cache.
79 recipient = "https://pleroma.soykaf.com/users/lain"
80 user = insert(:user, %{ap_id: recipient})
82 {:ok, [activity]} = OStatus.handle_incoming(incoming)
84 status = StatusView.render("status.json", %{activity: activity})
86 assert status.mentions == [AccountView.render("mention.json", %{user: user})]
94 "mediaType" => "image/png",
105 remote_url: "someurl",
106 preview_url: "someurl",
111 assert expected == StatusView.render("attachment.json", %{attachment: object})
113 # If theres a "id", use that instead of the generated one
114 object = Map.put(object, "id", 2)
115 assert %{id: "2"} = StatusView.render("attachment.json", %{attachment: object})
120 activity = insert(:note_activity)
122 {:ok, reblog, _} = CommonAPI.repeat(activity.id, user)
124 represented = StatusView.render("status.json", %{for: user, activity: reblog})
126 assert represented[:id] == to_string(reblog.id)
127 assert represented[:reblog][:id] == to_string(activity.id)
128 assert represented[:emojis] == []