1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
9 alias Pleroma.Web.CommonAPI
10 alias Pleroma.Web.MastodonAPI.AccountView
12 test "Represent a user account" do
17 "icon" => %{"url" => "/file.png"},
18 "name" => ":karjalanpiirakka:"
24 "url" => [%{"href" => "https://example.com/images/asuka_hospital.png"}]
32 source_data: source_data,
33 background: background_image
35 nickname: "shp@shitposter.club",
36 name: ":karjalanpiirakka: shp",
37 bio: "<script src=\"invalid-html\"></script><span>valid html</span>",
38 inserted_at: ~N[2017-08-15 15:47:06.597036]
42 id: to_string(user.id),
45 display_name: user.name,
47 created_at: "2017-08-15T15:47:06.000Z",
51 note: "<span>valid html</span>",
53 avatar: "http://localhost:4001/images/avi.png",
54 avatar_static: "http://localhost:4001/images/avi.png",
55 header: "http://localhost:4001/images/banner.png",
56 header_static: "http://localhost:4001/images/banner.png",
59 "static_url" => "/file.png",
61 "shortcode" => "karjalanpiirakka",
62 "visible_in_picker" => false
74 background_image: "https://example.com/images/asuka_hospital.png",
75 confirmation_pending: false,
80 hide_followers: false,
83 skip_thread_containment: false
87 assert expected == AccountView.render("account.json", %{user: user})
90 test "Represent the user account for the account owner" do
93 notification_settings = %{
96 "non_follows" => true,
97 "non_followers" => true
100 privacy = user.info.default_scope
103 pleroma: %{notification_settings: ^notification_settings},
104 source: %{privacy: ^privacy}
105 } = AccountView.render("account.json", %{user: user, for: user})
108 test "Represent a Service(bot) account" do
111 info: %{note_count: 5, follower_count: 3, source_data: %{"type" => "Service"}},
112 nickname: "shp@shitposter.club",
113 inserted_at: ~N[2017-08-15 15:47:06.597036]
117 id: to_string(user.id),
120 display_name: user.name,
122 created_at: "2017-08-15T15:47:06.000Z",
128 avatar: "http://localhost:4001/images/avi.png",
129 avatar_static: "http://localhost:4001/images/avi.png",
130 header: "http://localhost:4001/images/banner.png",
131 header_static: "http://localhost:4001/images/banner.png",
142 background_image: nil,
143 confirmation_pending: false,
147 hide_favorites: true,
148 hide_followers: false,
151 skip_thread_containment: false
155 assert expected == AccountView.render("account.json", %{user: user})
158 test "Represent a deactivated user for an admin" do
159 admin = insert(:user, %{info: %{is_admin: true}})
160 deactivated_user = insert(:user, %{info: %{deactivated: true}})
161 represented = AccountView.render("account.json", %{user: deactivated_user, for: admin})
162 assert represented[:pleroma][:deactivated] == true
165 test "Represent a smaller mention" do
169 id: to_string(user.id),
171 username: user.nickname,
175 assert expected == AccountView.render("mention.json", %{user: user})
178 describe "relationship" do
179 test "represent a relationship for the following and followed user" do
181 other_user = insert(:user)
183 {:ok, user} = User.follow(user, other_user)
184 {:ok, other_user} = User.follow(other_user, user)
185 {:ok, other_user} = User.subscribe(user, other_user)
186 {:ok, user} = User.mute(user, other_user, true)
187 {:ok, user} = CommonAPI.hide_reblogs(user, other_user)
190 id: to_string(other_user.id),
196 muting_notifications: true,
199 domain_blocking: false,
200 showing_reblogs: false,
205 AccountView.render("relationship.json", %{user: user, target: other_user})
208 test "represent a relationship for the blocking and blocked user" do
210 other_user = insert(:user)
212 {:ok, user} = User.follow(user, other_user)
213 {:ok, other_user} = User.subscribe(user, other_user)
214 {:ok, user} = User.block(user, other_user)
215 {:ok, other_user} = User.block(other_user, user)
218 id: to_string(other_user.id),
224 muting_notifications: false,
227 domain_blocking: false,
228 showing_reblogs: true,
233 AccountView.render("relationship.json", %{user: user, target: other_user})
236 test "represent a relationship for the user blocking a domain" do
238 other_user = insert(:user, ap_id: "https://bad.site/users/other_user")
240 {:ok, user} = User.block_domain(user, "bad.site")
242 assert %{domain_blocking: true, blocking: false} =
243 AccountView.render("relationship.json", %{user: user, target: other_user})
246 test "represent a relationship for the user with a pending follow request" do
248 other_user = insert(:user, %{info: %User.Info{locked: true}})
250 {:ok, user, other_user, _} = CommonAPI.follow(user, other_user)
251 user = User.get_cached_by_id(user.id)
252 other_user = User.get_cached_by_id(other_user.id)
255 id: to_string(other_user.id),
261 muting_notifications: false,
264 domain_blocking: false,
265 showing_reblogs: true,
270 AccountView.render("relationship.json", %{user: user, target: other_user})
274 test "represent an embedded relationship" do
277 info: %{note_count: 5, follower_count: 0, source_data: %{"type" => "Service"}},
278 nickname: "shp@shitposter.club",
279 inserted_at: ~N[2017-08-15 15:47:06.597036]
282 other_user = insert(:user)
283 {:ok, other_user} = User.follow(other_user, user)
284 {:ok, other_user} = User.block(other_user, user)
285 {:ok, _} = User.follow(insert(:user), user)
288 id: to_string(user.id),
291 display_name: user.name,
293 created_at: "2017-08-15T15:47:06.000Z",
299 avatar: "http://localhost:4001/images/avi.png",
300 avatar_static: "http://localhost:4001/images/avi.png",
301 header: "http://localhost:4001/images/banner.png",
302 header_static: "http://localhost:4001/images/banner.png",
313 background_image: nil,
314 confirmation_pending: false,
318 hide_favorites: true,
319 hide_followers: false,
322 id: to_string(user.id),
329 muting_notifications: false,
331 domain_blocking: false,
332 showing_reblogs: true,
335 skip_thread_containment: false
339 assert expected == AccountView.render("account.json", %{user: user, for: other_user})
342 test "returns the settings store if the requesting user is the represented user and it's requested specifically" do
343 user = insert(:user, %{info: %User.Info{pleroma_settings_store: %{fe: "test"}}})
346 AccountView.render("account.json", %{user: user, for: user, with_pleroma_settings: true})
348 assert result.pleroma.settings_store == %{:fe => "test"}
350 result = AccountView.render("account.json", %{user: user, with_pleroma_settings: true})
351 assert result.pleroma[:settings_store] == nil
353 result = AccountView.render("account.json", %{user: user, for: user})
354 assert result.pleroma[:settings_store] == nil
357 test "sanitizes display names" do
358 user = insert(:user, name: "<marquee> username </marquee>")
359 result = AccountView.render("account.json", %{user: user})
360 refute result.display_name == "<marquee> username </marquee>"
363 describe "hiding follows/following" do
364 test "shows when follows/following are hidden and sets follower/following count to 0" do
365 user = insert(:user, info: %{hide_followers: true, hide_follows: true})
366 other_user = insert(:user)
367 {:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)
368 {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
373 pleroma: %{hide_follows: true, hide_followers: true}
374 } = AccountView.render("account.json", %{user: user})
377 test "shows actual follower/following count to the account owner" do
378 user = insert(:user, info: %{hide_followers: true, hide_follows: true})
379 other_user = insert(:user)
380 {:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)
381 {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
386 } = AccountView.render("account.json", %{user: user, for: user})