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:"
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]
32 id: to_string(user.id),
35 display_name: user.name,
37 created_at: "2017-08-15T15:47:06.000Z",
41 note: "<span>valid html</span>",
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",
49 "static_url" => "/file.png",
51 "shortcode" => "karjalanpiirakka",
52 "visible_in_picker" => false
63 confirmation_pending: false,
68 hide_followers: false,
71 skip_thread_containment: false
75 assert expected == AccountView.render("account.json", %{user: user})
78 test "Represent the user account for the account owner" do
81 notification_settings = %{
84 "non_follows" => true,
85 "non_followers" => true
88 privacy = user.info.default_scope
91 pleroma: %{notification_settings: ^notification_settings},
92 source: %{privacy: ^privacy}
93 } = AccountView.render("account.json", %{user: user, for: user})
96 test "Represent a Service(bot) account" do
99 info: %{note_count: 5, follower_count: 3, source_data: %{"type" => "Service"}},
100 nickname: "shp@shitposter.club",
101 inserted_at: ~N[2017-08-15 15:47:06.597036]
105 id: to_string(user.id),
108 display_name: user.name,
110 created_at: "2017-08-15T15:47:06.000Z",
116 avatar: "http://localhost:4001/images/avi.png",
117 avatar_static: "http://localhost:4001/images/avi.png",
118 header: "http://localhost:4001/images/banner.png",
119 header_static: "http://localhost:4001/images/banner.png",
129 confirmation_pending: false,
133 hide_favorites: true,
134 hide_followers: false,
137 skip_thread_containment: false
141 assert expected == AccountView.render("account.json", %{user: user})
144 test "Represent a smaller mention" do
148 id: to_string(user.id),
150 username: user.nickname,
154 assert expected == AccountView.render("mention.json", %{user: user})
157 test "represent a relationship" do
159 other_user = insert(:user)
161 {:ok, user} = User.follow(user, other_user)
162 {:ok, user} = User.block(user, other_user)
165 id: to_string(other_user.id),
170 muting_notifications: false,
173 domain_blocking: false,
174 showing_reblogs: true,
178 assert expected == AccountView.render("relationship.json", %{user: user, target: other_user})
181 test "represent an embedded relationship" do
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]
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)
195 id: to_string(user.id),
198 display_name: user.name,
200 created_at: "2017-08-15T15:47:06.000Z",
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",
219 confirmation_pending: false,
223 hide_favorites: true,
224 hide_followers: false,
227 id: to_string(user.id),
233 muting_notifications: false,
235 domain_blocking: false,
236 showing_reblogs: true,
239 skip_thread_containment: false
243 assert expected == AccountView.render("account.json", %{user: user, for: other_user})
246 test "returns the settings store if the requesting user is the represented user and it's requested specifically" do
247 user = insert(:user, %{info: %User.Info{pleroma_settings_store: %{fe: "test"}}})
250 AccountView.render("account.json", %{user: user, for: user, with_pleroma_settings: true})
252 assert result.pleroma.settings_store == %{:fe => "test"}
254 result = AccountView.render("account.json", %{user: user, with_pleroma_settings: true})
255 assert result.pleroma[:settings_store] == nil
257 result = AccountView.render("account.json", %{user: user, for: user})
258 assert result.pleroma[:settings_store] == nil