Merge branch 'features/masto-account-view-rights' into 'develop'
[akkoma] / test / web / mastodon_api / account_view_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
6 use Pleroma.DataCase
7 import Pleroma.Factory
8 alias Pleroma.Web.MastodonAPI.AccountView
9 alias Pleroma.User
10
11 test "Represent a user account" do
12 source_data = %{
13 "tag" => [
14 %{
15 "type" => "Emoji",
16 "icon" => %{"url" => "/file.png"},
17 "name" => ":karjalanpiirakka:"
18 }
19 ]
20 }
21
22 user =
23 insert(:user, %{
24 info: %{note_count: 5, follower_count: 3, source_data: source_data},
25 nickname: "shp@shitposter.club",
26 name: ":karjalanpiirakka: shp",
27 bio: "<script src=\"invalid-html\"></script><span>valid html</span>",
28 inserted_at: ~N[2017-08-15 15:47:06.597036]
29 })
30
31 expected = %{
32 id: to_string(user.id),
33 username: "shp",
34 acct: user.nickname,
35 display_name: user.name,
36 locked: false,
37 created_at: "2017-08-15T15:47:06.000Z",
38 followers_count: 3,
39 following_count: 0,
40 statuses_count: 5,
41 note: "<span>valid html</span>",
42 url: user.ap_id,
43 avatar: "http://localhost:4001/images/avi.png",
44 avatar_static: "http://localhost:4001/images/avi.png",
45 header: "http://localhost:4001/images/banner.png",
46 header_static: "http://localhost:4001/images/banner.png",
47 emojis: [
48 %{
49 "static_url" => "/file.png",
50 "url" => "/file.png",
51 "shortcode" => "karjalanpiirakka",
52 "visible_in_picker" => false
53 }
54 ],
55 fields: [],
56 bot: false,
57 source: %{
58 note: "",
59 privacy: "public",
60 sensitive: false
61 },
62 pleroma: %{
63 confirmation_pending: false,
64 tags: [],
65 is_admin: false,
66 is_moderator: false
67 }
68 }
69
70 assert expected == AccountView.render("account.json", %{user: user})
71 end
72
73 test "Represent a Service(bot) account" do
74 user =
75 insert(:user, %{
76 info: %{note_count: 5, follower_count: 3, source_data: %{"type" => "Service"}},
77 nickname: "shp@shitposter.club",
78 inserted_at: ~N[2017-08-15 15:47:06.597036]
79 })
80
81 expected = %{
82 id: to_string(user.id),
83 username: "shp",
84 acct: user.nickname,
85 display_name: user.name,
86 locked: false,
87 created_at: "2017-08-15T15:47:06.000Z",
88 followers_count: 3,
89 following_count: 0,
90 statuses_count: 5,
91 note: user.bio,
92 url: user.ap_id,
93 avatar: "http://localhost:4001/images/avi.png",
94 avatar_static: "http://localhost:4001/images/avi.png",
95 header: "http://localhost:4001/images/banner.png",
96 header_static: "http://localhost:4001/images/banner.png",
97 emojis: [],
98 fields: [],
99 bot: true,
100 source: %{
101 note: "",
102 privacy: "public",
103 sensitive: false
104 },
105 pleroma: %{
106 confirmation_pending: false,
107 tags: [],
108 is_admin: false,
109 is_moderator: false
110 }
111 }
112
113 assert expected == AccountView.render("account.json", %{user: user})
114 end
115
116 test "Represent a smaller mention" do
117 user = insert(:user)
118
119 expected = %{
120 id: to_string(user.id),
121 acct: user.nickname,
122 username: user.nickname,
123 url: user.ap_id
124 }
125
126 assert expected == AccountView.render("mention.json", %{user: user})
127 end
128
129 test "represent a relationship" do
130 user = insert(:user)
131 other_user = insert(:user)
132
133 {:ok, user} = User.follow(user, other_user)
134 {:ok, user} = User.block(user, other_user)
135
136 expected = %{
137 id: to_string(other_user.id),
138 following: false,
139 followed_by: false,
140 blocking: true,
141 muting: false,
142 muting_notifications: false,
143 requested: false,
144 domain_blocking: false,
145 showing_reblogs: false,
146 endorsed: false
147 }
148
149 assert expected == AccountView.render("relationship.json", %{user: user, target: other_user})
150 end
151 end