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
73 background_image: "https://example.com/images/asuka_hospital.png",
74 confirmation_pending: false,
79 hide_followers: false,
82 skip_thread_containment: false
86 assert expected == AccountView.render("account.json", %{user: user})
89 test "Represent the user account for the account owner" do
92 notification_settings = %{
95 "non_follows" => true,
96 "non_followers" => true
99 privacy = user.info.default_scope
102 pleroma: %{notification_settings: ^notification_settings},
103 source: %{privacy: ^privacy}
104 } = AccountView.render("account.json", %{user: user, for: user})
107 test "Represent a Service(bot) account" do
110 info: %{note_count: 5, follower_count: 3, source_data: %{"type" => "Service"}},
111 nickname: "shp@shitposter.club",
112 inserted_at: ~N[2017-08-15 15:47:06.597036]
116 id: to_string(user.id),
119 display_name: user.name,
121 created_at: "2017-08-15T15:47:06.000Z",
127 avatar: "http://localhost:4001/images/avi.png",
128 avatar_static: "http://localhost:4001/images/avi.png",
129 header: "http://localhost:4001/images/banner.png",
130 header_static: "http://localhost:4001/images/banner.png",
140 background_image: nil,
141 confirmation_pending: false,
145 hide_favorites: true,
146 hide_followers: false,
149 skip_thread_containment: false
153 assert expected == AccountView.render("account.json", %{user: user})
156 test "Represent a deactivated user for an admin" do
157 admin = insert(:user, %{info: %{is_admin: true}})
158 deactivated_user = insert(:user, %{info: %{deactivated: true}})
159 represented = AccountView.render("account.json", %{user: deactivated_user, for: admin})
160 assert represented[:pleroma][:deactivated] == true
163 test "Represent a smaller mention" do
167 id: to_string(user.id),
169 username: user.nickname,
173 assert expected == AccountView.render("mention.json", %{user: user})
176 describe "relationship" do
177 test "represent a relationship for the following and followed user" do
179 other_user = insert(:user)
181 {:ok, user} = User.follow(user, other_user)
182 {:ok, other_user} = User.follow(other_user, user)
183 {:ok, other_user} = User.subscribe(user, other_user)
184 {:ok, user} = User.mute(user, other_user, true)
185 {:ok, user} = CommonAPI.hide_reblogs(user, other_user)
188 id: to_string(other_user.id),
194 muting_notifications: true,
197 domain_blocking: false,
198 showing_reblogs: false,
203 AccountView.render("relationship.json", %{user: user, target: other_user})
206 test "represent a relationship for the blocking and blocked user" do
208 other_user = insert(:user)
210 {:ok, user} = User.follow(user, other_user)
211 {:ok, other_user} = User.subscribe(user, other_user)
212 {:ok, user} = User.block(user, other_user)
213 {:ok, other_user} = User.block(other_user, user)
216 id: to_string(other_user.id),
222 muting_notifications: false,
225 domain_blocking: false,
226 showing_reblogs: true,
231 AccountView.render("relationship.json", %{user: user, target: other_user})
234 test "represent a relationship for the user with a pending follow request" do
236 other_user = insert(:user, %{info: %User.Info{locked: true}})
238 {:ok, user, other_user, _} = CommonAPI.follow(user, other_user)
239 user = User.get_cached_by_id(user.id)
240 other_user = User.get_cached_by_id(other_user.id)
243 id: to_string(other_user.id),
249 muting_notifications: false,
252 domain_blocking: false,
253 showing_reblogs: true,
258 AccountView.render("relationship.json", %{user: user, target: other_user})
262 test "represent an embedded relationship" do
265 info: %{note_count: 5, follower_count: 0, source_data: %{"type" => "Service"}},
266 nickname: "shp@shitposter.club",
267 inserted_at: ~N[2017-08-15 15:47:06.597036]
270 other_user = insert(:user)
271 {:ok, other_user} = User.follow(other_user, user)
272 {:ok, other_user} = User.block(other_user, user)
273 {:ok, _} = User.follow(insert(:user), user)
276 id: to_string(user.id),
279 display_name: user.name,
281 created_at: "2017-08-15T15:47:06.000Z",
287 avatar: "http://localhost:4001/images/avi.png",
288 avatar_static: "http://localhost:4001/images/avi.png",
289 header: "http://localhost:4001/images/banner.png",
290 header_static: "http://localhost:4001/images/banner.png",
300 background_image: nil,
301 confirmation_pending: false,
305 hide_favorites: true,
306 hide_followers: false,
309 id: to_string(user.id),
316 muting_notifications: false,
318 domain_blocking: false,
319 showing_reblogs: true,
322 skip_thread_containment: false
326 assert expected == AccountView.render("account.json", %{user: user, for: other_user})
329 test "returns the settings store if the requesting user is the represented user and it's requested specifically" do
330 user = insert(:user, %{info: %User.Info{pleroma_settings_store: %{fe: "test"}}})
333 AccountView.render("account.json", %{user: user, for: user, with_pleroma_settings: true})
335 assert result.pleroma.settings_store == %{:fe => "test"}
337 result = AccountView.render("account.json", %{user: user, with_pleroma_settings: true})
338 assert result.pleroma[:settings_store] == nil
340 result = AccountView.render("account.json", %{user: user, for: user})
341 assert result.pleroma[:settings_store] == nil
344 test "sanitizes display names" do
345 user = insert(:user, name: "<marquee> username </marquee>")
346 result = AccountView.render("account.json", %{user: user})
347 refute result.display_name == "<marquee> username </marquee>"