Remove milliseconds from mastodon api response.
[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, Object}
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+/, "")
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: nil,
40 language: nil
41 }
42
43 assert status == expected
44 end
45
46 test "contains mentions" do
47 incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
48 user = insert(:user, %{ap_id: "https://pleroma.soykaf.com/users/lain"})
49
50 {:ok, [activity]} = OStatus.handle_incoming(incoming)
51
52 status = StatusView.render("status.json", %{activity: activity})
53
54 assert status.mentions == [AccountView.render("mention.json", %{user: user})]
55 end
56
57 test "attachments" do
58 incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
59 object = %{
60 "type" => "Image",
61 "url" => [
62 %{
63 "mediaType" => "image/png",
64 "href" => "someurl"
65 }
66 ],
67 "uuid" => 6
68 }
69
70 expected = %{
71 id: 1638338801,
72 type: "image",
73 url: "someurl",
74 remote_url: "someurl",
75 preview_url: "someurl"
76 }
77
78 assert expected == StatusView.render("attachment.json", %{attachment: object})
79 end
80 end