870a205f110c5d30d663370aebcdb0fc52d0539b
[akkoma] / test / web / mastodon_api / status_view_test.exs
1 defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
2 use Pleroma.DataCase
3
4 alias Pleroma.Web.MastodonAPI.{StatusView, AccountView}
5 alias Pleroma.User
6 alias Pleroma.Web.OStatus
7 import Pleroma.Factory
8
9 test "a note activity" do
10 note = insert(:note_activity)
11 user = User.get_cached_by_ap_id(note.data["actor"])
12
13 status = StatusView.render("status.json", %{activity: note})
14
15 created_at = (note.data["object"]["published"] || "")
16 |> String.replace(~r/\.\d+Z/, ".000Z")
17
18 expected = %{
19 id: note.id,
20 uri: note.data["object"]["id"],
21 url: note.data["object"]["external_id"],
22 account: AccountView.render("account.json", %{user: user}),
23 in_reply_to_id: nil,
24 in_reply_to_account_id: nil,
25 reblog: nil,
26 content: HtmlSanitizeEx.basic_html(note.data["object"]["content"]),
27 created_at: created_at,
28 reblogs_count: 0,
29 favourites_count: 0,
30 reblogged: false,
31 favourited: false,
32 muted: false,
33 sensitive: false,
34 spoiler_text: "",
35 visibility: "public",
36 media_attachments: [],
37 mentions: [],
38 tags: [],
39 application: %{
40 name: "Web",
41 website: nil
42 },
43 language: nil
44 }
45
46 assert status == expected
47 end
48
49 test "contains mentions" do
50 incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
51 user = insert(:user, %{ap_id: "https://pleroma.soykaf.com/users/lain"})
52
53 {:ok, [activity]} = OStatus.handle_incoming(incoming)
54
55 status = StatusView.render("status.json", %{activity: activity})
56
57 assert status.mentions == [AccountView.render("mention.json", %{user: user})]
58 end
59
60 test "attachments" do
61 object = %{
62 "type" => "Image",
63 "url" => [
64 %{
65 "mediaType" => "image/png",
66 "href" => "someurl"
67 }
68 ],
69 "uuid" => 6
70 }
71
72 expected = %{
73 id: 1638338801,
74 type: "image",
75 url: "someurl",
76 remote_url: "someurl",
77 preview_url: "someurl",
78 text_url: "someurl"
79 }
80
81 assert expected == StatusView.render("attachment.json", %{attachment: object})
82
83 # If theres a "id", use that instead of the generated one
84 object = Map.put(object, "id", 2)
85 assert %{id: 2} = StatusView.render("attachment.json", %{attachment: object})
86 end
87 end