6f8480ee2badb460a43614e1cc6ba79392c44c9e
[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.User
9 alias Pleroma.Web.MastodonAPI.AccountView
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: "valid html",
59 sensitive: false,
60 pleroma: %{}
61 },
62 pleroma: %{
63 confirmation_pending: false,
64 tags: [],
65 is_admin: false,
66 is_moderator: false,
67 hide_favorites: true,
68 hide_followers: false,
69 hide_follows: false,
70 relationship: %{}
71 }
72 }
73
74 assert expected == AccountView.render("account.json", %{user: user})
75 end
76
77 test "Represent the user account for the account owner" do
78 user = insert(:user)
79
80 notification_settings = %{
81 "remote" => true,
82 "local" => true,
83 "followers" => true,
84 "follows" => true,
85 "non_follows" => true,
86 "non_followers" => true
87 }
88
89 privacy = user.info.default_scope
90
91 assert %{
92 pleroma: %{notification_settings: ^notification_settings},
93 source: %{privacy: ^privacy}
94 } = AccountView.render("account.json", %{user: user, for: user})
95 end
96
97 test "Represent a Service(bot) account" do
98 user =
99 insert(:user, %{
100 info: %{note_count: 5, follower_count: 3, source_data: %{"type" => "Service"}},
101 nickname: "shp@shitposter.club",
102 inserted_at: ~N[2017-08-15 15:47:06.597036]
103 })
104
105 expected = %{
106 id: to_string(user.id),
107 username: "shp",
108 acct: user.nickname,
109 display_name: user.name,
110 locked: false,
111 created_at: "2017-08-15T15:47:06.000Z",
112 followers_count: 3,
113 following_count: 0,
114 statuses_count: 5,
115 note: user.bio,
116 url: user.ap_id,
117 avatar: "http://localhost:4001/images/avi.png",
118 avatar_static: "http://localhost:4001/images/avi.png",
119 header: "http://localhost:4001/images/banner.png",
120 header_static: "http://localhost:4001/images/banner.png",
121 emojis: [],
122 fields: [],
123 bot: true,
124 source: %{
125 note: user.bio,
126 sensitive: false,
127 pleroma: %{}
128 },
129 pleroma: %{
130 confirmation_pending: false,
131 tags: [],
132 is_admin: false,
133 is_moderator: false,
134 hide_favorites: true,
135 hide_followers: false,
136 hide_follows: false,
137 relationship: %{}
138 }
139 }
140
141 assert expected == AccountView.render("account.json", %{user: user})
142 end
143
144 test "Represent a smaller mention" do
145 user = insert(:user)
146
147 expected = %{
148 id: to_string(user.id),
149 acct: user.nickname,
150 username: user.nickname,
151 url: user.ap_id
152 }
153
154 assert expected == AccountView.render("mention.json", %{user: user})
155 end
156
157 test "represent a relationship" do
158 user = insert(:user)
159 other_user = insert(:user)
160
161 {:ok, user} = User.follow(user, other_user)
162 {:ok, user} = User.block(user, other_user)
163
164 expected = %{
165 id: to_string(other_user.id),
166 following: false,
167 followed_by: false,
168 blocking: true,
169 muting: false,
170 muting_notifications: false,
171 subscribing: false,
172 requested: false,
173 domain_blocking: false,
174 showing_reblogs: true,
175 endorsed: false
176 }
177
178 assert expected == AccountView.render("relationship.json", %{user: user, target: other_user})
179 end
180
181 test "represent an embedded relationship" do
182 user =
183 insert(:user, %{
184 info: %{note_count: 5, follower_count: 0, source_data: %{"type" => "Service"}},
185 nickname: "shp@shitposter.club",
186 inserted_at: ~N[2017-08-15 15:47:06.597036]
187 })
188
189 other_user = insert(:user)
190 {:ok, other_user} = User.follow(other_user, user)
191 {:ok, other_user} = User.block(other_user, user)
192 {:ok, _} = User.follow(insert(:user), user)
193
194 expected = %{
195 id: to_string(user.id),
196 username: "shp",
197 acct: user.nickname,
198 display_name: user.name,
199 locked: false,
200 created_at: "2017-08-15T15:47:06.000Z",
201 followers_count: 1,
202 following_count: 0,
203 statuses_count: 5,
204 note: user.bio,
205 url: user.ap_id,
206 avatar: "http://localhost:4001/images/avi.png",
207 avatar_static: "http://localhost:4001/images/avi.png",
208 header: "http://localhost:4001/images/banner.png",
209 header_static: "http://localhost:4001/images/banner.png",
210 emojis: [],
211 fields: [],
212 bot: true,
213 source: %{
214 note: user.bio,
215 sensitive: false,
216 pleroma: %{}
217 },
218 pleroma: %{
219 confirmation_pending: false,
220 tags: [],
221 is_admin: false,
222 is_moderator: false,
223 hide_favorites: true,
224 hide_followers: false,
225 hide_follows: false,
226 relationship: %{
227 id: to_string(user.id),
228 following: false,
229 followed_by: false,
230 blocking: true,
231 subscribing: false,
232 muting: false,
233 muting_notifications: false,
234 requested: false,
235 domain_blocking: false,
236 showing_reblogs: true,
237 endorsed: false
238 }
239 }
240 }
241
242 assert expected == AccountView.render("account.json", %{user: user, for: other_user})
243 end
244 end