Fix conflict
[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 skip_thread_containment: false
72 }
73 }
74
75 assert expected == AccountView.render("account.json", %{user: user})
76 end
77
78 test "Represent the user account for the account owner" do
79 user = insert(:user)
80
81 notification_settings = %{
82 "followers" => true,
83 "follows" => true,
84 "non_follows" => true,
85 "non_followers" => true
86 }
87
88 privacy = user.info.default_scope
89
90 assert %{
91 pleroma: %{notification_settings: ^notification_settings},
92 source: %{privacy: ^privacy}
93 } = AccountView.render("account.json", %{user: user, for: user})
94 end
95
96 test "Represent a Service(bot) account" do
97 user =
98 insert(:user, %{
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]
102 })
103
104 expected = %{
105 id: to_string(user.id),
106 username: "shp",
107 acct: user.nickname,
108 display_name: user.name,
109 locked: false,
110 created_at: "2017-08-15T15:47:06.000Z",
111 followers_count: 3,
112 following_count: 0,
113 statuses_count: 5,
114 note: user.bio,
115 url: user.ap_id,
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",
120 emojis: [],
121 fields: [],
122 bot: true,
123 source: %{
124 note: user.bio,
125 sensitive: false,
126 pleroma: %{}
127 },
128 pleroma: %{
129 confirmation_pending: false,
130 tags: [],
131 is_admin: false,
132 is_moderator: false,
133 hide_favorites: true,
134 hide_followers: false,
135 hide_follows: false,
136 relationship: %{},
137 skip_thread_containment: false
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 skip_thread_containment: false
240 }
241 }
242
243 assert expected == AccountView.render("account.json", %{user: user, for: other_user})
244 end
245
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"}}})
248
249 result =
250 AccountView.render("account.json", %{user: user, for: user, with_pleroma_settings: true})
251
252 assert result.pleroma.settings_store == %{:fe => "test"}
253
254 result = AccountView.render("account.json", %{user: user, with_pleroma_settings: true})
255 assert result.pleroma[:settings_store] == nil
256
257 result = AccountView.render("account.json", %{user: user, for: user})
258 assert result.pleroma[:settings_store] == nil
259 end
260 end