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.MastodonAPI.AccountView
11 test "Represent a user account" do
16 "icon" => %{"url" => "/file.png"},
17 "name" => ":karjalanpiirakka:"
23 "url" => [%{"href" => "https://example.com/images/asuka_hospital.png"}]
31 source_data: source_data,
32 background: background_image
34 nickname: "shp@shitposter.club",
35 name: ":karjalanpiirakka: shp",
36 bio: "<script src=\"invalid-html\"></script><span>valid html</span>",
37 inserted_at: ~N[2017-08-15 15:47:06.597036]
41 id: to_string(user.id),
44 display_name: user.name,
46 created_at: "2017-08-15T15:47:06.000Z",
50 note: "<span>valid html</span>",
52 avatar: "http://localhost:4001/images/avi.png",
53 avatar_static: "http://localhost:4001/images/avi.png",
54 header: "http://localhost:4001/images/banner.png",
55 header_static: "http://localhost:4001/images/banner.png",
58 "static_url" => "/file.png",
60 "shortcode" => "karjalanpiirakka",
61 "visible_in_picker" => false
72 background_image: "https://example.com/images/asuka_hospital.png",
73 confirmation_pending: false,
78 hide_followers: false,
81 skip_thread_containment: false
85 assert expected == AccountView.render("account.json", %{user: user})
88 test "Represent the user account for the account owner" do
91 notification_settings = %{
94 "non_follows" => true,
95 "non_followers" => true
98 privacy = user.info.default_scope
101 pleroma: %{notification_settings: ^notification_settings},
102 source: %{privacy: ^privacy}
103 } = AccountView.render("account.json", %{user: user, for: user})
106 test "Represent a Service(bot) account" do
109 info: %{note_count: 5, follower_count: 3, source_data: %{"type" => "Service"}},
110 nickname: "shp@shitposter.club",
111 inserted_at: ~N[2017-08-15 15:47:06.597036]
115 id: to_string(user.id),
118 display_name: user.name,
120 created_at: "2017-08-15T15:47:06.000Z",
126 avatar: "http://localhost:4001/images/avi.png",
127 avatar_static: "http://localhost:4001/images/avi.png",
128 header: "http://localhost:4001/images/banner.png",
129 header_static: "http://localhost:4001/images/banner.png",
139 background_image: nil,
140 confirmation_pending: false,
144 hide_favorites: true,
145 hide_followers: false,
148 skip_thread_containment: false
152 assert expected == AccountView.render("account.json", %{user: user})
155 test "Represent a smaller mention" do
159 id: to_string(user.id),
161 username: user.nickname,
165 assert expected == AccountView.render("mention.json", %{user: user})
168 test "represent a relationship" do
170 other_user = insert(:user)
172 {:ok, user} = User.follow(user, other_user)
173 {:ok, user} = User.block(user, other_user)
176 id: to_string(other_user.id),
181 muting_notifications: false,
184 domain_blocking: false,
185 showing_reblogs: true,
189 assert expected == AccountView.render("relationship.json", %{user: user, target: other_user})
192 test "represent an embedded relationship" do
195 info: %{note_count: 5, follower_count: 0, source_data: %{"type" => "Service"}},
196 nickname: "shp@shitposter.club",
197 inserted_at: ~N[2017-08-15 15:47:06.597036]
200 other_user = insert(:user)
201 {:ok, other_user} = User.follow(other_user, user)
202 {:ok, other_user} = User.block(other_user, user)
203 {:ok, _} = User.follow(insert(:user), user)
206 id: to_string(user.id),
209 display_name: user.name,
211 created_at: "2017-08-15T15:47:06.000Z",
217 avatar: "http://localhost:4001/images/avi.png",
218 avatar_static: "http://localhost:4001/images/avi.png",
219 header: "http://localhost:4001/images/banner.png",
220 header_static: "http://localhost:4001/images/banner.png",
230 background_image: nil,
231 confirmation_pending: false,
235 hide_favorites: true,
236 hide_followers: false,
239 id: to_string(user.id),
245 muting_notifications: false,
247 domain_blocking: false,
248 showing_reblogs: true,
251 skip_thread_containment: false
255 assert expected == AccountView.render("account.json", %{user: user, for: other_user})
258 test "returns the settings store if the requesting user is the represented user and it's requested specifically" do
259 user = insert(:user, %{info: %User.Info{pleroma_settings_store: %{fe: "test"}}})
262 AccountView.render("account.json", %{user: user, for: user, with_pleroma_settings: true})
264 assert result.pleroma.settings_store == %{:fe => "test"}
266 result = AccountView.render("account.json", %{user: user, with_pleroma_settings: true})
267 assert result.pleroma[:settings_store] == nil
269 result = AccountView.render("account.json", %{user: user, for: user})
270 assert result.pleroma[:settings_store] == nil